agent upgrade on Windows run with option to force close applications keeping agent...
[public/netxms.git] / src / server / tools / nxdbmgr / upgrade.cpp
CommitLineData
6f33021d 1/*
5039dede 2** nxdbmgr - NetXMS database manager
221826d9 3** Copyright (C) 2004-2017 Victor Kirhenshtein
5039dede
AK
4**
5** This program is free software; you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation; either version 2 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
19** File: upgrade.cpp
20**
21**/
22
23#include "nxdbmgr.h"
bf6fb6c3 24#include <nxevent.h>
5039dede 25
4f50e45c
VK
26/**
27 * Externals
28 */
7a41a06e 29BOOL MigrateMaps();
63604cda 30bool ConvertTDataTables();
7a41a06e 31
50963ced
VK
32/**
33 * Pre-defined GUID mapping for GenerateGUID
34 */
35struct GUID_MAPPING
36{
37 UINT32 id;
38 const TCHAR *guid;
39};
40
271e3971
VK
41/**
42 * Generate GUIDs
43 */
50963ced 44static bool GenerateGUID(const TCHAR *table, const TCHAR *idColumn, const TCHAR *guidColumn, const GUID_MAPPING *mapping)
271e3971
VK
45{
46 TCHAR query[256];
47 _sntprintf(query, 256, _T("SELECT %s FROM %s"), idColumn, table);
48 DB_RESULT hResult = SQLSelect(query);
49 if (hResult == NULL)
50 return false;
51
50963ced
VK
52 uuid_t guid;
53 TCHAR buffer[64];
54
271e3971
VK
55 int count = DBGetNumRows(hResult);
56 for(int i = 0; i < count; i++)
57 {
50963ced
VK
58 const TCHAR *guidText = NULL;
59 UINT32 id = DBGetFieldULong(hResult, i, 0);
60 if (mapping != NULL)
61 {
62 for(int j = 0; mapping[j].guid != NULL; j++)
63 if (mapping[j].id == id)
64 {
65 guidText = mapping[j].guid;
66 break;
67 }
68 }
69 if (guidText == NULL)
70 {
71 _uuid_generate(guid);
72 guidText = _uuid_to_string(guid, buffer);
73 }
74 _sntprintf(query, 256, _T("UPDATE %s SET %s='%s' WHERE %s=%d"), table, guidColumn, guidText, idColumn, id);
271e3971
VK
75 if (!SQLQuery(query))
76 {
77 DBFreeResult(hResult);
78 return false;
79 }
80 }
81 DBFreeResult(hResult);
82 return true;
83}
84
4f50e45c
VK
85/**
86 * Create table
87 */
c85c8ef2 88static bool CreateTable(const TCHAR *pszQuery)
5039dede 89{
7618e362 90 String query(pszQuery);
5039dede 91
2a964810
VK
92 query.replace(_T("$SQL:TEXT"), g_pszSqlType[g_dbSyntax][SQL_TYPE_TEXT]);
93 query.replace(_T("$SQL:TXT4K"), g_pszSqlType[g_dbSyntax][SQL_TYPE_TEXT4K]);
94 query.replace(_T("$SQL:INT64"), g_pszSqlType[g_dbSyntax][SQL_TYPE_INT64]);
95 if (g_dbSyntax == DB_SYNTAX_MYSQL)
7618e362 96 query += g_pszTableSuffix;
c85c8ef2 97 return SQLQuery(query);
5039dede
AK
98}
99
4f50e45c 100/**
6a6b96c0 101 * Check if configuration variable exist
4f50e45c 102 */
c85c8ef2 103static bool IsConfigurationVariableExist(const TCHAR *name)
5039dede 104{
c85c8ef2
VK
105 bool found = false;
106 TCHAR query[256];
107 _sntprintf(query, 256, _T("SELECT var_value FROM config WHERE var_name='%s'"), name);
108 DB_RESULT hResult = DBSelect(g_hCoreDB, query);
5039dede
AK
109 if (hResult != 0)
110 {
c85c8ef2 111 found = (DBGetNumRows(hResult) > 0);
5039dede
AK
112 DBFreeResult(hResult);
113 }
c85c8ef2
VK
114 return found;
115}
5039dede 116
c85c8ef2 117/**
6a6b96c0 118 * Create configuration parameter if it doesn`t exist (unless bForceUpdate set to true)
c85c8ef2
VK
119 */
120bool CreateConfigParam(const TCHAR *name, const TCHAR *value, const TCHAR *description, char dataType, bool isVisible, bool needRestart, bool isPublic, bool forceUpdate)
121{
122 bool success = true;
2589cc10 123 TCHAR szQuery[3024];
c85c8ef2 124 if (!IsConfigurationVariableExist(name))
5039dede 125 {
2589cc10 126 _sntprintf(szQuery, 3024, _T("INSERT INTO config (var_name,var_value,is_visible,need_server_restart,is_public,data_type,description) VALUES (%s,%s,%d,%d,'%c','%c',%s)"),
c85c8ef2 127 (const TCHAR *)DBPrepareString(g_hCoreDB, name, 63),
2589cc10 128 (const TCHAR *)DBPrepareString(g_hCoreDB, value, 2000), isVisible ? 1 : 0, needRestart ? 1 : 0,
c85c8ef2
VK
129 isPublic ? _T('Y') : _T('N'), dataType, (const TCHAR *)DBPrepareString(g_hCoreDB, description, 255));
130 success = SQLQuery(szQuery);
5039dede 131 }
c85c8ef2 132 else if (forceUpdate)
5039dede 133 {
2589cc10 134 _sntprintf(szQuery, 3024, _T("UPDATE config SET var_value=%s WHERE var_name=%s"),
135 (const TCHAR *)DBPrepareString(g_hCoreDB, value, 2000), (const TCHAR *)DBPrepareString(g_hCoreDB, name, 63));
c85c8ef2 136 success = SQLQuery(szQuery);
5039dede 137 }
c85c8ef2
VK
138 return success;
139}
140
141/**
142 * Create configuration parameter if it doesn't exist (unless bForceUpdate set to true)
143 */
144bool CreateConfigParam(const TCHAR *name, const TCHAR *value, bool isVisible, bool needRestart, bool forceUpdate)
145{
146 bool success = true;
2589cc10 147 TCHAR szQuery[3024];
c85c8ef2
VK
148 if (!IsConfigurationVariableExist(name))
149 {
2589cc10 150 _sntprintf(szQuery, 3024, _T("INSERT INTO config (var_name,var_value,is_visible,need_server_restart) VALUES (%s,%s,%d,%d)"),
c85c8ef2 151 (const TCHAR *)DBPrepareString(g_hCoreDB, name, 63),
2589cc10 152 (const TCHAR *)DBPrepareString(g_hCoreDB, value, 2000), isVisible ? 1 : 0, needRestart ? 1 : 0);
c85c8ef2
VK
153 success = SQLQuery(szQuery);
154 }
155 else if (forceUpdate)
156 {
2589cc10 157 _sntprintf(szQuery, 3024, _T("UPDATE config SET var_value=%s WHERE var_name=%s"),
158 (const TCHAR *)DBPrepareString(g_hCoreDB, value, 2000), (const TCHAR *)DBPrepareString(g_hCoreDB, name, 63));
c85c8ef2
VK
159 success = SQLQuery(szQuery);
160 }
161 return success;
5039dede
AK
162}
163
63604cda
VK
164/**
165 * Rename table
166 */
167bool RenameDatabaseTable(const TCHAR *oldName, const TCHAR *newName)
168{
169 TCHAR query[1024];
170 switch(g_dbSyntax)
171 {
172 case DB_SYNTAX_DB2:
173 case DB_SYNTAX_INFORMIX:
174 case DB_SYNTAX_MYSQL:
175 _sntprintf(query, 1024, _T("RENAME TABLE %s TO %s"), oldName, newName);
176 break;
177 case DB_SYNTAX_ORACLE:
178 case DB_SYNTAX_PGSQL:
179 _sntprintf(query, 1024, _T("ALTER TABLE %s RENAME TO %s"), oldName, newName);
180 break;
181 case DB_SYNTAX_MSSQL:
182 _sntprintf(query, 1024, _T("EXEC sp_rename '%s','%s'"), oldName, newName);
183 break;
184 default: // Unsupported DB engine
185 return false;
186 }
187 return SQLQuery(query);
188}
189
4f50e45c
VK
190/**
191 * Drop primary key from table
192 */
9bfc9a6b
VK
193static BOOL DropPrimaryKey(const TCHAR *table)
194{
195 TCHAR query[1024];
196 DB_RESULT hResult;
197 BOOL success;
198
2a964810 199 switch(g_dbSyntax)
9bfc9a6b 200 {
c849da55
VK
201 case DB_SYNTAX_DB2:
202 case DB_SYNTAX_INFORMIX:
9bfc9a6b 203 case DB_SYNTAX_MYSQL:
c849da55 204 case DB_SYNTAX_ORACLE:
9bfc9a6b
VK
205 _sntprintf(query, 1024, _T("ALTER TABLE %s DROP PRIMARY KEY"), table);
206 success = SQLQuery(query);
207 break;
208 case DB_SYNTAX_PGSQL:
209 _sntprintf(query, 1024, _T("ALTER TABLE %s DROP CONSTRAINT %s_pkey"), table, table);
210 success = SQLQuery(query);
211 break;
212 case DB_SYNTAX_MSSQL:
213 success = FALSE;
214 _sntprintf(query, 1024, _T("SELECT name FROM sysobjects WHERE xtype='PK' AND parent_obj=OBJECT_ID('%s')"), table);
215 hResult = SQLSelect(query);
216 if (hResult != NULL)
217 {
218 if (DBGetNumRows(hResult) > 0)
219 {
220 TCHAR objName[512];
221
222 DBGetField(hResult, 0, 0, objName, 512);
223 _sntprintf(query, 1024, _T("ALTER TABLE %s DROP CONSTRAINT %s"), table, objName);
224 success = SQLQuery(query);
225 }
0b112a22
VK
226 else
227 {
228 success = TRUE; // No PK to drop
229 }
9bfc9a6b
VK
230 DBFreeResult(hResult);
231 }
232 break;
233 default: // Unsupported DB engine
234 success = FALSE;
235 break;
236 }
c849da55
VK
237
238 if ((g_dbSyntax == DB_SYNTAX_DB2) && success)
239 {
240 _sntprintf(query, 1024, _T("CALL Sysproc.admin_cmd('REORG TABLE %s')"), table);
241 success = SQLQuery(query);
242 }
9bfc9a6b
VK
243 return success;
244}
245
4f50e45c
VK
246/**
247 * Convert strings from # encoded form to normal form
248 */
d6bf58f9 249static BOOL ConvertStrings(const TCHAR *table, const TCHAR *idColumn, const TCHAR *idColumn2, const TCHAR *column, bool isStringId)
643c9dcb
VK
250{
251 DB_RESULT hResult;
252 TCHAR *query;
4e0e77e6 253 size_t queryLen = 512;
643c9dcb
VK
254 BOOL success = FALSE;
255
c29fb885 256 query = (TCHAR *)malloc(queryLen * sizeof(TCHAR));
fe12a1ea 257
2a964810 258 switch(g_dbSyntax)
a4743a0f
VK
259 {
260 case DB_SYNTAX_MSSQL:
9f6712bc 261 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE CAST(%s AS nvarchar(4000))=N'#00'"), table, column, column);
a4743a0f
VK
262 break;
263 case DB_SYNTAX_ORACLE:
264 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE to_char(%s)='#00'"), table, column, column);
265 break;
266 default:
267 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE %s='#00'"), table, column, column);
268 break;
269 }
fe12a1ea
VK
270 if (!SQLQuery(query))
271 {
272 free(query);
273 return FALSE;
274 }
275
6f33021d 276 _sntprintf(query, queryLen, _T("SELECT %s,%s%s%s FROM %s WHERE %s LIKE '%%#%%'"),
98cd01bb 277 idColumn, column, (idColumn2 != NULL) ? _T(",") : _T(""), (idColumn2 != NULL) ? idColumn2 : _T(""), table, column);
643c9dcb
VK
278 hResult = SQLSelect(query);
279 if (hResult == NULL)
280 {
281 free(query);
282 return FALSE;
283 }
284
285 int count = DBGetNumRows(hResult);
286 for(int i = 0; i < count; i++)
287 {
643c9dcb 288 TCHAR *value = DBGetField(hResult, i, 1, NULL, 0);
035a4d73 289 if (_tcschr(value, _T('#')) != NULL)
643c9dcb 290 {
035a4d73
VK
291 DecodeSQLString(value);
292 String newValue = DBPrepareString(g_hCoreDB, value);
4e0e77e6 293 if (newValue.length() + 256 > queryLen)
035a4d73 294 {
4e0e77e6 295 queryLen = newValue.length() + 256;
c29fb885 296 query = (TCHAR *)realloc(query, queryLen * sizeof(TCHAR));
035a4d73 297 }
d6bf58f9 298 if (isStringId)
98cd01bb 299 {
d6bf58f9
VK
300 TCHAR *id = DBGetField(hResult, i, 0, NULL, 0);
301 if (idColumn2 != NULL)
302 {
303 TCHAR *id2 = DBGetField(hResult, i, 2, NULL, 0);
304 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=%s AND %s=%s"),
305 table, column, (const TCHAR *)newValue,
6f33021d 306 idColumn, (const TCHAR *)DBPrepareString(g_hCoreDB, id),
d6bf58f9
VK
307 idColumn2, (const TCHAR *)DBPrepareString(g_hCoreDB, id2));
308 }
309 else
310 {
311 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=%s"), table, column,
312 (const TCHAR *)newValue, idColumn, (const TCHAR *)DBPrepareString(g_hCoreDB, id));
313 }
314 free(id);
98cd01bb
VK
315 }
316 else
317 {
d6bf58f9
VK
318 INT64 id = DBGetFieldInt64(hResult, i, 0);
319 if (idColumn2 != NULL)
320 {
321 INT64 id2 = DBGetFieldInt64(hResult, i, 2);
6f33021d 322 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=") INT64_FMT _T(" AND %s=") INT64_FMT,
d6bf58f9
VK
323 table, column, (const TCHAR *)newValue, idColumn, id, idColumn2, id2);
324 }
325 else
326 {
327 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=") INT64_FMT, table, column,
328 (const TCHAR *)newValue, idColumn, id);
329 }
98cd01bb 330 }
035a4d73
VK
331 if (!SQLQuery(query))
332 goto cleanup;
643c9dcb 333 }
643c9dcb
VK
334 }
335 success = TRUE;
336
337cleanup:
338 DBFreeResult(hResult);
a4743a0f 339 free(query);
643c9dcb
VK
340 return success;
341}
342
98cd01bb
VK
343static BOOL ConvertStrings(const TCHAR *table, const TCHAR *idColumn, const TCHAR *column)
344{
d6bf58f9 345 return ConvertStrings(table, idColumn, NULL, column, false);
98cd01bb
VK
346}
347
4f50e45c 348/**
241541f4 349 * Remove NOT NULL constraint from column
4f50e45c 350 */
241541f4 351static bool RemoveNotNullConstraint(const TCHAR *table, const TCHAR *column)
1024e962
VK
352{
353 TCHAR query[1024] = _T("");
354
2a964810 355 switch(g_dbSyntax)
1024e962
VK
356 {
357 case DB_SYNTAX_ORACLE:
358 _sntprintf(query, 1024, _T("DECLARE already_null EXCEPTION; ")
359 _T("PRAGMA EXCEPTION_INIT(already_null, -1451); ")
f57209fd
VK
360 _T("BEGIN EXECUTE IMMEDIATE 'ALTER TABLE %s MODIFY %s null'; ")
361 _T("EXCEPTION WHEN already_null THEN null; END;"), table, column);
1024e962 362 break;
480e036b
VK
363 case DB_SYNTAX_PGSQL:
364 _sntprintf(query, 1024, _T("ALTER TABLE %s ALTER COLUMN %s DROP NOT NULL"), table, column);
365 break;
1024e962
VK
366 default:
367 break;
368 }
369
241541f4
VK
370 return (query[0] != 0) ? SQLQuery(query) : true;
371}
372
373/**
374 * Set NOT NULL constraint on column
375 */
376static bool SetNotNullConstraint(const TCHAR *table, const TCHAR *column)
377{
378 TCHAR query[1024] = _T("");
379
380 switch(g_dbSyntax)
381 {
382 case DB_SYNTAX_ORACLE:
383 _sntprintf(query, 1024, _T("DECLARE already_not_null EXCEPTION; ")
384 _T("PRAGMA EXCEPTION_INIT(already_not_null, -1442); ")
385 _T("BEGIN EXECUTE IMMEDIATE 'ALTER TABLE %s MODIFY %s NOT NULL'; ")
386 _T("EXCEPTION WHEN already_not_null THEN null; END;"), table, column);
387 break;
388 case DB_SYNTAX_PGSQL:
389 _sntprintf(query, 1024, _T("ALTER TABLE %s ALTER COLUMN %s SET NOT NULL"), table, column);
390 break;
391 default:
392 break;
393 }
394
395 return (query[0] != 0) ? SQLQuery(query) : true;
1024e962
VK
396}
397
480e036b
VK
398/**
399 * Resize varchar column
400 */
b69710b9 401static BOOL ResizeColumn(const TCHAR *table, const TCHAR *column, int newSize, bool nullable)
480e036b
VK
402{
403 TCHAR query[1024];
404
2a964810 405 switch(g_dbSyntax)
480e036b
VK
406 {
407 case DB_SYNTAX_DB2:
408 _sntprintf(query, 1024, _T("ALTER TABLE %s ALTER COLUMN %s SET DATA TYPE varchar(%d)"), table, column, newSize);
409 break;
410 case DB_SYNTAX_MSSQL:
b69710b9 411 _sntprintf(query, 1024, _T("ALTER TABLE %s ALTER COLUMN %s varchar(%d) %s NULL"), table, column, newSize, nullable ? _T("") : _T("NOT"));
480e036b
VK
412 break;
413 case DB_SYNTAX_PGSQL:
414 _sntprintf(query, 1024, _T("ALTER TABLE %s ALTER COLUMN %s TYPE varchar(%d)"), table, column, newSize);
415 break;
416 case DB_SYNTAX_SQLITE:
417 /* TODO: add SQLite support */
418 query[0] = 0;
419 break;
420 default:
421 _sntprintf(query, 1024, _T("ALTER TABLE %s MODIFY %s varchar(%d)"), table, column, newSize);
422 break;
423 }
424
425 return (query[0] != 0) ? SQLQuery(query) : TRUE;
426}
427
4f50e45c
VK
428/**
429 * Create new event template
430 */
3da098f7 431static BOOL CreateEventTemplate(int code, const TCHAR *name, int severity, int flags, const TCHAR *guid, const TCHAR *message, const TCHAR *description)
aa16f82b 432{
480e036b 433 TCHAR query[4096];
aa16f82b 434
3da098f7
VK
435 if (guid != NULL)
436 {
437 _sntprintf(query, 4096, _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description,guid) VALUES (%d,'%s',%d,%d,%s,%s,'%s')"),
438 code, name, severity, flags, (const TCHAR *)DBPrepareString(g_hCoreDB, message),
439 (const TCHAR *)DBPrepareString(g_hCoreDB, description), guid);
440 }
441 else
442 {
443 _sntprintf(query, 4096, _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES (%d,'%s',%d,%d,%s,%s)"),
444 code, name, severity, flags, (const TCHAR *)DBPrepareString(g_hCoreDB, message),
445 (const TCHAR *)DBPrepareString(g_hCoreDB, description));
446 }
aa16f82b
VK
447 return SQLQuery(query);
448}
449
22aaa779
VK
450/**
451 * Re-create TDATA tables
452 */
2f1bc68b 453static BOOL RecreateTData(const TCHAR *className, bool multipleTables, bool indexFix)
22aaa779 454{
1d4f7890 455 TCHAR query[1024];
22aaa779
VK
456 _sntprintf(query, 256, _T("SELECT id FROM %s"), className);
457 DB_RESULT hResult = SQLSelect(query);
458 if (hResult != NULL)
459 {
460 int count = DBGetNumRows(hResult);
461 for(int i = 0; i < count; i++)
462 {
2f1bc68b 463 bool recreateTables = true;
22aaa779
VK
464 DWORD id = DBGetFieldULong(hResult, i, 0);
465
2f1bc68b 466 if (indexFix)
1d4f7890 467 {
2f1bc68b
VK
468 _sntprintf(query, 256, _T("SELECT count(*) FROM dc_tables WHERE node_id=%d"), id);
469 DB_RESULT hResultCount = SQLSelect(query);
470 if (hResultCount != NULL)
22aaa779 471 {
7d4f8ace 472 recreateTables = (DBGetFieldLong(hResultCount, 0, 0) == 0);
2f1bc68b
VK
473 DBFreeResult(hResultCount);
474 }
475
476 if (!recreateTables)
477 {
a9f5aa55 478 _sntprintf(query, 256, _T("CREATE INDEX idx_tdata_rec_%d_id ON tdata_records_%d(record_id)"), id, id);
2f1bc68b
VK
479 if (!SQLQuery(query))
480 {
481 if (!g_bIgnoreErrors)
482 {
483 DBFreeResult(hResult);
484 return FALSE;
485 }
486 }
22aaa779
VK
487 }
488 }
489
2f1bc68b 490 if (recreateTables)
22aaa779 491 {
2f1bc68b 492 if (multipleTables)
22aaa779 493 {
2f1bc68b
VK
494 _sntprintf(query, 1024, _T("DROP TABLE tdata_rows_%d\nDROP TABLE tdata_records_%d\nDROP TABLE tdata_%d\n<END>"), id, id, id);
495 }
496 else
497 {
498 _sntprintf(query, 256, _T("DROP TABLE tdata_%d\n<END>"), id);
499 }
500 if (!SQLBatch(query))
501 {
502 if (!g_bIgnoreErrors)
503 {
504 DBFreeResult(hResult);
505 return FALSE;
506 }
507 }
508
63604cda 509 if (!CreateTDataTable(id))
2f1bc68b
VK
510 {
511 if (!g_bIgnoreErrors)
512 {
513 DBFreeResult(hResult);
514 return FALSE;
515 }
22aaa779
VK
516 }
517 }
518 }
519 DBFreeResult(hResult);
520 }
521 else
522 {
523 if (!g_bIgnoreErrors)
524 return FALSE;
525 }
385b1f20 526 return TRUE;
527}
528
c75e9ee4
VK
529/**
530 * Convert network masks from dotted decimal format to number of bits
531 */
532static BOOL ConvertNetMasks(const TCHAR *table, const TCHAR *column, const TCHAR *idColumn, const TCHAR *idColumn2 = NULL, const TCHAR *condition = NULL)
533{
534 TCHAR query[256];
fcf91b2e 535
c75e9ee4
VK
536 if (idColumn2 != NULL)
537 _sntprintf(query, 256, _T("SELECT %s,%s,%s FROM %s"), idColumn, column, idColumn2, table);
538 else
539 _sntprintf(query, 256, _T("SELECT %s,%s FROM %s"), idColumn, column, table);
540 DB_RESULT hResult = SQLSelect(query);
541 if (hResult == NULL)
542 return FALSE;
543
a19fa589 544 BOOL success = SQLDropColumn(table, column);
fcf91b2e 545
c75e9ee4
VK
546 if (success)
547 {
548 _sntprintf(query, 256, _T("ALTER TABLE %s ADD %s integer"), table, column);
549 success = SQLQuery(query);
550 }
551
552 if (success)
553 {
554 int count = DBGetNumRows(hResult);
555 for(int i = 0; (i < count) && success; i++)
556 {
557 if (idColumn2 != NULL)
558 {
559 TCHAR id2[256];
fcf91b2e 560 _sntprintf(query, 256, _T("UPDATE %s SET %s=%d WHERE %s=%d AND %s='%s'"),
c75e9ee4
VK
561 table, column, BitsInMask(DBGetFieldIPAddr(hResult, i, 1)), idColumn, DBGetFieldLong(hResult, i, 0),
562 idColumn2, DBGetField(hResult, i, 2, id2, 256));
563 }
564 else
565 {
fcf91b2e 566 _sntprintf(query, 256, _T("UPDATE %s SET %s=%d WHERE %s=%d"),
c75e9ee4
VK
567 table, column, BitsInMask(DBGetFieldIPAddr(hResult, i, 1)), idColumn, DBGetFieldLong(hResult, i, 0));
568 }
569 success = SQLQuery(query);
570 }
571 }
572
573 DBFreeResult(hResult);
574 return success;
575}
576
b2a15edc
VK
577/**
578 * Convert object tool macros to new format
579 */
580static bool ConvertObjectToolMacros(UINT32 id, const TCHAR *text, const TCHAR *column)
581{
582 if (_tcschr(text, _T('%')) == NULL)
583 return true; // nothing to convert
584
585 String s;
586 for(const TCHAR *p = text; *p != 0; p++)
587 {
588 if (*p == _T('%'))
589 {
590 TCHAR name[256];
591 int i = 0;
592 for(p++; (*p != _T('%')) && (*p != 0); p++)
593 {
594 if (i < 255)
595 name[i++] = *p;
596 }
597 if (*p == 0)
598 break; // malformed string
599 name[i] = 0;
600 if (!_tcscmp(name, _T("ALARM_ID")))
601 {
602 s.append(_T("%Y"));
603 }
604 else if (!_tcscmp(name, _T("ALARM_MESSAGE")))
605 {
606 s.append(_T("%A"));
607 }
608 else if (!_tcscmp(name, _T("ALARM_SEVERITY")))
609 {
610 s.append(_T("%s"));
611 }
612 else if (!_tcscmp(name, _T("ALARM_SEVERITY_TEXT")))
613 {
614 s.append(_T("%S"));
615 }
616 else if (!_tcscmp(name, _T("ALARM_STATE")))
617 {
618 s.append(_T("%y"));
619 }
620 else if (!_tcscmp(name, _T("OBJECT_ID")))
621 {
622 s.append(_T("%I"));
623 }
624 else if (!_tcscmp(name, _T("OBJECT_IP_ADDR")))
625 {
626 s.append(_T("%a"));
627 }
628 else if (!_tcscmp(name, _T("OBJECT_NAME")))
629 {
630 s.append(_T("%n"));
631 }
632 else if (!_tcscmp(name, _T("USERNAME")))
633 {
634 s.append(_T("%U"));
635 }
636 else
637 {
638 s.append(_T("%{"));
639 s.append(name);
640 s.append(_T('}'));
641 }
642 }
643 else
644 {
645 s.append(*p);
646 }
647 }
648
649 String query = _T("UPDATE object_tools SET ");
650 query.append(column);
651 query.append(_T('='));
652 query.append(DBPrepareString(g_hCoreDB, s));
653 query.append(_T(" WHERE tool_id="));
654 query.append(id);
655 return SQLQuery(query);
656}
8a1519ce 657
83aa5ebd
VK
658/**
659 * Create library script
660 */
661static bool CreateLibraryScript(UINT32 id, const TCHAR *name, const TCHAR *code)
662{
663 // Check if script exists
664 TCHAR query[256];
665 _sntprintf(query, 256, _T("SELECT script_id FROM script_library WHERE script_id=%d OR script_name=%s"),
666 id, (const TCHAR *)DBPrepareString(g_hCoreDB, name));
667 DB_RESULT hResult = SQLSelect(query);
668 if (hResult == NULL)
669 return false;
670 bool exist = (DBGetNumRows(hResult) > 0);
671 DBFreeResult(hResult);
672 if (exist)
673 return true;
674
675 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("INSERT INTO script_library (script_id,script_name,script_code) VALUES (?,?,?)"));
676 if (hStmt == NULL)
677 return false;
678
679 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, id);
680 DBBind(hStmt, 2, DB_SQLTYPE_VARCHAR, name, DB_BIND_STATIC);
681 DBBind(hStmt, 3, DB_SQLTYPE_TEXT, code, DB_BIND_STATIC);
682
683 bool success = SQLExecute(hStmt);
684 DBFreeStatement(hStmt);
685 return success;
686}
687
e2a9c5fc
VK
688/**
689 * Check if an event pair is handled by any EPP rules
690 */
691static bool IsEventPairInUse(UINT32 code1, UINT32 code2)
692{
693 TCHAR query[256];
694 _sntprintf(query, 256, _T("SELECT count(*) FROM policy_event_list WHERE event_code=%d OR event_code=%d"), code1, code2);
695 DB_RESULT hResult = SQLSelect(query);
696 if (hResult == NULL)
697 return false;
698 bool inUse = (DBGetFieldLong(hResult, 0, 0) > 0);
699 DBFreeResult(hResult);
700 return inUse;
701}
702
703/**
704 * Return the next free EPP rule ID
705 */
706static int NextFreeEPPruleID()
707{
708 int ruleId = 1;
709 DB_RESULT hResult = SQLSelect(_T("SELECT max(rule_id) FROM event_policy"));
710 if (hResult != NULL)
711 {
712 ruleId = DBGetFieldLong(hResult, 0, 0) + 1;
713 DBFreeResult(hResult);
714 }
715 return ruleId;
716}
717
e4926628
VK
718/**
719 * Set schema version
720 */
721static bool SetSchemaVersion(int version)
722{
723 TCHAR query[256];
724 _sntprintf(query, 256, _T("UPDATE metadata SET var_value='%d' WHERE var_name='SchemaVersion'"), version);
725 return SQLQuery(query);
726}
727
f14e669f 728/**
221826d9
VK
729 * Upgrade from V427 to V428
730 */
731static BOOL H_UpgradeFromV427(int currVersion, int newVersion)
732{
733 CHK_EXEC(CreateConfigParam(_T("ClusterContainerAutoBind"), _T("0"), _T("Enable/disable container auto binding for clusters"), 'B', true, false, false, false));
734 CHK_EXEC(CreateConfigParam(_T("ClusterTemplateAutoApply"), _T("0"), _T("Enable/disable template auto apply for clusters"), 'B', true, false, false, false));
735 CHK_EXEC(SetSchemaVersion(428));
736 return TRUE;
737}
738
739/**
740 * Upgrade from V426 to V427
f14e669f 741 */
61854771 742static BOOL H_UpgradeFromV426(int currVersion, int newVersion)
f14e669f 743{
5f18cc16
VK
744 CHK_EXEC(SQLQuery(_T("ALTER TABLE nodes ADD port_rows integer")));
745 CHK_EXEC(SQLQuery(_T("ALTER TABLE nodes ADD port_numbering_scheme integer")));
61854771 746 CHK_EXEC(SetSchemaVersion(427));
f14e669f
EJ
747 return TRUE;
748}
749
291644e3 750/**
221826d9 751 * Upgrade from V425 to V426
291644e3
EJ
752 */
753static BOOL H_UpgradeFromV425(int currVersion, int newVersion)
754{
5f18cc16
VK
755 CHK_EXEC(CreateConfigParam(_T("EnableAlarmSummaryEmails"), _T(""), _T("Enable alarm summary e-mails"), 'I', true, false, false, false));
756 CHK_EXEC(CreateConfigParam(_T("AlarmSummaryEmailSchedule"), _T(""), _T("Schedule for sending alarm summary e-mails in cron format"), 'S', true, false, false, false));
757 CHK_EXEC(CreateConfigParam(_T("AlarmSummaryEmailRecipients"), _T(""), _T("A semicolon separated list of alarm summary e-mail recipient addresses"), 'S', true, false, false, false));
291644e3
EJ
758 CHK_EXEC(SetSchemaVersion(426));
759 return TRUE;
760}
761
b52e8ddd
EJ
762/**
763 * Upgrade from V424 to V425
764 */
765static BOOL H_UpgradeFromV424(int currVersion, int newVersion)
766{
767 CHK_EXEC(SQLQuery(_T("ALTER TABLE scheduled_tasks ADD comments varchar(255)")));
768 CHK_EXEC(SetSchemaVersion(425));
769 return TRUE;
770}
771
8b75662b
EJ
772/**
773 * Upgrade from V423 to V424
774 */
775static BOOL H_UpgradeFromV423(int currVersion, int newVersion)
776{
777 CHK_EXEC(CreateConfigParam(_T("MessageOfTheDay"), _T(""), _T("Message to be shown when a user logs into the console"), 'S', true, false, false, false));
778 CHK_EXEC(SetSchemaVersion(424));
779 return TRUE;
780}
781
88072662 782/**
b2ecde3b
VK
783 * Upgrade from V422 to V423
784 */
785static BOOL H_UpgradeFromV422(int currVersion, int newVersion)
786{
787 CHK_EXEC(CreateConfigParam(_T("RADIUSAuthMethod"), _T("PAP"), _T("RADIUS authentication method to be used (PAP, CHAP, MS-CHAPv1, MS-CHAPv2)"), 'S', true, false, false, false));
788 CHK_EXEC(SetSchemaVersion(423));
789 return TRUE;
790}
791
792/**
793 * Upgrade from V421 to V422
794 */
88072662
VK
795static BOOL H_UpgradeFromV421(int currVersion, int newVersion)
796{
797 CHK_EXEC(CreateConfigParam(_T("ServerColor"), _T(""), _T("Identification color for this server"), 'S', true, false, false, false));
798 CHK_EXEC(CreateConfigParam(_T("ServerName"), _T(""), _T("Name of this server"), 'S', true, false, false, false));
799 CHK_EXEC(SetSchemaVersion(422));
800 return TRUE;
801}
802
b97ddf57 803/**
b52e8ddd 804 * Upgrade from V420 to V421
b2ecde3b 805 */
d38a36c6 806static BOOL H_UpgradeFromV420(int currVersion, int newVersion)
b97ddf57
EJ
807{
808 DB_RESULT hResult = SQLSelect(_T("SELECT access_rights,user_id,object_id FROM acl"));
b97ddf57
EJ
809 if (hResult != NULL)
810 {
811 UINT32 rights;
4c34f2c2
EJ
812 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("UPDATE acl SET access_rights=? WHERE user_id=? AND object_id=?"));
813 if (hStmt != NULL)
b97ddf57 814 {
4c34f2c2 815 for(int i = 0; i < DBGetNumRows(hResult); i++)
b97ddf57 816 {
4c34f2c2
EJ
817 rights = DBGetFieldULong(hResult, i, 0);
818 if ((rights & 0x2) == 0x2)
b97ddf57 819 {
4c34f2c2 820 rights = rights | 0x8000; // Add Manage maintenance access right to all users which have Modify object access right
b97ddf57
EJ
821 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, rights);
822 DBBind(hStmt, 2, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 1));
823 DBBind(hStmt, 3, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 2));
824 SQLExecute(hStmt);
b97ddf57
EJ
825 }
826 }
a6baa9d2
VK
827 DBFreeStatement(hStmt);
828 }
829 else
830 {
831 if (!g_bIgnoreErrors)
832 {
833 DBFreeResult(hResult);
834 return FALSE;
835 }
b97ddf57 836 }
b97ddf57
EJ
837 DBFreeResult(hResult);
838 }
839 else
a6baa9d2
VK
840 {
841 if (!g_bIgnoreErrors)
842 return FALSE;
843 }
b97ddf57 844
d38a36c6
EJ
845 CHK_EXEC(SetSchemaVersion(421));
846 return TRUE;
847}
848
849/*
850 * Upgrade from V419 to V420
851 */
852static BOOL H_UpgradeFromV419(int currVersion, int newVersion)
853{
854 CHK_EXEC(CreateConfigParam(_T("EnableReportingServer"), _T("0"), 1, 1));
855 CHK_EXEC(CreateConfigParam(_T("ReportingServerHostname"), _T("localhost"), 1, 1));
856 CHK_EXEC(CreateConfigParam(_T("ReportingServerPort"), _T("4710"), 1, 1));
b97ddf57
EJ
857 CHK_EXEC(SetSchemaVersion(420));
858 return TRUE;
859}
860
288a0046 861/**
b2ecde3b
VK
862 * Upgrade from V418 to V419
863 */
288a0046
VK
864static BOOL H_UpgradeFromV418(int currVersion, int newVersion)
865{
866 CHK_EXEC(SQLQuery(_T("ALTER TABLE items ADD npe_name varchar(15)")));
867 CHK_EXEC(SetSchemaVersion(419));
868 return TRUE;
869}
870
7ac735ef 871/**
b2ecde3b
VK
872 * Upgrade from V417 to V418
873 */
7ac735ef 874static BOOL H_UpgradeFromV417(int currVersion, int newVersion)
875{
288a0046
VK
876 // Update in object tools objectToolFilter objectMenuFilter
877 // move object tool flags to filter structure
7ac735ef 878 DB_RESULT hResult = SQLSelect(_T("SELECT tool_id,flags,tool_filter FROM object_tools"));
879 if (hResult != NULL)
880 {
881 int count = DBGetNumRows(hResult);
882 for(int i = 0; i < count; i++)
883 {
884 int filteringFlag = 0;
885 int objectToolFlag = DBGetFieldLong(hResult, i, 1);
7ac735ef 886
a13cb1ac
VK
887 // Separate and reorder flags for filter and for object tools
888 for(int j = 1; j < 5; j = j << 1) //REQUIRES_SNMP 0x01, REQUIRES_AGENT 0x02, REQUIRES_OID_MATCH 0x04
7ac735ef 889 {
a13cb1ac 890 if ((objectToolFlag & j) != 0)
7ac735ef 891 {
892 objectToolFlag = objectToolFlag & ~j;
893 filteringFlag = filteringFlag | j;
894 }
895 }
a13cb1ac
VK
896
897 if ((objectToolFlag & 0x08) != 0) //ASK_CONFIRMATION
7ac735ef 898 {
899 objectToolFlag = objectToolFlag & ~0x08;
900 objectToolFlag = objectToolFlag | 0x01;
901 }
a13cb1ac
VK
902
903 if ((objectToolFlag & 0x10) != 0) //GENERATES_OUTPUT
7ac735ef 904 {
905 objectToolFlag = objectToolFlag & ~0x10;
906 objectToolFlag = objectToolFlag | 0x02;
907 }
a13cb1ac
VK
908
909 if ((objectToolFlag & 0x20) != 0) //DISABLED
7ac735ef 910 {
911 objectToolFlag = objectToolFlag & ~0x20;
912 objectToolFlag = objectToolFlag | 0x04;
913 }
a13cb1ac
VK
914
915 if ((objectToolFlag & 0x40) != 0) //SHOW_IN_COMMANDS
7ac735ef 916 {
917 objectToolFlag = objectToolFlag & ~0x40;
918 objectToolFlag = objectToolFlag | 0x08;
919 }
a13cb1ac
VK
920
921 if ((objectToolFlag & 0x80) != 0) //REQUIRES_NODE_OS_MATCH
7ac735ef 922 {
923 objectToolFlag = objectToolFlag & ~0x80;
924 filteringFlag = filteringFlag | 0x08;
925 }
a13cb1ac
VK
926
927 if ((objectToolFlag & 0x100) != 0) //REQUIRES_TEMPLATE_MATCH
7ac735ef 928 {
929 objectToolFlag = objectToolFlag & ~0x100;
930 filteringFlag = filteringFlag | 0x10;
931 }
a13cb1ac
VK
932
933 if ((objectToolFlag & 0x10000) != 0) //SNMP_INDEXED_BY_VALUE
7ac735ef 934 {
935 objectToolFlag = objectToolFlag & ~0x10000;
936 objectToolFlag = objectToolFlag | 0x10;
937 }
a13cb1ac
VK
938
939 if ((objectToolFlag & 0x20000) != 0) //REQUIRES_WORKSTATION_OS_MATCH
7ac735ef 940 {
941 objectToolFlag = objectToolFlag & ~0x20000;
942 filteringFlag = filteringFlag | 0x20;
943 }
944
a13cb1ac
VK
945 // Add filter flags to XML
946 TCHAR *xml = DBGetField(hResult, i, 2, NULL, 0);
367caea6 947 size_t len = (xml != NULL) ? _tcslen(xml) + 1024 : 1024;
a13cb1ac 948 TCHAR *tmp = (TCHAR *)malloc(len * sizeof(TCHAR));
367caea6 949 TCHAR *ptr = (xml != NULL) ? _tcsrchr(xml, '<') : NULL;
a13cb1ac 950 if (ptr != NULL)
7ac735ef 951 {
952 *ptr = 0;
a13cb1ac 953 _sntprintf(tmp, len, _T("%s<flags>%d</flags></objectMenuFilter>"), xml, filteringFlag);
7ac735ef 954 _tcsncpy(tmp, _T("<objectMenuFilter"), 17); //Change main tag name
955 }
956 else
957 {
a13cb1ac 958 _sntprintf(tmp, len, _T("<objectMenuFilter><flags>%d</flags></objectMenuFilter>"), filteringFlag);
7ac735ef 959 }
960
961 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("UPDATE object_tools SET flags=?,tool_filter=? WHERE tool_id=?"));
962 if (hStmt != NULL)
963 {
964 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, objectToolFlag);
a13cb1ac 965 DBBind(hStmt, 2, DB_SQLTYPE_TEXT, tmp, DB_BIND_DYNAMIC);
7ac735ef 966 DBBind(hStmt, 3, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 0));
967 if (!SQLExecute(hStmt))
968 {
969 if (!g_bIgnoreErrors)
970 {
a13cb1ac 971 free(xml);
7ac735ef 972 DBFreeStatement(hStmt);
973 DBFreeResult(hResult);
974 return FALSE;
975 }
976 }
977 }
a13cb1ac 978 else
7ac735ef 979 {
a13cb1ac
VK
980 free(tmp);
981 if (!g_bIgnoreErrors)
982 {
983 free(xml);
984 DBFreeResult(hResult);
985 return FALSE;
986 }
7ac735ef 987 }
a13cb1ac 988 free(xml);
7ac735ef 989 }
990 DBFreeResult(hResult);
991 }
992 else
993 {
994 if (!g_bIgnoreErrors)
995 return false;
996 }
997
998 CHK_EXEC(SetSchemaVersion(418));
999 return TRUE;
1000}
1001
c299358f 1002/**
b2ecde3b
VK
1003 * Upgrade from V416 to V417
1004 */
c299358f
EJ
1005static BOOL H_UpgradeFromV416(int currVersion, int newVersion)
1006{
1007 CHK_EXEC(CreateConfigParam(_T("JiraIssueType"), _T("Task"), true, false));
1008 CHK_EXEC(CreateConfigParam(_T("JiraLogin"), _T("netxms"), true, true));
1009 CHK_EXEC(CreateConfigParam(_T("JiraPassword"), _T(""), true, true));
1010 CHK_EXEC(CreateConfigParam(_T("JiraProjectCode"), _T("NETXMS"), true, false));
1011 CHK_EXEC(CreateConfigParam(_T("JiraProjectComponent"), _T(""), true, false));
1012 CHK_EXEC(CreateConfigParam(_T("JiraServerURL"), _T("http://localhost"), true, true));
1013
1014 CHK_EXEC(SetSchemaVersion(417));
1015 return TRUE;
1016}
1017
6a6b96c0 1018/**
b2ecde3b
VK
1019 * Upgrade from V415 to V416
1020 */
6a6b96c0
EJ
1021static BOOL H_UpgradeFromV415(int currVersion, int newVersion)
1022{
1023 CHK_EXEC(CreateTable(
1024 _T("CREATE TABLE alarm_categories (")
1025 _T("id integer not null,")
1026 _T("name varchar(63) null,")
1027 _T("descr varchar(255) null,")
1028 _T("PRIMARY KEY(id))")));
1029 CHK_EXEC(CreateTable(
1030 _T("CREATE TABLE alarm_category_acl (")
1031 _T("category_id integer not null,")
1032 _T("user_id integer not null,")
1033 _T("PRIMARY KEY(category_id,user_id))")));
1034 CHK_EXEC(CreateTable(
1035 _T("CREATE TABLE alarm_category_map (")
1036 _T("alarm_id integer not null,")
1037 _T("category_id integer not null,")
1038 _T("PRIMARY KEY(alarm_id,category_id))")));
1039
1040 CHK_EXEC(SQLQuery(
1041 _T("ALTER TABLE alarms ADD alarm_category_ids varchar(255)")));
1042
1043 // Add view all alarms system access to user group - Everyone
1044 DB_RESULT hResult = SQLSelect(_T("SELECT system_access FROM user_groups WHERE name='Everyone'"));
1045 if (hResult != NULL)
1046 {
1047 UINT64 sysAccess = DBGetFieldUInt64(hResult, 0, 0);
1048 sysAccess = sysAccess | SYSTEM_ACCESS_VIEW_ALL_ALARMS;
1049
1050 TCHAR query[MAX_DB_STRING];
1051 _sntprintf(query, MAX_DB_STRING, _T("UPDATE user_groups SET system_access=%ld WHERE name='Everyone'"), sysAccess);
1052 CHK_EXEC(SQLQuery(query));
1053
1054 DBFreeResult(hResult);
1055 }
1056 else
1057 {
1058 if (!g_bIgnoreErrors)
1059 return false;
1060 }
1061
1062 CHK_EXEC(SetSchemaVersion(416));
1063 return TRUE;
1064}
1065
73bbcd77
VK
1066/**
1067 * Upgrade from V414 to V415
1068 */
1069static BOOL H_UpgradeFromV414(int currVersion, int newVersion)
1070{
1071 CHK_EXEC(RemoveNotNullConstraint(_T("dci_summary_tables"), _T("menu_path")));
1072 CHK_EXEC(SetSchemaVersion(415));
1073 return TRUE;
1074}
1075
685508a7
VK
1076/**
1077 * Upgrade from V413 to V414
1078 */
1079static BOOL H_UpgradeFromV413(int currVersion, int newVersion)
1080{
1081 CHK_EXEC(SQLQuery(_T("UPDATE config SET var_name='EnableSyslogReceiver' WHERE var_name='EnableSyslogDaemon'")));
1082 CHK_EXEC(SetSchemaVersion(414));
1083 return TRUE;
1084}
1085
be737a59
VK
1086/**
1087 * Upgrade from V412 to V413
1088 */
1089static BOOL H_UpgradeFromV412(int currVersion, int newVersion)
1090{
1091 CHK_EXEC(SQLQuery(_T("UPDATE users SET name='system',description='Built-in system account',full_name='',flags=12 WHERE id=0")));
1092
1093 TCHAR password[128];
1094 DB_RESULT hResult = SQLSelect(_T("SELECT password FROM users WHERE id=0"));
1095 if (hResult != NULL)
1096 {
1097 if (DBGetNumRows(hResult) > 0)
1098 DBGetField(hResult, 0, 0, password, 128);
1099 else
1100 _tcscpy(password, _T("3A445C0072CD69D9030CC6644020E5C4576051B1")); // Use default password "netxms"
1101 DBFreeResult(hResult);
1102 }
1103 else
1104 {
1105 if (!g_bIgnoreErrors)
1106 return false;
1107 }
1108
1109 UINT32 userId = 1;
1110 hResult = SQLSelect(_T("SELECT max(id) FROM users"));
1111 if (hResult != NULL)
1112 {
1113 if (DBGetNumRows(hResult) > 0)
1114 userId = DBGetFieldULong(hResult, 0, 0) + 1;
1115 DBFreeResult(hResult);
1116 }
1117 else
1118 {
1119 if (!g_bIgnoreErrors)
1120 return false;
1121 }
1122
1123 uuid guid = uuid::generate();
1124 TCHAR query[1024];
1125 _sntprintf(query, 1024,
1126 _T("INSERT INTO users (id,name,password,system_access,flags,full_name,")
1127 _T(" description,grace_logins,auth_method,guid,")
1128 _T(" cert_mapping_method,cert_mapping_data,")
1129 _T(" auth_failures,last_passwd_change,min_passwd_length,")
1130 _T(" disabled_until,last_login) VALUES (%d,'admin','%s',274877906943,0,")
1131 _T(" '','Default administrator account',5,0,'%s',0,'',0,0,0,0,0)"),
1132 userId, password, (const TCHAR *)guid.toString());
1133 CHK_EXEC(SQLQuery(query));
1134
1135 for(int i = 1; i < 10; i++)
1136 {
1137 _sntprintf(query, 256, _T("INSERT INTO acl (object_id,user_id,access_rights) VALUES (%d,%d,32767)"), i, userId);
1138 CHK_EXEC(SQLQuery(query));
1139 }
1140
1141 CHK_EXEC(SetSchemaVersion(413));
1142 return TRUE;
1143}
1144
43b62436
VK
1145/**
1146 * Upgrade from V411 to V412
1147 */
1148static BOOL H_UpgradeFromV411(int currVersion, int newVersion)
1149{
1150 DB_RESULT hResult = SQLSelect(_T("SELECT id,zone_guid,agent_proxy,snmp_proxy,icmp_proxy,ssh_proxy FROM zones"));
1151 if (hResult != NULL)
1152 {
1153 CHK_EXEC(SQLQuery(_T("DROP TABLE zones")));
1154 CHK_EXEC(CreateTable(
1155 _T("CREATE TABLE zones (")
1156 _T("id integer not null,")
1157 _T("zone_guid integer not null,")
1158 _T("proxy_node integer not null,")
1159 _T("PRIMARY KEY(id))")));
1160 int count = DBGetNumRows(hResult);
1161 if (count > 0)
1162 {
1163 TCHAR query[256];
1164 for(int i = 0; i < count; i++)
1165 {
1166 UINT32 proxy = 0;
1167 for(int j = 2; (j < 6) && (proxy == 0); j++)
1168 proxy = DBGetFieldULong(hResult, i, j);
49e749f3 1169 _sntprintf(query, 256, _T("INSERT INTO zones (id,zone_guid,proxy_node) VALUES (%d,%d,%d)"),
43b62436
VK
1170 DBGetFieldLong(hResult, i, 0), DBGetFieldLong(hResult, i, 1), (int)proxy);
1171 CHK_EXEC(SQLQuery(query));
1172 }
1173 }
1174 DBFreeResult(hResult);
1175 }
1176 else
1177 {
be737a59 1178 if (!g_bIgnoreErrors)
43b62436
VK
1179 return false;
1180 }
1181 CHK_EXEC(SetSchemaVersion(412));
1182 return TRUE;
1183}
1184
63604cda
VK
1185/**
1186 * Upgrade from V410 to V411
1187 */
1188static BOOL H_UpgradeFromV410(int currVersion, int newVersion)
1189{
29e18f5a 1190 //check if tdata upgrade was already done, then just delete "TdataTableUpdated" metadata parameter
03e5e230 1191 if (!MetaDataReadInt(_T("TdataTableUpdated"), 0))
63604cda 1192 {
29e18f5a 1193 StringMap savedMetadata;
1194 DB_RESULT hResult = SQLSelect(_T("SELECT var_name,var_value FROM metadata WHERE var_name LIKE 'TDataTableCreationCommand_%' OR var_name LIKE 'TDataIndexCreationCommand_%'"));
1195 if (hResult != NULL)
63604cda 1196 {
29e18f5a 1197 int count = DBGetNumRows(hResult);
1198 for(int i = 0; i < count; i++)
63604cda 1199 {
29e18f5a 1200 savedMetadata.setPreallocated(DBGetField(hResult, i, 0, NULL, 0), DBGetField(hResult, i, 1, NULL, 0));
63604cda 1201 }
29e18f5a 1202 DBFreeResult(hResult);
1203 }
1204 else if (!g_bIgnoreErrors)
1205 {
63604cda
VK
1206 return false;
1207 }
63604cda 1208
29e18f5a 1209 static const TCHAR *batch =
1210 _T("DELETE FROM metadata WHERE var_name LIKE 'TDataTableCreationCommand_%' OR var_name LIKE 'TDataIndexCreationCommand_%'\n")
1211 _T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataTableCreationCommand_0','CREATE TABLE tdata_%d (item_id integer not null,tdata_timestamp integer not null,tdata_value $SQL:TEXT null)')\n")
1212 _T("<END>");
1213 CHK_EXEC(SQLBatch(batch));
1214
1215 if (g_dbSyntax == DB_SYNTAX_MSSQL)
1216 CHK_EXEC(SQLQuery(_T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataIndexCreationCommand_0','CREATE CLUSTERED INDEX idx_tdata_%d ON tdata_%d(item_id,tdata_timestamp)')")));
1217 else
1218 CHK_EXEC(SQLQuery(_T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataIndexCreationCommand_0','CREATE INDEX idx_tdata_%d ON tdata_%d(item_id,tdata_timestamp)')")));
1219
1220 // table conversion will require multiple commits
1221 DBCommit(g_hCoreDB);
1222 if (!ConvertTDataTables())
1223 {
1224 if (!g_bIgnoreErrors)
1225 {
1226 // Restore metadata
1227 SQLQuery(_T("DELETE FROM metadata WHERE var_name LIKE 'TDataTableCreationCommand_%' OR var_name LIKE 'TDataIndexCreationCommand_%'"));
1228 StringList *keys = savedMetadata.keys();
1229 for(int i = 0; i < keys->size(); i++)
1230 {
1231 TCHAR query[4096];
1232 _sntprintf(query, 4096, _T("INSERT INTO metadata (var_name,var_value) VALUES (%s,%s)"),
1233 (const TCHAR *)DBPrepareString(g_hCoreDB, keys->get(i)),
1234 (const TCHAR *)DBPrepareString(g_hCoreDB, savedMetadata.get(keys->get(i))));
1235 SQLQuery(query);
1236 }
1237 return false;
1238 }
1239 }
1240
1241 DBBegin(g_hCoreDB);
1242 }
1243 else
1244 {
1245 CHK_EXEC(SQLQuery(_T("DELETE FROM metadata WHERE var_name='TdataTableUpdated'")));
1246 }
63604cda
VK
1247 CHK_EXEC(SetSchemaVersion(411));
1248 return TRUE;
1249}
1250
241541f4
VK
1251/**
1252 * Upgrade from V409 to V410
1253 */
1254static BOOL H_UpgradeFromV409(int currVersion, int newVersion)
1255{
1256 static const TCHAR *batch =
1257 _T("ALTER TABLE zones ADD ssh_proxy integer\n")
1258 _T("UPDATE zones SET ssh_proxy=0\n")
1259 _T("ALTER TABLE nodes ADD ssh_login varchar(63)\n")
1260 _T("ALTER TABLE nodes ADD ssh_password varchar(63)\n")
1261 _T("ALTER TABLE nodes ADD ssh_proxy integer\n")
1262 _T("UPDATE nodes SET ssh_proxy=0\n")
1263 _T("<END>");
1264 CHK_EXEC(SQLBatch(batch));
1265
1266 CHK_EXEC(SetNotNullConstraint(_T("nodes"), _T("ssh_proxy")));
1267 CHK_EXEC(SetNotNullConstraint(_T("zones"), _T("ssh_proxy")));
1268
1269 CHK_EXEC(SetSchemaVersion(410));
1270 return TRUE;
1271}
1272
e980db40
VK
1273/**
1274 * Upgrade from V408 to V409
1275 */
1276static BOOL H_UpgradeFromV408(int currVersion, int newVersion)
1277{
1278 static const TCHAR *batch =
1279 _T("ALTER TABLE nodes ADD node_type integer\n")
1280 _T("ALTER TABLE nodes ADD node_subtype varchar(127)\n")
1281 _T("UPDATE nodes SET node_type=0\n")
1282 _T("<END>");
1283 CHK_EXEC(SQLBatch(batch));
1284
241541f4
VK
1285 CHK_EXEC(SetNotNullConstraint(_T("nodes"), _T("node_type")));
1286
e980db40
VK
1287 CHK_EXEC(SetSchemaVersion(409));
1288 return TRUE;
1289}
1290
e4926628
VK
1291/**
1292 * Upgrade from V407 to V408
1293 */
1294static BOOL H_UpgradeFromV407(int currVersion, int newVersion)
1295{
1296 CHK_EXEC(CreateTable(
1297 _T("CREATE TABLE chassis (")
1298 _T(" id integer not null,")
32a400d9 1299 _T(" flags integer not null,")
e4926628
VK
1300 _T(" controller_id integer not null,")
1301 _T(" rack_id integer not null,")
1302 _T(" rack_image varchar(36) null,")
1303 _T(" rack_position integer not null,")
1304 _T(" rack_height integer not null,")
1305 _T(" PRIMARY KEY(id))")
1306 ));
1307
1308 static const TCHAR *batch =
1309 _T("ALTER TABLE nodes ADD chassis_id integer\n")
1310 _T("UPDATE nodes SET chassis_id=0\n")
1311 _T("<END>");
1312 CHK_EXEC(SQLBatch(batch));
1313
241541f4
VK
1314 CHK_EXEC(SetNotNullConstraint(_T("nodes"), _T("chassis_id")));
1315
e4926628
VK
1316 CHK_EXEC(SetSchemaVersion(408));
1317 return TRUE;
1318}
1319
8498228c 1320/**
1321 * Upgrade from V406 to V407
1322 */
1323static BOOL H_UpgradeFromV406(int currVersion, int newVersion)
1324{
1325 ResizeColumn(_T("user_groups"), _T("ldap_unique_id"), 64, true);
e4926628 1326 CHK_EXEC(SetSchemaVersion(407));
8498228c 1327 return TRUE;
1328}
1329
ba756b1a
VK
1330/**
1331 * Upgrade from V405 to V406
1332 */
1333static BOOL H_UpgradeFromV405(int currVersion, int newVersion)
1334{
1335 static const TCHAR *batch =
1336 _T("ALTER TABLE nodes ADD syslog_msg_count $SQL:INT64\n")
1337 _T("ALTER TABLE nodes ADD snmp_trap_count $SQL:INT64\n")
1338 _T("UPDATE nodes SET syslog_msg_count=0,snmp_trap_count=0\n")
1339 _T("<END>");
1340 CHK_EXEC(SQLBatch(batch));
e4926628 1341 CHK_EXEC(SetSchemaVersion(406));
ba756b1a
VK
1342 return TRUE;
1343}
1344
b123ecb3 1345/**
1346 * Upgrade from V404 to V405
1347 */
1348static BOOL H_UpgradeFromV404(int currVersion, int newVersion)
1349{
7b30e5ae 1350 CHK_EXEC(CreateEventTemplate(EVENT_AGENT_LOG_PROBLEM, _T("SYS_AGENT_LOG_PROBLEM"),
b123ecb3 1351 SEVERITY_MAJOR, EF_LOG, _T("262057ca-357a-4a4d-9b78-42ae96e490a1"),
1352 _T("Problem with agent log: %2"),
7b30e5ae 1353 _T("Generated on status poll if agent reports problem with log file.\r\n")
b123ecb3 1354 _T("Parameters:\r\n")
7b30e5ae 1355 _T(" 1) Status code\r\n")
b123ecb3 1356 _T(" 2) Description")));
7b30e5ae 1357 CHK_EXEC(CreateEventTemplate(EVENT_AGENT_LOCAL_DATABASE_PROBLEM, _T("SYS_AGENT_LOCAL_DATABASE_PROBLEM"),
b123ecb3 1358 SEVERITY_MAJOR, EF_LOG, _T("d02b63f1-1151-429e-adb9-1dfbb3a31b32"),
1359 _T("Problem with agent local database: %2"),
7b30e5ae 1360 _T("Generated on status poll if agent reports local database problem.\r\n")
b123ecb3 1361 _T("Parameters:\r\n")
7b30e5ae 1362 _T(" 1) Status code\r\n")
b123ecb3 1363 _T(" 2) Description")));
1364
1365 int ruleId = NextFreeEPPruleID();
1366 TCHAR query[1024];
1367 _sntprintf(query, 1024, _T("INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) ")
7b30e5ae 1368 _T("VALUES (%d,'19bd89ba-8bb2-4915-8546-a1ecc650dedd',7944,'Generate an alarm when there is problem with agent log','%%m',5,'SYS_AGENT_LOG_PROBLEM_%%i','',0,%d,0,'')"),
b123ecb3 1369 ruleId, EVENT_ALARM_TIMEOUT);
1370 CHK_EXEC(SQLQuery(query));
7b30e5ae 1371 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_AGENT_LOG_PROBLEM);
b123ecb3 1372 CHK_EXEC(SQLQuery(query));
7b30e5ae
VK
1373
1374 ruleId = NextFreeEPPruleID();
b123ecb3 1375 _sntprintf(query, 1024, _T("INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) ")
7b30e5ae 1376 _T("VALUES (%d,'cff7fe6b-2ad1-4c18-8a8f-4d397d44fe04',7944,'Generate an alarm when there is problem with agent local database','%%m',5,'SYS_AGENT_LOCAL_DATABASE_PROBLEM_%%i','',0,%d,0,'')"),
b123ecb3 1377 ruleId, EVENT_ALARM_TIMEOUT);
1378 CHK_EXEC(SQLQuery(query));
7b30e5ae 1379 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_AGENT_LOCAL_DATABASE_PROBLEM);
b123ecb3 1380 CHK_EXEC(SQLQuery(query));
1381
e4926628 1382 CHK_EXEC(SetSchemaVersion(405));
b123ecb3 1383 return TRUE;
1384}
1385
b8c8a8a7
VK
1386/**
1387 * Upgrade from V403 to V404
1388 */
1389static BOOL H_UpgradeFromV403(int currVersion, int newVersion)
1390{
1391 CHK_EXEC(CreateConfigParam(_T("SyslogIgnoreMessageTimestamp"), _T("0"),
1392 _T("Ignore timestamp received in syslog messages and always use server time"),
1393 'B', true, false, false, false));
e4926628 1394 CHK_EXEC(SetSchemaVersion(404));
b8c8a8a7
VK
1395 return TRUE;
1396}
1397
a18687b9
VK
1398/**
1399 * Upgrade from V402 to V403
1400 */
1401static BOOL H_UpgradeFromV402(int currVersion, int newVersion)
1402{
1403 CHK_EXEC(SQLQuery(_T("DROP TABLE policy_time_range_list")));
1404 CHK_EXEC(SQLQuery(_T("DROP TABLE time_ranges")));
e4926628 1405 CHK_EXEC(SetSchemaVersion(403));
a18687b9
VK
1406 return TRUE;
1407}
1408
ed0a9e41
VK
1409/**
1410 * Upgrade from V401 to V402
1411 */
1412static BOOL H_UpgradeFromV401(int currVersion, int newVersion)
1413{
1414 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_event_log_source ON event_log(event_source)")));
e4926628 1415 CHK_EXEC(SetSchemaVersion(402));
ed0a9e41
VK
1416 return TRUE;
1417}
1418
bad2c02e 1419/**
1420 * Upgrade from V400 to V401
1421 */
1422static BOOL H_UpgradeFromV400(int currVersion, int newVersion)
1423{
3da098f7
VK
1424 CHK_EXEC(CreateEventTemplate(EVENT_LDAP_SYNC_ERROR, _T("SYS_LDAP_SYNC_ERROR"),
1425 SEVERITY_MAJOR, EF_LOG, _T("f7e8508d-1503-4736-854b-1e5b8b0ad1f2"),
1426 _T("LDAP sync error: %5"),
bad2c02e 1427 _T("Generated when LDAP synchronization error occurs.\r\n")
1428 _T("Parameters:\r\n")
1429 _T(" 1) User ID\r\n")
1430 _T(" 2) User GUID\r\n")
1431 _T(" 3) User LDAP DN\r\n")
1432 _T(" 4) User name\r\n")
1433 _T(" 5) Problem description")));
355aa002 1434
3da098f7 1435 int ruleId = NextFreeEPPruleID();
bad2c02e 1436 TCHAR query[1024];
3da098f7 1437 _sntprintf(query, 1024, _T("INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) VALUES (%d,'417648af-5361-49a5-9471-6ef31e857b2d',7944,'Generate an alarm when error occurred during LDAP synchronization','%%m',5,'SYS_LDAP_SYNC_ERROR_%%2','',0,%d,0,'')"), ruleId, EVENT_ALARM_TIMEOUT);
bad2c02e 1438 CHK_EXEC(SQLQuery(query));
50e319a2 1439 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_LDAP_SYNC_ERROR);
bad2c02e 1440 CHK_EXEC(SQLQuery(query));
1441
1442 CHK_EXEC(SQLQuery(_T("ALTER TABLE users ADD ldap_unique_id varchar(64)")));
1443 CHK_EXEC(SQLQuery(_T("ALTER TABLE user_groups ADD ldap_unique_id varchar(64)")));
1444 CHK_EXEC(CreateConfigParam(_T("LdapUserUniqueId"), _T(""), true, false, false));
1445 CHK_EXEC(CreateConfigParam(_T("LdapGroupUniqueId"), _T(""), true, false, false));
1446
e4926628 1447 CHK_EXEC(SetSchemaVersion(401));
bad2c02e 1448 return TRUE;
1449}
355aa002 1450
8e6e8ef1 1451/**
355aa002
TD
1452 * Upgrade from V399 to V400
1453 */
1454static BOOL H_UpgradeFromV399(int currVersion, int newVersion)
1455{
1456 CHK_EXEC(CreateConfigParam(_T("JobRetryCount"), _T("5"), _T("Maximum mumber of job execution retrys"), 'I', true, false, false, false));
e4926628 1457 CHK_EXEC(SetSchemaVersion(400));
355aa002
TD
1458 return TRUE;
1459}
1460
1461/**
1462 * Upgrade from V398 to V399
8e6e8ef1
VK
1463 */
1464static BOOL H_UpgradeFromV398(int currVersion, int newVersion)
1465{
1466 CHK_EXEC(CreateTable(
1467 _T("CREATE TABLE config_repositories (")
1468 _T(" id integer not null,")
1469 _T(" url varchar(1023) not null,")
1470 _T(" auth_token varchar(63) null,")
1471 _T(" description varchar(1023) null,")
1472 _T(" PRIMARY KEY(id))")
1473 ));
1474
e4926628 1475 CHK_EXEC(SetSchemaVersion(399));
8e6e8ef1
VK
1476 return TRUE;
1477}
1478
0de31ec3
VK
1479/**
1480 * Upgrade from V397 to V398
1481 */
1482static BOOL H_UpgradeFromV397(int currVersion, int newVersion)
1483{
1484 CHK_EXEC(CreateTable(
1485 _T("CREATE TABLE currency_codes (")
1486 _T(" numeric_code char(3) not null,")
1487 _T(" alpha_code char(3) not null,")
a27a303e 1488 _T(" description varchar(127) not null,")
0de31ec3
VK
1489 _T(" exponent integer not null,")
1490 _T(" PRIMARY KEY(numeric_code))")
1491 ));
1492
1493 CHK_EXEC(CreateTable(
1494 _T("CREATE TABLE country_codes (")
1495 _T(" numeric_code char(3) not null,")
1496 _T(" alpha_code char(2) not null,")
1497 _T(" alpha3_code char(3) not null,")
a27a303e 1498 _T(" name varchar(127) not null,")
0de31ec3
VK
1499 _T(" PRIMARY KEY(numeric_code))")
1500 ));
1501
dc4472a5 1502 static const TCHAR *batch1 =
0de31ec3
VK
1503 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('008', 'ALL', 'Lek', 2)\n")
1504 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('012', 'DZD', 'Algerian Dinar', 2)\n")
1505 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('031', 'AZM', 'Azerbaijanian Manat', 0)\n")
1506 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('032', 'ARS', 'Argentine Peso', 2)\n")
1507 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('036', 'AUD', 'Australian Dollar', 2)\n")
1508 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('044', 'BSD', 'Bahamian Dollar', 2)\n")
1509 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('048', 'BHD', 'Bahraini Dinar', 3)\n")
1510 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('050', 'BDT', 'Taka', 2)\n")
1511 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('051', 'AMD', 'Armenian Dram', 2)\n")
1512 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('052', 'BBD', 'Barbados Dollar', 2)\n")
1513 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('060', 'BMD', 'Bermudian Dollar', 2)\n")
1514 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('064', 'BTN', 'Ngultrum', 2)\n")
1515 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('068', 'BOB', 'Boliviano', 2)\n")
1516 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('072', 'BWP', 'Pula', 2)\n")
1517 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('084', 'BZD', 'Belize Dollar', 2)\n")
1518 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('090', 'SBD', 'Solomon Islands Dollar', 2)\n")
1519 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('096', 'BND', 'Brunei Dollar', 2)\n")
1520 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('100', 'BGL', 'Lev', 0)\n")
1521 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('104', 'MMK', 'Kyat', 2)\n")
1522 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('108', 'BIF', 'Burundi Franc', 0)\n")
1523 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('116', 'KHR', 'Riel', 2)\n")
1524 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('124', 'CAD', 'Canadian Dollar', 2)\n")
1525 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('132', 'CVE', 'Cape Verde Escudo', 2)\n")
1526 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('136', 'KYD', 'Cayman Islands Dollar', 2)\n")
1527 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('144', 'LKR', 'Sri Lanka Rupee', 2)\n")
1528 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('152', 'CLP', 'Chilean Peso', 0)\n")
1529 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('156', 'CNY', 'Yuan Renminbi', 2)\n")
1530 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('170', 'COP', 'Colombian Peso', 2)\n")
1531 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('174', 'KMF', 'Comoro Franc', 0)\n")
1532 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('188', 'CRC', 'Costa Rican Colon', 2)\n")
1533 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('191', 'HRK', 'Croatian Kuna', 2)\n")
1534 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('192', 'CUP', 'Cuban Peso', 2)\n")
1535 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('196', 'CYP', 'Cyprus Pound', 0)\n")
1536 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('203', 'CZK', 'Czech Koruna', 2)\n")
1537 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('208', 'DKK', 'Danish Krone', 2)\n")
1538 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('214', 'DOP', 'Dominican Peso', 2)\n")
1539 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('222', 'SVC', 'El Salvador Colon', 2)\n")
1540 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('230', 'ETB', 'Ethiopian Birr', 2)\n")
1541 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('232', 'ERN', 'Nakfa', 2)\n")
1542 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('233', 'EEK', 'Estonian Kroon', 0)\n")
1543 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('238', 'FKP', 'Falkland Islands Pound', 2)\n")
1544 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('242', 'FJD', 'Fiji Dollar', 2)\n")
1545 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('262', 'DJF', 'Djibouti Franc', 0)\n")
1546 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('270', 'GMD', 'Dalasi', 2)\n")
1547 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('288', 'GHC', 'Cedi', 0)\n")
1548 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('292', 'GIP', 'Gibraltar Pound', 2)\n")
1549 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('320', 'GTQ', 'Quetzal', 2)\n")
1550 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('324', 'GNF', 'Guinea Franc', 0)\n")
1551 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('328', 'GYD', 'Guyana Dollar', 2)\n")
1552 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('332', 'HTG', 'Gourde', 2)\n")
1553 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('340', 'HNL', 'Lempira', 2)\n")
1554 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('344', 'HKD', 'Hong Kong Dollar', 2)\n")
1555 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('348', 'HUF', 'Forint', 2)\n")
1556 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('352', 'ISK', 'Iceland Krona', 0)\n")
1557 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('356', 'INR', 'Indian Rupee', 2)\n")
1558 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('360', 'IDR', 'Rupiah', 2)\n")
1559 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('364', 'IRR', 'Iranian Rial', 2)\n")
1560 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('368', 'IQD', 'Iraqi Dinar', 3)\n")
1561 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('376', 'ILS', 'New Israeli Sheqel', 2)\n")
1562 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('388', 'JMD', 'Jamaican Dollar', 2)\n")
1563 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('392', 'JPY', 'Yen', 0)\n")
1564 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('398', 'KZT', 'Tenge', 2)\n")
1565 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('400', 'JOD', 'Jordanian Dinar', 3)\n")
1566 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('404', 'KES', 'Kenyan Shilling', 2)\n")
1567 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('408', 'KPW', 'North Korean Won', 2)\n")
1568 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('410', 'KRW', 'Won', 0)\n")
1569 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('414', 'KWD', 'Kuwaiti Dinar', 3)\n")
1570 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('417', 'KGS', 'Som', 2)\n")
1571 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('418', 'LAK', 'Kip', 2)\n")
1572 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('422', 'LBP', 'Lebanese Pound', 2)\n")
1573 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('426', 'LSL', 'Lesotho Loti', 2)\n")
1574 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('428', 'LVL', 'Latvian Lats', 2)\n")
1575 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('430', 'LRD', 'Liberian Dollar', 2)\n")
1576 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('434', 'LYD', 'Lybian Dinar', 3)\n")
1577 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('440', 'LTL', 'Lithuanian Litas', 2)\n")
1578 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('446', 'MOP', 'Pataca', 2)\n")
1579 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('450', 'MGF', 'Malagasy Franc', 0)\n")
1580 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('454', 'MWK', 'Kwacha', 2)\n")
1581 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('458', 'MYR', 'Malaysian Ringgit', 2)\n")
1582 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('462', 'MVR', 'Rufiyaa', 2)\n")
1583 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('470', 'MTL', 'Maltese Lira', 0)\n")
1584 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('478', 'MRO', 'Ouguiya', 2)\n")
1585 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('480', 'MUR', 'Mauritius Rupee', 2)\n")
1586 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('484', 'MXN', 'Mexican Peso', 2)\n")
1587 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('496', 'MNT', 'Tugrik', 2)\n")
1588 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('498', 'MDL', 'Moldovan Leu', 2)\n")
1589 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('504', 'MAD', 'Moroccan Dirham', 2)\n")
1590 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('508', 'MZM', 'Metical', 0)\n")
1591 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('512', 'OMR', 'Rial Omani', 3)\n")
1592 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('516', 'NAD', 'Namibia Dollar', 2)\n")
1593 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('524', 'NPR', 'Nepalese Rupee', 2)\n")
1594 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('532', 'ANG', 'Netherlands Antillan Guilder', 2)\n")
1595 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('533', 'AWG', 'Aruban Guilder', 2)\n")
1596 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('548', 'VUV', 'Vatu', 0)\n")
1597 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('554', 'NZD', 'New Zealand Dollar', 2)\n")
1598 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('558', 'NIO', 'Cordoba Oro', 2)\n")
1599 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('566', 'NGN', 'Naira', 2)\n")
1600 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('578', 'NOK', 'Norvegian Krone', 2)\n")
1601 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('586', 'PKR', 'Pakistan Rupee', 2)\n")
1602 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('590', 'PAB', 'Balboa', 2)\n")
1603 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('598', 'PGK', 'Kina', 2)\n")
1604 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('600', 'PYG', 'Guarani', 0)\n")
1605 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('604', 'PEN', 'Nuevo Sol', 2)\n")
1606 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('608', 'PHP', 'Philippine Peso', 2)\n")
1607 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('624', 'GWP', 'Guinea-Bissau Peso', 0)\n")
1608 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('634', 'QAR', 'Qatari Rial', 2)\n")
1609 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('642', 'ROL', 'Leu', 0)\n")
1610 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('643', 'RUB', 'Russian Ruble', 2)\n")
1611 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('646', 'RWF', 'Rwanda Franc', 0)\n")
1612 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('654', 'SHP', 'Saint Helena Pound', 2)\n")
1613 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('678', 'STD', 'Dobra', 2)\n")
1614 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('682', 'SAR', 'Saudi Riyal', 2)\n")
1615 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('690', 'SCR', 'Seychelles Rupee', 2)\n")
1616 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('694', 'SLL', 'Leone', 2)\n")
1617 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('702', 'SGD', 'Singapore Dollar', 2)\n")
1618 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('703', 'SKK', 'Slovak Koruna', 0)\n")
1619 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('704', 'VND', 'Dong', 0)\n")
1620 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('706', 'SOS', 'Somali Shilling', 2)\n")
1621 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('710', 'ZAR', 'Rand', 2)\n")
1622 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('716', 'ZWD', 'Zimbabwe Dollar', 0)\n")
1623 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('728', 'SSP', 'South Sudanese pound', 2)\n")
1624 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('740', 'SRG', 'Suriname Guilder', 0)\n")
1625 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('748', 'SZL', 'Lilangeni', 2)\n")
1626 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('752', 'SEK', 'Swedish Krona', 2)\n")
1627 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('756', 'CHF', 'Swiss Franc', 2)\n")
1628 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('760', 'SYP', 'Syrian Pound', 2)\n")
1629 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('764', 'THB', 'Baht', 2)\n")
1630 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('776', 'TOP', 'Paanga', 2)\n")
1631 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('780', 'TTD', 'Trinidad and Tobago Dollar', 2)\n")
1632 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('784', 'AED', 'UAE Dirham', 2)\n")
1633 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('788', 'TND', 'Tunisian Dinar', 3)\n")
1634 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('795', 'TMM', 'Manat', 0)\n")
1635 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('800', 'UGX', 'Uganda Shilling', 2)\n")
1636 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('807', 'MKD', 'Denar', 2)\n")
1637 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('810', 'RUR', 'Russian Ruble', 0)\n")
1638 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('818', 'EGP', 'Egyptian Pound', 2)\n")
1639 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('826', 'GBP', 'Pound Sterling', 2)\n")
1640 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('834', 'TZS', 'Tanzanian Shilling', 2)\n")
1641 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('840', 'USD', 'US Dollar', 2)\n")
1642 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('858', 'UYU', 'Peso Uruguayo', 2)\n")
1643 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('860', 'UZS', 'Uzbekistan Sum', 2)\n")
1644 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('862', 'VEB', 'Bolivar', 0)\n")
1645 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('882', 'WST', 'Tala', 2)\n")
1646 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('886', 'YER', 'Yemeni Rial', 2)\n")
1647 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('891', 'CSD', 'Serbian Dinar', 0)\n")
1648 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('894', 'ZMK', 'Kwacha', 2)\n")
1649 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('901', 'TWD', 'New Taiwan Dollar', 2)\n")
1650 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('933', 'BYN', 'Belarussian New Ruble', 2)\n")
1651 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('934', 'TMT', 'Turkmenistani Manat', 2)\n")
1652 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('937', 'VEF', 'Venezuelan Bolivar', 2)\n")
1653 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('938', 'SDG', 'Sudanese Pound', 2)\n")
1654 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('941', 'RSD', 'Serbian Dinar', 2)\n")
1655 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('943', 'MZN', 'Mozambican Metical', 2)\n")
1656 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('944', 'AZN', 'Azerbaijani Manat', 2)\n")
1657 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('946', 'RON', 'New Romanian Leu', 2)\n")
1658 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('949', 'TRY', 'New Turkish Lira', 2)\n")
1659 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('950', 'XAF', 'CFA Franc BEAC', 0)\n")
1660 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('951', 'XCD', 'East Carribbean Dollar', 2)\n")
1661 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('952', 'XOF', 'CFA Franc BCEAO', 0)\n")
1662 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('953', 'XPF', 'CFP Franc', 0)\n")
1663 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('967', 'ZMW', 'Zambian Kwacha', 2)\n")
1664 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('968', 'SRD', 'Surinamese Dollar', 2)\n")
1665 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('969', 'MGA', 'Malagasy Ariary', 2)\n")
1666 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('971', 'AFN', 'Afghani', 2)\n")
1667 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('972', 'TJS', 'Somoni', 2)\n")
1668 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('973', 'AOA', 'Kwanza', 2)\n")
1669 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('974', 'BYR', 'Belarussian Ruble', 0)\n")
1670 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('975', 'BGN', 'Bulgarian Lev', 2)\n")
1671 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('976', 'CDF', 'Franc Congolais', 2)\n")
1672 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('977', 'BAM', 'Convertible Marks', 2)\n")
1673 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('978', 'EUR', 'Euro', 2)\n")
1674 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('979', 'MXV', 'Mexican Unidad de Inversion (UDI)', 2)\n")
1675 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('980', 'UAH', 'Hryvnia', 2)\n")
1676 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('981', 'GEL', 'Lari', 2)\n")
1677 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('984', 'BOV', 'Mvdol', 2)\n")
1678 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('985', 'PLN', 'Zloty', 2)\n")
1679 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('986', 'BRL', 'Brazilian Real', 2)\n")
1680 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('990', 'CLF', 'Unidades de Fomento', 0)\n")
1681 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('997', 'USN', 'US dollar (next day funds code)', 2)\n")
1682 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('998', 'USS', 'US dollar (same day funds code)', 2)\n")
1683 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('999', 'XXX', 'No currency', 0)\n")
dc4472a5
VK
1684 _T("<END>");
1685 static const TCHAR *batch2 =
0de31ec3
VK
1686 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AD','AND','020','Andorra')\n")
1687 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AE','ARE','784','United Arab Emirates')\n")
1688 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AF','AFG','004','Afghanistan')\n")
1689 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AG','ATG','028','Antigua and Barbuda')\n")
1690 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AI','AIA','660','Anguilla')\n")
1691 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AL','ALB','008','Albania')\n")
1692 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AM','ARM','051','Armenia')\n")
1693 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AN','ANT','530','Netherlands Antilles')\n")
1694 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AO','AGO','024','Angola')\n")
1695 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AQ','ATA','010','Antarctica')\n")
1696 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AR','ARG','032','Argentina')\n")
1697 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AS','ASM','016','American Samoa')\n")
1698 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AT','AUT','040','Austria')\n")
1699 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AU','AUS','036','Australia')\n")
1700 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AW','ABW','533','Aruba')\n")
1701 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AX','ALA','248','Aland Islands')\n")
1702 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AZ','AZE','031','Azerbaijan')\n")
1703 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BA','BIH','070','Bosnia and Herzegovina')\n")
1704 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BB','BRB','052','Barbados')\n")
1705 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BD','BGD','050','Bangladesh')\n")
1706 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BE','BEL','056','Belgium')\n")
1707 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BF','BFA','854','Burkina Faso')\n")
1708 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BG','BGR','100','Bulgaria')\n")
1709 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BH','BHR','048','Bahrain')\n")
1710 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BI','BDI','108','Burundi')\n")
1711 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BJ','BEN','204','Benin')\n")
1712 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BL','BLM','652','Saint-Barthelemy')\n")
1713 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BM','BMU','060','Bermuda')\n")
1714 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BN','BRN','096','Brunei Darussalam')\n")
1715 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BO','BOL','068','Bolivia')\n")
1716 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BQ','BES','535','Bonaire, Sint Eustatius and Saba')\n")
1717 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BR','BRA','076','Brazil')\n")
1718 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BS','BHS','044','Bahamas')\n")
1719 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BT','BTN','064','Bhutan')\n")
1720 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BV','BVT','074','Bouvet Island')\n")
1721 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BW','BWA','072','Botswana')\n")
1722 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BY','BLR','112','Belarus')\n")
1723 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BZ','BLZ','084','Belize')\n")
1724 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CA','CAN','124','Canada')\n")
1725 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CC','CCK','166','Cocos (Keeling) Islands')\n")
1726 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CD','COD','180','Congo, Democratic Republic of the')\n")
1727 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CF','CAF','140','Central African Republic')\n")
1728 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CG','COG','178','Congo (Brazzaville)')\n")
1729 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CH','CHE','756','Switzerland')\n")
1730 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CI','CIV','384','Cote d''Ivoire')\n")
1731 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CK','COK','184','Cook Islands')\n")
1732 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CL','CHL','152','Chile')\n")
1733 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CM','CMR','120','Cameroon')\n")
1734 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CN','CHN','156','China')\n")
1735 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CO','COL','170','Colombia')\n")
1736 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CR','CRI','188','Costa Rica')\n")
1737 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CU','CUB','192','Cuba')\n")
1738 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CV','CPV','132','Cape Verde')\n")
1739 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CW','CUW','531','Curacao')\n")
1740 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CX','CXR','162','Christmas Island')\n")
1741 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CY','CYP','196','Cyprus')\n")
1742 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CZ','CZE','203','Czech Republic')\n")
1743 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('DE','DEU','276','Germany')\n")
1744 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('DJ','DJI','262','Djibouti')\n")
1745 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('DK','DNK','208','Denmark')\n")
1746 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('DM','DMA','212','Dominica')\n")
1747 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('DO','DOM','214','Dominican Republic')\n")
1748 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('DZ','DZA','012','Algeria')\n")
1749 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('EC','ECU','218','Ecuador')\n")
1750 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('EE','EST','233','Estonia')\n")
1751 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('EG','EGY','818','Egypt')\n")
1752 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('EH','ESH','732','Western Sahara')\n")
1753 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('ER','ERI','232','Eritrea')\n")
1754 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('ES','ESP','724','Spain')\n")
1755 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('ET','ETH','231','Ethiopia')\n")
1756 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('FI','FIN','246','Finland')\n")
1757 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('FJ','FJI','242','Fiji')\n")
1758 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('FK','FLK','238','Falkland Islands (Malvinas)')\n")
1759 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('FM','FSM','583','Micronesia, Federated States of')\n")
1760 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('FO','FRO','234','Faroe Islands')\n")
1761 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('FR','FRA','250','France')\n")
1762 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GA','GAB','266','Gabon')\n")
1763 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GB','GBR','826','United Kingdom')\n")
1764 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GD','GRD','308','Grenada')\n")
1765 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GE','GEO','268','Georgia')\n")
1766 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GF','GUF','254','French Guiana')\n")
1767 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GG','GGY','831','Guernsey')\n")
1768 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GH','GHA','288','Ghana')\n")
1769 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GI','GIB','292','Gibraltar')\n")
1770 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GL','GRL','304','Greenland')\n")
1771 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GM','GMB','270','Gambia')\n")
1772 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GN','GIN','324','Guinea')\n")
1773 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GP','GLP','312','Guadeloupe')\n")
1774 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GQ','GNQ','226','Equatorial Guinea')\n")
1775 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GR','GRC','300','Greece')\n")
1776 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GS','SGS','239','South Georgia and the South Sandwich Islands')\n")
1777 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GT','GTM','320','Guatemala')\n")
1778 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GU','GUM','316','Guam')\n")
1779 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GW','GNB','624','Guinea-Bissau')\n")
1780 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GY','GUY','328','Guyana')\n")
1781 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('HK','HKG','344','Hong Kong, Special Administrative Region of China')\n")
1782 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('HM','HMD','334','Heard Island and Mcdonald Islands')\n")
1783 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('HN','HND','340','Honduras')\n")
1784 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('HR','HRV','191','Croatia')\n")
1785 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('HT','HTI','332','Haiti')\n")
1786 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('HU','HUN','348','Hungary')\n")
1787 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('ID','IDN','360','Indonesia')\n")
1788 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('IE','IRL','372','Ireland')\n")
1789 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('IL','ISR','376','Israel')\n")
1790 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('IM','IMN','833','Isle of Man')\n")
1791 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('IN','IND','356','India')\n")
1792 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('IO','IOT','086','British Indian Ocean Territory')\n")
1793 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('IQ','IRQ','368','Iraq')\n")
1794 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('IR','IRN','364','Iran, Islamic Republic of')\n")
1795 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('IS','ISL','352','Iceland')\n")
1796 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('IT','ITA','380','Italy')\n")
1797 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('JE','JEY','832','Jersey')\n")
1798 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('JM','JAM','388','Jamaica')\n")
1799 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('JO','JOR','400','Jordan')\n")
1800 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('JP','JPN','392','Japan')\n")
1801 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KE','KEN','404','Kenya')\n")
1802 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KG','KGZ','417','Kyrgyzstan')\n")
1803 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KH','KHM','116','Cambodia')\n")
1804 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KI','KIR','296','Kiribati')\n")
1805 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KM','COM','174','Comoros')\n")
1806 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KN','KNA','659','Saint Kitts and Nevis')\n")
1807 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KP','PRK','408','Korea, Democratic People''s Republic of')\n")
1808 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KR','KOR','410','Korea, Republic of')\n")
1809 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KW','KWT','414','Kuwait')\n")
1810 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KY','CYM','136','Cayman Islands')\n")
1811 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KZ','KAZ','398','Kazakhstan')\n")
1812 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LA','LAO','418','Lao PDR')\n")
1813 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LB','LBN','422','Lebanon')\n")
1814 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LC','LCA','662','Saint Lucia')\n")
1815 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LI','LIE','438','Liechtenstein')\n")
1816 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LK','LKA','144','Sri Lanka')\n")
1817 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LR','LBR','430','Liberia')\n")
1818 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LS','LSO','426','Lesotho')\n")
1819 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LT','LTU','440','Lithuania')\n")
1820 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LU','LUX','442','Luxembourg')\n")
1821 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LV','LVA','428','Latvia')\n")
1822 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LY','LBY','434','Libya')\n")
1823 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MA','MAR','504','Morocco')\n")
1824 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MC','MCO','492','Monaco')\n")
1825 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MD','MDA','498','Moldova')\n")
1826 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('ME','MNE','499','Montenegro')\n")
1827 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MF','MAF','663','Saint-Martin (French part)')\n")
1828 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MG','MDG','450','Madagascar')\n")
1829 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MH','MHL','584','Marshall Islands')\n")
1830 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MK','MKD','807','Macedonia, Republic of')\n")
1831 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('ML','MLI','466','Mali')\n")
1832 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MM','MMR','104','Myanmar')\n")
1833 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MN','MNG','496','Mongolia')\n")
1834 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MO','MAC','446','Macao, Special Administrative Region of China')\n")
1835 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MP','MNP','580','Northern Mariana Islands')\n")
1836 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MQ','MTQ','474','Martinique')\n")
1837 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MR','MRT','478','Mauritania')\n")
1838 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MS','MSR','500','Montserrat')\n")
1839 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MT','MLT','470','Malta')\n")
1840 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MU','MUS','480','Mauritius')\n")
1841 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MV','MDV','462','Maldives')\n")
1842 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MW','MWI','454','Malawi')\n")
1843 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MX','MEX','484','Mexico')\n")
1844 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MY','MYS','458','Malaysia')\n")
1845 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MZ','MOZ','508','Mozambique')\n")
1846 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('NA','NAM','516','Namibia')\n")
1847 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('NC','NCL','540','New Caledonia')\n")
1848 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('NE','NER','562','Niger')\n")
1849 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('NF','NFK','574','Norfolk Island')\n")
1850 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('NG','NGA','566','Nigeria')\n")
1851 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('NI','NIC','558','Nicaragua')\n")
1852 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('NL','NLD','528','Netherlands')\n")
1853 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('NO','NOR','578','Norway')\n")
1854 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('NP','NPL','524','Nepal')\n")
1855 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('NR','NRU','520','Nauru')\n")
1856 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('NU','NIU','570','Niue')\n")
1857 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('NZ','NZL','554','New Zealand')\n")
1858 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('OM','OMN','512','Oman')\n")
1859 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('PA','PAN','591','Panama')\n")
1860 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('PE','PER','604','Peru')\n")
1861 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('PF','PYF','258','French Polynesia')\n")
1862 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('PG','PNG','598','Papua New Guinea')\n")
1863 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('PH','PHL','608','Philippines')\n")
1864 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('PK','PAK','586','Pakistan')\n")
1865 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('PL','POL','616','Poland')\n")
1866 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('PM','SPM','666','Saint Pierre and Miquelon')\n")
1867 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('PN','PCN','612','Pitcairn')\n")
1868 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('PR','PRI','630','Puerto Rico')\n")
1869 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('PS','PSE','275','Palestinian Territory, Occupied')\n")
1870 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('PT','PRT','620','Portugal')\n")
1871 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('PW','PLW','585','Palau')\n")
1872 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('PY','PRY','600','Paraguay')\n")
1873 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('QA','QAT','634','Qatar')\n")
1874 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('RE','REU','638','Reunion')\n")
1875 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('RO','ROU','642','Romania')\n")
1876 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('RS','SRB','688','Serbia')\n")
1877 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('RU','RUS','643','Russian Federation')\n")
1878 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('RW','RWA','646','Rwanda')\n")
1879 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('SA','SAU','682','Saudi Arabia')\n")
1880 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('SB','SLB','090','Solomon Islands')\n")
1881 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('SC','SYC','690','Seychelles')\n")
1882 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('SD','SDN','729','Sudan')\n")
1883 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('SE','SWE','752','Sweden')\n")
1884 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('SG','SGP','702','Singapore')\n")
1885 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('SH','SHN','654','Saint Helena')\n")
1886 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('SI','SVN','705','Slovenia')\n")
1887 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('SJ','SJM','744','Svalbard and Jan Mayen Islands')\n")
1888 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('SK','SVK','703','Slovakia')\n")
1889 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('SL','SLE','694','Sierra Leone')\n")
1890 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('SM','SMR','674','San Marino')\n")
1891 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('SN','SEN','686','Senegal')\n")
1892 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('SO','SOM','706','Somalia')\n")
1893 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('SR','SUR','740','Suriname')\n")
1894 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('SS','SSD','728','South Sudan')\n")
1895 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('ST','STP','678','Sao Tome and Principe')\n")
1896 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('SV','SLV','222','El Salvador')\n")
1897 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('SX','SXM','534','Sint Maarten (Dutch part)')\n")
1898 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('SY','SYR','760','Syrian Arab Republic (Syria)')\n")
1899 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('SZ','SWZ','748','Swaziland')\n")
1900 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('TC','TCA','796','Turks and Caicos Islands')\n")
1901 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('TD','TCD','148','Chad')\n")
1902 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('TF','ATF','260','French Southern Territories')\n")
1903 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('TG','TGO','768','Togo')\n")
1904 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('TH','THA','764','Thailand')\n")
1905 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('TJ','TJK','762','Tajikistan')\n")
1906 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('TK','TKL','772','Tokelau')\n")
1907 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('TL','TLS','626','Timor-Leste')\n")
1908 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('TM','TKM','795','Turkmenistan')\n")
1909 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('TN','TUN','788','Tunisia')\n")
1910 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('TO','TON','776','Tonga')\n")
1911 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('TR','TUR','792','Turkey')\n")
1912 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('TT','TTO','780','Trinidad and Tobago')\n")
1913 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('TV','TUV','798','Tuvalu')\n")
1914 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('TW','TWN','158','Taiwan')\n")
1915 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('TZ','TZA','834','Tanzania')\n")
1916 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('UA','UKR','804','Ukraine')\n")
1917 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('UG','UGA','800','Uganda')\n")
1918 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('UM','UMI','581','United States Minor Outlying Islands')\n")
1919 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('US','USA','840','United States of America')\n")
1920 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('UY','URY','858','Uruguay')\n")
1921 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('UZ','UZB','860','Uzbekistan')\n")
1922 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('VA','VAT','336','Holy See (Vatican City State)')\n")
1923 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('VC','VCT','670','Saint Vincent and Grenadines')\n")
1924 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('VE','VEN','862','Venezuela')\n")
1925 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('VG','VGB','092','British Virgin Islands')\n")
1926 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('VI','VIR','850','Virgin Islands, US')\n")
1927 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('VN','VNM','704','Viet Nam')\n")
1928 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('VU','VUT','548','Vanuatu')\n")
1929 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('WF','WLF','876','Wallis and Futuna Islands')\n")
1930 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('WS','WSM','882','Samoa')\n")
1931 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('YE','YEM','887','Yemen')\n")
1932 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('YT','MYT','175','Mayotte')\n")
1933 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('ZA','ZAF','710','South Africa')\n")
1934 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('ZM','ZMB','894','Zambia')\n")
1935 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('ZW','ZWE','716','Zimbabwe')\n")
1936 _T("<END>");
dc4472a5
VK
1937 CHK_EXEC(SQLBatch(batch1));
1938 CHK_EXEC(SQLBatch(batch2));
0de31ec3 1939
e4926628 1940 CHK_EXEC(SetSchemaVersion(398));
0de31ec3
VK
1941 return TRUE;
1942}
1943
50963ced
VK
1944/**
1945 * Upgrade from V396 to V397
1946 */
1947static BOOL H_UpgradeFromV396(int currVersion, int newVersion)
1948{
1949 static GUID_MAPPING eventGuidMapping[] = {
1950 { EVENT_NODE_ADDED, _T("8d34acfd-dad6-4f6e-b6a8-1189683591ef") },
1951 { EVENT_SUBNET_ADDED, _T("75fc3f8b-768f-46b4-bf44-72949436a679") },
1952 { EVENT_INTERFACE_ADDED, _T("33cb8f9c-9427-459c-8a71-45c73f5cc183") },
1953 { EVENT_INTERFACE_UP, _T("09ee209a-0e75-434f-b8c8-399d93305d7b") },
1954 { EVENT_INTERFACE_DOWN, _T("d9a6d46d-97f8-48eb-a86a-2c0f6b150d0d") },
1955 { EVENT_INTERFACE_UNKNOWN, _T("ecb47be1-f911-4c1f-9b00-d0d21694071d") },
1956 { EVENT_INTERFACE_DISABLED, _T("2f3123a2-425f-47db-9c6b-9bc05a7fba2d") },
1957 { EVENT_INTERFACE_TESTING, _T("eb500e5c-3560-4394-8f5f-80aa67036f13") },
1958 { EVENT_INTERFACE_UNEXPECTED_UP, _T("ff21a165-9253-4ecc-929a-ffd1e388d504") },
1959 { EVENT_INTERFACE_EXPECTED_DOWN, _T("911358f4-d2a1-4465-94d7-ce4bc5c38860") },
1960 { EVENT_NODE_NORMAL, _T("03bc11c0-ec20-43be-be45-e60846f744dc") },
1961 { EVENT_NODE_WARNING, _T("1c80deab-aafb-43a7-93a7-1330dd563b47") },
1962 { EVENT_NODE_MINOR, _T("84eaea00-4ed7-41eb-9079-b783e5c60651") },
1963 { EVENT_NODE_MAJOR, _T("27035c88-c27a-4c16-97b3-4658d34a5f63") },
1964 { EVENT_NODE_CRITICAL, _T("8f2e98f8-1cd4-4e12-b41f-48b5c60ebe8e") },
1965 { EVENT_NODE_UNKNOWN, _T("6933cce0-fe1f-4123-817f-af1fb9f0eab4") },
1966 { EVENT_NODE_UNMANAGED, _T("a8356ba7-51b7-4487-b74e-d12132db233c") },
1967 { EVENT_NODE_FLAGS_CHANGED, _T("b04e39f5-d3a7-4d9a-b594-37132f5eaf34") },
1968 { EVENT_SNMP_FAIL, _T("d2fc3b0c-1215-4a92-b8f3-47df5d753602") },
1969 { EVENT_AGENT_FAIL, _T("ba484457-3594-418e-a72a-65336055d025") },
1970 { EVENT_INTERFACE_DELETED, _T("ad7e9856-e361-4095-9361-ccc462d93624") },
1971 { EVENT_THRESHOLD_REACHED, _T("05161c3d-7ceb-406f-af0a-af5c77f324a5") },
1972 { EVENT_THRESHOLD_REARMED, _T("25eef3a7-6158-4c5e-b4e3-8a7aa7ade73c") },
1973 { EVENT_SUBNET_DELETED, _T("af188eb3-e84f-4fd9-aecf-f1ba934a9f1a") },
1974 { EVENT_THREAD_HANGS, _T("df247d13-a63a-43fe-bb02-cb41718ee387") },
1975 { EVENT_THREAD_RUNNING, _T("5589f6ce-7133-44db-8e7a-e1452d636a9a") },
1976 { EVENT_SMTP_FAILURE, _T("1e376009-0d26-4b86-87a2-f4715a02fb38") },
1977 { EVENT_MAC_ADDR_CHANGED, _T("61916ef0-1eee-4df7-a95b-150928d47962") },
1978 { EVENT_INCORRECT_NETMASK, _T("86c08c55-416e-4ac4-bf2b-302b5fddbd68") },
1979 { EVENT_NODE_DOWN, _T("ce34f0d0-5b21-48c2-8788-8ed5ee547023") },
1980 { EVENT_NODE_UP, _T("05f180b6-62e7-4bc4-8a8d-34540214254b") },
1981 { EVENT_SERVICE_DOWN, _T("89caacb5-d2cf-493b-862f-cddbfecac5b6") },
1982 { EVENT_SERVICE_UP, _T("ab35e7c7-2428-44db-ad43-57fe551bb8cc") },
1983 { EVENT_SERVICE_UNKNOWN, _T("d891adae-49fe-4442-a8f3-0ca37ca8820a") },
1984 { EVENT_SMS_FAILURE, _T("c349bf75-458a-4d43-9c27-f71ea4bb06e2") },
1985 { EVENT_SNMP_OK, _T("a821086b-1595-40db-9148-8d770d30a54b") },
1986 { EVENT_AGENT_OK, _T("9c15299a-f2e3-4440-84c5-b17dea87ae2a") },
1987 { EVENT_SCRIPT_ERROR, _T("2cc78efe-357a-4278-932f-91e36754c775") },
1988 { EVENT_CONDITION_ACTIVATED, _T("16a86780-b73a-4601-929c-0c503bd06401") },
1989 { EVENT_CONDITION_DEACTIVATED, _T("926d15d2-9761-4bb6-a1ce-64175303796f") },
1990 { EVENT_DB_CONNECTION_LOST, _T("0311e9c8-8dcf-4a5b-9036-8cff034409ff") },
1991 { EVENT_DB_CONNECTION_RESTORED, _T("d36259a7-5f6b-4e3c-bb6f-17d1f8ac950d") },
1992 { EVENT_CLUSTER_RESOURCE_MOVED, _T("44abe5f3-a7c9-4fbd-8d10-53be172eae83") },
1993 { EVENT_CLUSTER_RESOURCE_DOWN, _T("c3b1d4b5-2e41-4a2f-b379-9d74ebba3a25") },
1994 { EVENT_CLUSTER_RESOURCE_UP, _T("ef6fff96-0cbb-4030-aeba-2473a80c6568") },
1995 { EVENT_CLUSTER_DOWN, _T("8f14d0f7-08d4-4422-92f4-469e5eef93ef") },
1996 { EVENT_CLUSTER_UP, _T("4a9cdb65-aa44-42f2-99b0-1e302aec10f6") },
1997 { EVENT_ALARM_TIMEOUT, _T("4ae4f601-327b-4ef8-9740-8600a1ba2acd") },
1998 { EVENT_LOG_RECORD_MATCHED, _T("d9326159-5c60-410f-990e-fae88df7fdd4") },
1999 { EVENT_EVENT_STORM_DETECTED, _T("c98d8575-d134-4044-ba67-75c5f5d0f6e0") },
2000 { EVENT_EVENT_STORM_ENDED, _T("dfd5e3ba-3182-4deb-bc32-9e6b8c1c6546") },
2001 { EVENT_NETWORK_CONNECTION_LOST, _T("3cb0921a-87a1-46e4-8be1-82ad2dda0015") },
2002 { EVENT_NETWORK_CONNECTION_RESTORED, _T("1c61b3e0-389a-47ac-8469-932a907392bc") },
2003 { EVENT_DB_QUERY_FAILED, _T("5f35d646-63b6-4dcd-b94a-e2ccd060686a") },
2004 { EVENT_DCI_UNSUPPORTED, _T("28367b5b-1541-4526-8cbe-91a17ed31ba4") },
2005 { EVENT_DCI_DISABLED, _T("50196042-0619-4420-9471-16b7c25c0213") },
2006 { EVENT_DCI_ACTIVE, _T("740b6810-b355-46f4-a921-65118504af18") },
2007 { EVENT_IP_ADDRESS_CHANGED, _T("517b6d2a-f5c6-46aa-969d-48e62e05e3bf") },
2008 { EVENT_CONTAINER_AUTOBIND, _T("611133e2-1f76-446f-b278-9d500a823611") },
2009 { EVENT_CONTAINER_AUTOUNBIND, _T("e57603be-0d81-41aa-b07c-12d08640561c") },
2010 { EVENT_TEMPLATE_AUTOAPPLY, _T("bf084945-f928-4428-8c6c-d2965addc832") },
2011 { EVENT_TEMPLATE_AUTOREMOVE, _T("8f7a4b4a-d0a2-4404-9b66-fdbc029f42cf") },
2012 { EVENT_NODE_UNREACHABLE, _T("47bba2ce-c795-4e56-ad44-cbf05741e1ff") },
2013 { EVENT_TABLE_THRESHOLD_ACTIVATED, _T("c08a1cfe-3128-40c2-99cc-378e7ef91f79") },
2014 { EVENT_TABLE_THRESHOLD_DEACTIVATED, _T("479085e7-e1d1-4f2a-9d96-1d522f51b26a") },
2015 { EVENT_IF_PEER_CHANGED, _T("a3a5c1df-9d96-4e98-9e06-b3157dbf39f0") },
2016 { EVENT_AP_ADOPTED, _T("5aaee261-0c5d-44e0-b2f0-223bbba5297d") },
2017 { EVENT_AP_UNADOPTED, _T("846a3581-aad1-4e17-9c55-9bd2e6b1247b") },
2018 { EVENT_AP_DOWN, _T("2c8c6208-d3ab-4b8c-926a-872f4d8abcee") },
2019 { EVENT_IF_MASK_CHANGED, _T("f800e593-057e-4aec-9e47-be0f7718c5c4") },
2020 { EVENT_IF_IPADDR_ADDED, _T("475bdca6-543e-410b-9aff-c217599e0fe6") },
2021 { EVENT_IF_IPADDR_DELETED, _T("ef477387-eb50-4a1a-bf90-717502b9873c") },
2022 { EVENT_MAINTENANCE_MODE_ENTERED, _T("5f6c8b1c-f162-413e-8028-80e7ad2c362d") },
2023 { EVENT_MAINTENANCE_MODE_LEFT, _T("cab06848-a622-430d-8b4c-addeea732657") },
2024 { EVENT_SNMP_UNMATCHED_TRAP, _T("fc3613f7-d151-4221-9acd-d28b6f804335") },
2025 { EVENT_SNMP_COLD_START, _T("39920e99-97bd-4d61-a462-43f89ba6fbdf") },
2026 { EVENT_SNMP_WARM_START, _T("0aa888c1-eba6-4fe7-a37a-b85f2b373bdc") },
2027 { EVENT_SNMP_LINK_DOWN, _T("b71338cc-137d-473c-a0f1-6b131086af56") },
2028 { EVENT_SNMP_LINK_UP, _T("03da14a7-e39c-4a46-a7cb-4bf77ec7936c") },
2029 { EVENT_SNMP_AUTH_FAILURE, _T("37020cb0-dde7-487b-9cfb-0d5ee771aa13") },
2030 { EVENT_SNMP_EGP_NL, _T("aecf5fa4-390c-4125-be10-df8b0e669fe1") },
2031 { 0, NULL }
2032 };
2033
2034 CHK_EXEC(SQLQuery(_T("ALTER TABLE event_cfg ADD guid varchar(36)")));
2035 CHK_EXEC(GenerateGUID(_T("event_cfg"), _T("event_code"), _T("guid"), eventGuidMapping));
e4926628 2036 CHK_EXEC(SetSchemaVersion(397));
50963ced
VK
2037 return TRUE;
2038}
2039
3df8bccd
Z
2040/**
2041 * Upgrade from V395 to V396
2042 */
2043static BOOL H_UpgradeFromV395(int currVersion, int newVersion)
2044{
2045 CHK_EXEC(CreateTable(
2046 _T("CREATE TABLE ap_log_parser (")
2047 _T(" policy_id integer not null,")
2048 _T(" file_content $SQL:TEXT null,")
2049 _T(" PRIMARY KEY(policy_id))")));
2050
e4926628 2051 CHK_EXEC(SetSchemaVersion(396));
3df8bccd
Z
2052 return TRUE;
2053}
2054
fdef3439
Z
2055/**
2056 * Upgrade from V394 to V395
2057 */
2058static BOOL H_UpgradeFromV394(int currVersion, int newVersion)
2059{
f6456d80 2060 CHK_EXEC(SQLQuery(_T("UPDATE config SET need_server_restart='1' WHERE var_name='OfflineDataRelevanceTime'")));
e4926628 2061 CHK_EXEC(SetSchemaVersion(395));
fdef3439
Z
2062 return TRUE;
2063}
2064
7f418694
Z
2065/**
2066 * Upgrade from V393 to V394
2067 */
2068static BOOL H_UpgradeFromV393(int currVersion, int newVersion)
2069{
c0e0623b 2070 CHK_EXEC(CreateConfigParam(_T("OfflineDataRelevanceTime"), _T("86400"), _T("Time period in seconds within which received offline data still relevant for threshold validation"), 'I', true, false, false, false));
e4926628 2071 CHK_EXEC(SetSchemaVersion(394));
7f418694
Z
2072 return TRUE;
2073}
2074
c908b63b
VK
2075/**
2076 * Upgrade from V392 to V393
2077 */
2078static BOOL H_UpgradeFromV392(int currVersion, int newVersion)
2079{
2080 CHK_EXEC(CreateConfigParam(_T("DefaultInterfaceExpectedState"), _T("0"), _T("Default expected state for new interface objects"), 'C', true, false, false, false));
e4926628 2081 CHK_EXEC(SetSchemaVersion(393));
c908b63b
VK
2082 return TRUE;
2083}
2084
2085/**
03b96461
VK
2086 * Upgrade from V391 to V392
2087 */
2088static BOOL H_UpgradeFromV391(int currVersion, int newVersion)
2089{
2090 CHK_EXEC(CreateConfigParam(_T("ImportConfigurationOnStartup"), _T("0"), _T("Import configuration from local files on server startup"), 'B', true, true, false, false));
e4926628 2091 CHK_EXEC(SetSchemaVersion(392));
03b96461
VK
2092 return TRUE;
2093}
2094
c908b63b 2095/**
f61f151c
AK
2096 * Upgrade from V390 to V391
2097 */
2098static BOOL H_UpgradeFromV390(int currVersion, int newVersion)
2099{
03b96461
VK
2100 CHK_EXEC(CreateTable(
2101 _T("CREATE TABLE zmq_subscription (")
2102 _T(" object_id integer not null,")
2103 _T(" subscription_type char(1) not null,")
2104 _T(" ignore_items integer not null,")
2105 _T(" items $SQL:TEXT,")
2106 _T(" PRIMARY KEY(object_id, subscription_type))")));
f61f151c 2107
e4926628 2108 CHK_EXEC(SetSchemaVersion(391));
f61f151c
AK
2109 return TRUE;
2110}
2111
23464115
VK
2112/**
2113 * Upgrade from V389 to V390
2114 */
2115static BOOL H_UpgradeFromV389(int currVersion, int newVersion)
2116{
2117 CHK_EXEC(CreateTable(
2118 _T("CREATE TABLE object_containers (")
2119 _T(" id integer not null,")
2120 _T(" object_class integer not null,")
2121 _T(" flags integer not null,")
2122 _T(" auto_bind_filter $SQL:TEXT null,")
2123 _T(" PRIMARY KEY(id))")));
2124
2125 DB_RESULT hResult = SQLSelect(_T("SELECT id,object_class,flags,auto_bind_filter FROM containers"));
2126 if (hResult != NULL)
2127 {
2128 int count = DBGetNumRows(hResult);
2129 if (count > 0)
2130 {
2131 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("INSERT INTO object_containers (id,object_class,flags,auto_bind_filter) VALUES (?,?,?,?)"));
2132 if (hStmt != NULL)
2133 {
2134 for(int i = 0; i < count; i++)
2135 {
2136 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 0));
2137 DBBind(hStmt, 2, DB_SQLTYPE_INTEGER, DBGetFieldLong(hResult, i, 1));
2138 DBBind(hStmt, 3, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 2));
2139 DBBind(hStmt, 4, DB_SQLTYPE_TEXT, DBGetField(hResult, i, 3, NULL, 0), DB_BIND_DYNAMIC);
2140 if (!SQLExecute(hStmt))
2141 {
2142 if (!g_bIgnoreErrors)
2143 {
2144 DBFreeStatement(hStmt);
2145 DBFreeResult(hResult);
2146 return FALSE;
2147 }
2148 }
2149 }
2150 DBFreeStatement(hStmt);
2151 }
2152 else if (!g_bIgnoreErrors)
2153 {
2154 DBFreeResult(hResult);
2155 return FALSE;
2156 }
2157 }
2158 DBFreeResult(hResult);
2159 }
2160 else
2161 {
2162 if (!g_bIgnoreErrors)
2163 return FALSE;
2164 }
2165
2166 CHK_EXEC(SQLQuery(_T("DROP TABLE containers")));
2167 CHK_EXEC(SQLQuery(_T("DROP TABLE container_categories")));
e4926628 2168 CHK_EXEC(SetSchemaVersion(390));
23464115
VK
2169 return TRUE;
2170}
2171
b120cd0f
VK
2172/**
2173 * Upgrade from V388 to V389
2174 */
2175static BOOL H_UpgradeFromV388(int currVersion, int newVersion)
2176{
2177 static TCHAR batch[] =
2178 _T("ALTER TABLE racks ADD top_bottom_num char(1)\n")
2179 _T("UPDATE racks SET top_bottom_num='0'\n")
2180 _T("<END>");
2181 CHK_EXEC(SQLBatch(batch));
e4926628 2182 CHK_EXEC(SetSchemaVersion(389));
b120cd0f
VK
2183 return TRUE;
2184}
2185
65ce7452
VK
2186/**
2187 * Upgrade from V387 to V388
2188 */
2189static BOOL H_UpgradeFromV387(int currVersion, int newVersion)
2190{
2191 static TCHAR batch[] =
2192 _T("ALTER TABLE alarms ADD dci_id integer\n")
2193 _T("UPDATE alarms SET dci_id=0\n")
2194 _T("ALTER TABLE event_log ADD dci_id integer\n")
2195 _T("UPDATE event_log SET dci_id=0\n")
2196 _T("<END>");
2197 CHK_EXEC(SQLBatch(batch));
e4926628 2198 CHK_EXEC(SetSchemaVersion(388));
65ce7452
VK
2199 return TRUE;
2200}
2201
53e39123
VK
2202/**
2203 * Upgrade from V386 to V387
2204 */
2205static BOOL H_UpgradeFromV386(int currVersion, int newVersion)
2206{
2207 DB_RESULT hResult = SQLSelect(_T("SELECT id,flags,filter FROM network_maps WHERE filter IS NOT NULL"));
2208 if (hResult != NULL)
2209 {
2210 int count = DBGetNumRows(hResult);
2211 for(int i = 0; i < count; i++)
2212 {
2213 TCHAR *filter = DBGetField(hResult, i, 2, NULL, 0);
2214 if ((filter != NULL) && (filter[0] != 0))
2215 {
2216 TCHAR query[256];
2217 _sntprintf(query, 256, _T("UPDATE network_maps SET flags=%d WHERE id=%d"),
2218 DBGetFieldULong(hResult, i, 1) | MF_FILTER_OBJECTS, DBGetFieldULong(hResult, i, 0));
2219 CHK_EXEC(SQLQuery(query));
2220 }
2221 free(filter);
2222 }
2223 DBFreeResult(hResult);
2224 }
2225 else
2226 {
2227 if (!g_bIgnoreErrors)
2228 return FALSE;
2229 }
e4926628 2230 CHK_EXEC(SetSchemaVersion(387));
53e39123
VK
2231 return TRUE;
2232}
2233
e2a9c5fc
VK
2234/**
2235 * Upgrade from V385 to V386
2236 */
2237static BOOL H_UpgradeFromV385(int currVersion, int newVersion)
2238{
2239 TCHAR query[1024];
2240 int ruleId = NextFreeEPPruleID();
2241
2242 if (!IsEventPairInUse(EVENT_THREAD_HANGS, EVENT_THREAD_RUNNING))
2243 {
2244 _sntprintf(query, 1024, _T("INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) VALUES (%d,'ea1dee96-b42e-499c-a992-0b0f9e4874b9',7944,'Generate an alarm when one of the system threads hangs or stops unexpectedly','%%m',5,'SYS_THREAD_HANG_%%1','',0,%d,0,'')"), ruleId, EVENT_ALARM_TIMEOUT);
2245 CHK_EXEC(SQLQuery(query));
2246 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_THREAD_HANGS);
2247 CHK_EXEC(SQLQuery(query));
2248 ruleId++;
2249 _sntprintf(query, 1024, _T("INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) VALUES (%d,'f0c5a6b2-7427-45e5-8333-7d60d2b408e6',7944,'Terminate the alarm when one of the system threads which previously hanged or stopped unexpectedly returned to the running state','%%m',6,'SYS_THREAD_HANG_%%1','',0,%d,0,'')"), ruleId, EVENT_ALARM_TIMEOUT);
2250 CHK_EXEC(SQLQuery(query));
2251 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_THREAD_RUNNING);
2252 CHK_EXEC(SQLQuery(query));
2253 ruleId++;
2254 }
2255
2256 if (!IsEventPairInUse(EVENT_MAINTENANCE_MODE_ENTERED, EVENT_MAINTENANCE_MODE_LEFT))
2257 {
2258 _sntprintf(query, 1024, _T("INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) VALUES (%d,'ed3397a8-a496-4534-839b-5a6fc77c167c',7944,'Generate an alarm when the object enters the maintenance mode','%%m',5,'MAINTENANCE_MODE_%%i','',0,%d,0,'')"), ruleId, EVENT_ALARM_TIMEOUT);
2259 CHK_EXEC(SQLQuery(query));
2260 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_MAINTENANCE_MODE_ENTERED);
2261 CHK_EXEC(SQLQuery(query));
2262 ruleId++;
2263 _sntprintf(query, 1024, _T("INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) VALUES (%d,'20a0f4a5-d90e-4961-ba88-a65b9ee45d07',7944,'Terminate the alarm when the object leaves the maintenance mode','%%m',6,'MAINTENANCE_MODE_%%i','',0,%d,0,'')"), ruleId, EVENT_ALARM_TIMEOUT);
2264 CHK_EXEC(SQLQuery(query));
2265 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_MAINTENANCE_MODE_LEFT);
2266 CHK_EXEC(SQLQuery(query));
2267 ruleId++;
2268 }
2269
2270 if (!IsEventPairInUse(EVENT_AGENT_FAIL, EVENT_AGENT_OK))
2271 {
2272 _sntprintf(query, 1024, _T("INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) VALUES (%d,'c6f66840-4758-420f-a27d-7bbf7b66a511',7944,'Generate an alarm if the NetXMS agent on the node stops responding','%%m',5,'AGENT_UNREACHABLE_%%i','',0,%d,0,'')"), ruleId, EVENT_ALARM_TIMEOUT);
2273 CHK_EXEC(SQLQuery(query));
2274 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_AGENT_FAIL);
2275 CHK_EXEC(SQLQuery(query));
2276 ruleId++;
2277 _sntprintf(query, 1024, _T("INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) VALUES (%d,'9fa60260-c2ec-4371-b4e4-f5346b1d8400',7944,'Terminate the alarm if the NetXMS agent on the node start responding again','%%m',6,'AGENT_UNREACHABLE_%%i','',0,%d,0,'')"), ruleId, EVENT_ALARM_TIMEOUT);
2278 CHK_EXEC(SQLQuery(query));
2279 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_AGENT_OK);
2280 CHK_EXEC(SQLQuery(query));
2281 ruleId++;
2282 }
2283
2284 if (!IsEventPairInUse(EVENT_SNMP_FAIL, EVENT_SNMP_OK))
2285 {
2286 _sntprintf(query, 1024, _T("INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) VALUES (%d,'20ef861f-b8e4-4e04-898e-e57d13863661',7944,'Generate an alarm if the SNMP agent on the node stops responding','%%m',5,'SNMP_UNREACHABLE_%%i','',0,%d,0,'')"), ruleId, EVENT_ALARM_TIMEOUT);
2287 CHK_EXEC(SQLQuery(query));
2288 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_SNMP_FAIL);
2289 CHK_EXEC(SQLQuery(query));
2290 ruleId++;
2291 _sntprintf(query, 1024, _T("INSERT INTO event_policy (rule_id,rule_guid,flags,comments,alarm_message,alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) VALUES (%d,'33f6193a-e103-4f5f-8bee-870bbcc08066',7944,'Terminate the alarm if the SNMP agent on the node start responding again','%%m',6,'SNMP_UNREACHABLE_%%i','',0,%d,0,'')"), ruleId, EVENT_ALARM_TIMEOUT);
2292 CHK_EXEC(SQLQuery(query));
2293 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_SNMP_OK);
2294 CHK_EXEC(SQLQuery(query));
2295 ruleId++;
2296 }
2297
2298 CHK_EXEC(SQLQuery(_T("UPDATE event_cfg SET severity='3' WHERE event_code=14 OR event_code=15")));
e4926628 2299 CHK_EXEC(SetSchemaVersion(386));
e2a9c5fc
VK
2300 return TRUE;
2301}
2302
7ac735ef 2303
4e7ebbb4
VK
2304/**
2305 * Upgrade from V384 to V385
2306 */
2307static BOOL H_UpgradeFromV384(int currVersion, int newVersion)
2308{
2309 CHK_EXEC(SQLQuery(_T("UPDATE config SET is_visible=1,need_server_restart=0 WHERE var_name='SNMPPorts'")));
e4926628 2310 CHK_EXEC(SetSchemaVersion(385));
4e7ebbb4
VK
2311 return TRUE;
2312}
2313
aed41472 2314/**
7bae90f4 2315 * Upgrade from V383 to V384
aed41472 2316 */
2317static BOOL H_UpgradeFromV383(int currVersion, int newVersion)
2318{
2319 CHK_EXEC(ConvertStrings(_T("graphs"), _T("graph_id"), _T("config")));
2320 static TCHAR batch[] =
2321 _T("ALTER TABLE graphs ADD flags integer\n")
2322 _T("ALTER TABLE graphs ADD filters $SQL:TEXT\n")
17b6b6a4 2323 _T("UPDATE graphs SET flags=0\n")
aed41472 2324 _T("<END>");
2325 CHK_EXEC(SQLBatch(batch));
e4926628 2326 CHK_EXEC(SetSchemaVersion(384));
aed41472 2327 return TRUE;
2328}
2329
55f6cb79
VK
2330/**
2331 * Upgrade from V382 to V383
2332 */
2333static BOOL H_UpgradeFromV382(int currVersion, int newVersion)
2334{
2335 CHK_EXEC(ResizeColumn(_T("nodes"), _T("primary_ip"), 48, false));
e4926628 2336 CHK_EXEC(SetSchemaVersion(383));
55f6cb79
VK
2337 return TRUE;
2338}
2339
83aa5ebd
VK
2340/**
2341 * Upgrade from V381 to V382
2342 */
2343static BOOL H_UpgradeFromV381(int currVersion, int newVersion)
2344{
7bae90f4
VK
2345 CHK_EXEC(CreateLibraryScript(11, _T("Hook::StatusPoll"), _T("/* Available global variables:\r\n * $node - current node, object of 'Node' type\r\n *\r\n * Expected return value:\r\n * none - returned value is ignored\r\n */\r\n")));
2346 CHK_EXEC(CreateLibraryScript(12, _T("Hook::ConfigurationPoll"), _T("/* Available global variables:\r\n * $node - current node, object of 'Node' type\r\n *\r\n * Expected return value:\r\n * none - returned value is ignored\r\n */\r\n")));
2347 CHK_EXEC(CreateLibraryScript(13, _T("Hook::InstancePoll"), _T("/* Available global variables:\r\n * $node - current node, object of 'Node' type\r\n *\r\n * Expected return value:\r\n * none - returned value is ignored\r\n */\r\n")));
2348 CHK_EXEC(CreateLibraryScript(14, _T("Hook::TopologyPoll"), _T("/* Available global variables:\r\n * $node - current node, object of 'Node' type\r\n *\r\n * Expected return value:\r\n * none - returned value is ignored\r\n */\r\n")));
2349 CHK_EXEC(CreateLibraryScript(15, _T("Hook::CreateInterface"), _T("/* Available global variables:\r\n * $node - current node, object of 'Node' type\r\n * $1 - current interface, object of 'Interface' type\r\n *\r\n * Expected return value:\r\n * true/false - boolean - whether interface should be created\r\n */\r\nreturn true;\r\n")));
2350 CHK_EXEC(CreateLibraryScript(16, _T("Hook::AcceptNewNode"), _T("/* Available global variables:\r\n * $ipAddr - IP address of the node being processed\r\n * $ipNetMask - netmask of the node being processed\r\n * $macAddr - MAC address of the node being processed\r\n * $zoneId - zone ID of the node being processed\r\n *\r\n * Expected return value:\r\n * true/false - boolean - whether node should be created\r\n */\r\nreturn true;\r\n")));
e4926628 2351 CHK_EXEC(SetSchemaVersion(382));
83aa5ebd
VK
2352 return TRUE;
2353}
2354
98ef8e4a
VK
2355/**
2356 * Upgrade from V380 to V381
2357 */
2358static BOOL H_UpgradeFromV380(int currVersion, int newVersion)
2359{
2360 static TCHAR batch[] =
2361 _T("ALTER TABLE items ADD guid varchar(36)\n")
2362 _T("ALTER TABLE dc_tables ADD guid varchar(36)\n")
2363 _T("<END>");
2364 CHK_EXEC(SQLBatch(batch));
50963ced
VK
2365 CHK_EXEC(GenerateGUID(_T("items"), _T("item_id"), _T("guid"), NULL));
2366 CHK_EXEC(GenerateGUID(_T("dc_tables"), _T("item_id"), _T("guid"), NULL));
e4926628 2367 CHK_EXEC(SetSchemaVersion(381));
98ef8e4a
VK
2368 return TRUE;
2369}
2370
9b4a2a0e
VK
2371/**
2372 * Upgrade from V379 to V380
2373 */
2374static BOOL H_UpgradeFromV379(int currVersion, int newVersion)
2375{
2376 static TCHAR batch[] =
2377 _T("UPDATE object_properties SET maint_event_id=0 WHERE maint_event_id IS NULL\n")
2378 _T("UPDATE nodes SET last_agent_comm_time=0 WHERE last_agent_comm_time IS NULL\n")
2379 _T("<END>");
2380 CHK_EXEC(SQLBatch(batch));
e4926628 2381 CHK_EXEC(SetSchemaVersion(380));
9b4a2a0e
VK
2382 return TRUE;
2383}
2384
ec5829b2
VK
2385/**
2386 * Upgrade from V378 to V379
2387 */
2388static BOOL H_UpgradeFromV378(int currVersion, int newVersion)
2389{
2390 CHK_EXEC(SQLQuery(_T("DELETE FROM config WHERE var_name='NumberOfDatabaseWriters'")));
e4926628 2391 CHK_EXEC(SetSchemaVersion(379));
ec5829b2
VK
2392 return TRUE;
2393}
2394
9bd1bace
VK
2395/**
2396 * Upgrade from V377 to V378
2397 */
2398static BOOL H_UpgradeFromV377(int currVersion, int newVersion)
2399{
2400 static TCHAR batch[] =
2401 _T("DELETE FROM config WHERE var_name='EnableMultipleDBConnections'\n")
2402 _T("UPDATE config SET var_name='DBConnectionPoolBaseSize' WHERE var_name='ConnectionPoolBaseSize'\n")
2403 _T("UPDATE config SET var_name='DBConnectionPoolMaxSize' WHERE var_name='ConnectionPoolMaxSize'\n")
2404 _T("UPDATE config SET var_name='DBConnectionPoolCooldownTime' WHERE var_name='ConnectionPoolCooldownTime'\n")
2405 _T("UPDATE config SET var_name='DBConnectionPoolMaxLifetime' WHERE var_name='ConnectionPoolMaxLifetime'\n")
2406 _T("<END>");
2407 CHK_EXEC(SQLBatch(batch));
e4926628 2408 CHK_EXEC(SetSchemaVersion(378));
9bd1bace
VK
2409 return TRUE;
2410}
2411
9d7771b8
VK
2412/**
2413 * Upgrade from V376 to V377
2414 */
2415static BOOL H_UpgradeFromV376(int currVersion, int newVersion)
2416{
2417 CHK_EXEC(CreateConfigParam(_T("DefaultSubnetMaskIPv4"), _T("24"), _T("Default mask for synthetic IPv4 subnets"), 'I', true, false, false, false));
2418 CHK_EXEC(CreateConfigParam(_T("DefaultSubnetMaskIPv6"), _T("64"), _T("Default mask for synthetic IPv6 subnets"), 'I', true, false, false, false));
e4926628 2419 CHK_EXEC(SetSchemaVersion(377));
9d7771b8
VK
2420 return TRUE;
2421}
2422
4e3133ee 2423/**
2424 * Upgrade from V375 to V376
2425 */
2426static BOOL H_UpgradeFromV375(int currVersion, int newVersion)
2427{
2428 static TCHAR batch[] =
2429 _T("ALTER TABLE nodes ADD last_agent_comm_time integer\n")
9b4a2a0e 2430 _T("UPDATE nodes SET last_agent_comm_time=0\n")
4e3133ee 2431 _T("<END>");
2432 CHK_EXEC(SQLBatch(batch));
2433
e4926628 2434 CHK_EXEC(SetSchemaVersion(376));
4e3133ee 2435 return TRUE;
2436}
2437
203cb23c
VK
2438/**
2439 * Upgrade from V374 to V375
2440 */
2441static BOOL H_UpgradeFromV374(int currVersion, int newVersion)
2442{
2443 static TCHAR batch[] =
2444 _T("ALTER TABLE object_tools_input_fields ADD sequence_num integer\n")
2445 _T("UPDATE object_tools_input_fields SET sequence_num=-1\n")
2446 _T("<END>");
2447 CHK_EXEC(SQLBatch(batch));
2448
e4926628 2449 CHK_EXEC(SetSchemaVersion(375));
203cb23c
VK
2450 return TRUE;
2451}
2452
97afcb6e
VK
2453/**
2454 * Upgrade from V373 to V374
2455 */
2456static BOOL H_UpgradeFromV373(int currVersion, int newVersion)
2457{
2458 static TCHAR batch[] =
2459 _T("ALTER TABLE object_properties ADD maint_event_id $SQL:INT64\n")
9b4a2a0e 2460 _T("UPDATE object_properties SET maint_mode='0',maint_event_id=0\n")
97afcb6e
VK
2461 _T("<END>");
2462 CHK_EXEC(SQLBatch(batch));
2463
3da098f7 2464 CHK_EXEC(CreateEventTemplate(EVENT_MAINTENANCE_MODE_ENTERED, _T("SYS_MAINTENANCE_MODE_ENTERED"), SEVERITY_NORMAL, EF_LOG, NULL,
97afcb6e
VK
2465 _T("Entered maintenance mode"),
2466 _T("Generated when node, cluster, or mobile device enters maintenance mode.")));
2467
3da098f7 2468 CHK_EXEC(CreateEventTemplate(EVENT_MAINTENANCE_MODE_LEFT, _T("SYS_MAINTENANCE_MODE_LEFT"), SEVERITY_NORMAL, EF_LOG, NULL,
97afcb6e
VK
2469 _T("Left maintenance mode"),
2470 _T("Generated when node, cluster, or mobile device leaves maintenance mode.")));
2471
e4926628 2472 CHK_EXEC(SetSchemaVersion(374));
97afcb6e
VK
2473 return TRUE;
2474}
2475
b3beb7f4 2476/**
2477 * Upgrade from V372 to V373
2478 */
2479static BOOL H_UpgradeFromV372(int currVersion, int newVersion)
2480{
2481 CHK_EXEC(SQLQuery(_T("ALTER TABLE scheduled_tasks ADD object_id integer")));
e4926628 2482 CHK_EXEC(SetSchemaVersion(373));
b3beb7f4 2483 return TRUE;
2484}
2485
89fd6fa4
VK
2486/**
2487 * Upgrade from V371 to V372
2488 */
2489static BOOL H_UpgradeFromV371(int currVersion, int newVersion)
2490{
2491 static TCHAR batch[] =
2492 _T("ALTER TABLE object_properties ADD maint_mode char(1)\n")
2493 _T("UPDATE object_properties SET maint_mode='0'\n")
2494 _T("<END>");
2495 CHK_EXEC(SQLBatch(batch));
e4926628 2496 CHK_EXEC(SetSchemaVersion(372));
89fd6fa4
VK
2497 return TRUE;
2498}
2499
90e3031f
VK
2500/**
2501 * Upgrade from V370 to V371
2502 */
2503static BOOL H_UpgradeFromV370(int currVersion, int newVersion)
2504{
2505 int defaultPollingInterval = ConfigReadInt(_T("DefaultDCIPollingInterval"), 60);
2506 int defaultRetentionTime = ConfigReadInt(_T("DefaultDCIRetentionTime"), 30);
2507
2508 TCHAR query[256];
2509 _sntprintf(query, 256, _T("UPDATE items SET polling_interval=0 WHERE polling_interval=%d"), defaultPollingInterval);
2510 CHK_EXEC(SQLQuery(query));
2511
2512 _sntprintf(query, 256, _T("UPDATE items SET retention_time=0 WHERE retention_time=%d"), defaultRetentionTime);
2513 CHK_EXEC(SQLQuery(query));
2514
2515 _sntprintf(query, 256, _T("UPDATE dc_tables SET polling_interval=0 WHERE polling_interval=%d"), defaultPollingInterval);
2516 CHK_EXEC(SQLQuery(query));
2517
2518 _sntprintf(query, 256, _T("UPDATE dc_tables SET retention_time=0 WHERE retention_time=%d"), defaultRetentionTime);
2519 CHK_EXEC(SQLQuery(query));
2520
e4926628 2521 CHK_EXEC(SetSchemaVersion(371));
90e3031f
VK
2522 return TRUE;
2523}
2524
8bdd26dc
VK
2525/**
2526 * Upgrade from V369 to V370
2527 */
2528static BOOL H_UpgradeFromV369(int currVersion, int newVersion)
2529{
2530 CHK_EXEC(CreateTable(
2531 _T("CREATE TABLE dashboard_associations (")
2532 _T(" object_id integer not null,")
2533 _T(" dashboard_id integer not null,")
2534 _T(" PRIMARY KEY(object_id,dashboard_id))")));
e4926628 2535 CHK_EXEC(SetSchemaVersion(370));
8bdd26dc
VK
2536 return TRUE;
2537}
2538
0a145c10 2539/**
2540 * Upgrade from V368 to V369
2541 */
2542static BOOL H_UpgradeFromV368(int currVersion, int newVersion)
2543{
2544 CHK_EXEC(CreateTable(
c6e191d2 2545 _T("CREATE TABLE scheduled_tasks (")
0a145c10 2546 _T(" id integer not null,")
2547 _T(" taskId varchar(255) null,")
c6e191d2 2548 _T(" schedule varchar(127) null,")
0a145c10 2549 _T(" params varchar(1023) null,")
2550 _T(" execution_time integer not null,")
2551 _T(" last_execution_time integer not null,")
2552 _T(" flags integer not null,")
c6e191d2 2553 _T(" owner integer not null,")
0a145c10 2554 _T(" PRIMARY KEY(id))")));
e4926628 2555 CHK_EXEC(SetSchemaVersion(369));
0a145c10 2556 return TRUE;
2557}
2558
de674bb6
VK
2559/**
2560 * Upgrade from V367 to V368
2561 */
2562static BOOL H_UpgradeFromV367(int currVersion, int newVersion)
2563{
2564 static TCHAR batch[] =
2565 _T("ALTER TABLE nodes ADD rack_height integer\n")
2566 _T("UPDATE nodes SET rack_height=1\n")
2567 _T("<END>");
2568 CHK_EXEC(SQLBatch(batch));
e4926628 2569 CHK_EXEC(SetSchemaVersion(368));
de674bb6
VK
2570 return TRUE;
2571}
2572
cf38357f
VK
2573/**
2574 * Upgrade from V366 to V367
2575 */
2576static BOOL H_UpgradeFromV366(int currVersion, int newVersion)
2577{
cd071c26 2578 CHK_EXEC(CreateConfigParam(_T("TrapSourcesInAllZones"), _T("0"), _T("Search all zones to match trap/syslog source address to node"), 'B', true, true, false, false));
cf38357f
VK
2579
2580 CHK_EXEC(SQLQuery(_T("ALTER TABLE nodes ADD snmp_sys_contact varchar(127)")));
2581 CHK_EXEC(SQLQuery(_T("ALTER TABLE nodes ADD snmp_sys_location varchar(127)")));
2582
e4926628 2583 CHK_EXEC(SetSchemaVersion(367));
cf38357f
VK
2584 return TRUE;
2585}
2586
48905317
VK
2587/**
2588 * Upgrade from V365 to V366
2589 */
2590static BOOL H_UpgradeFromV365(int currVersion, int newVersion)
2591{
b3643ffe 2592 CHK_EXEC(CreateConfigParam(_T("ServerCommandOutputTimeout"), _T("60"), true, false));
48905317 2593
e4926628 2594 CHK_EXEC(SetSchemaVersion(366));
48905317
VK
2595 return TRUE;
2596}
2597
d0a2ada6 2598/**
2599 * Upgrade from V364 to V365
2600 */
2601static BOOL H_UpgradeFromV364(int currVersion, int newVersion)
2602{
4e7ebbb4 2603 CHK_EXEC(CreateConfigParam(_T("SNMPPorts"), _T("161"), true, false));
e4926628 2604 CHK_EXEC(SetSchemaVersion(365));
d0a2ada6 2605 return TRUE;
2606}
2607
3d37f7bf
VK
2608/**
2609 * Upgrade from V363 to V364
2610 */
2611static BOOL H_UpgradeFromV363(int currVersion, int newVersion)
2612{
2613 static TCHAR batch[] =
2614 _T("ALTER TABLE interfaces ADD speed $SQL:INT64\n")
2615 _T("ALTER TABLE interfaces ADD iftable_suffix varchar(127)\n")
2616 _T("UPDATE interfaces SET speed=0\n")
2617 _T("<END>");
2618 CHK_EXEC(SQLBatch(batch));
2619
e4926628 2620 CHK_EXEC(SetSchemaVersion(364));
3d37f7bf
VK
2621 return TRUE;
2622}
2623
2589cc10 2624/**
2625 * Upgrade from V362 to V363
2626 */
2627static BOOL H_UpgradeFromV362(int currVersion, int newVersion)
2628{
2629 ResizeColumn(_T("config"), _T("var_value"), 2000, true);
e4926628 2630 CHK_EXEC(SetSchemaVersion(363));
2589cc10 2631 return TRUE;
2632}
2633
8a1519ce
VK
2634/**
2635 * Upgrade from V361 to V362
2636 */
2637static BOOL H_UpgradeFromV361(int currVersion, int newVersion)
2638{
2639 CHK_EXEC(CreateConfigParam(_T("CaseInsensitiveLoginNames"), _T("0"), _T("Enable/disable case insensitive login names"), 'B', true, true, false));
e4926628 2640 CHK_EXEC(SetSchemaVersion(362));
8a1519ce
VK
2641 return TRUE;
2642}
2643
b576249a
VK
2644/**
2645 * Upgrade from V360 to V361
2646 */
2647static BOOL H_UpgradeFromV360(int currVersion, int newVersion)
2648{
2649 CHK_EXEC(CreateTable(
2650 _T("CREATE TABLE object_tools_input_fields (")
2651 _T(" tool_id integer not null,")
2652 _T(" name varchar(31) not null,")
2653 _T(" input_type char(1) not null,")
2654 _T(" display_name varchar(127) null,")
2655 _T(" config $SQL:TEXT null,")
2656 _T(" PRIMARY KEY(tool_id,name))")));
2657
e4926628 2658 CHK_EXEC(SetSchemaVersion(361));
b576249a
VK
2659 return TRUE;
2660}
2661
b2a15edc
VK
2662/**
2663 * Upgrade from V359 to V360
2664 */
2665static BOOL H_UpgradeFromV359(int currVersion, int newVersion)
2666{
2667 DB_RESULT hResult = SQLSelect(_T("SELECT tool_id,tool_type,tool_data,confirmation_text FROM object_tools"));
2668 if (hResult != NULL)
2669 {
2670 int count = DBGetNumRows(hResult);
2671 for(int i = 0; i < count; i++)
2672 {
2673 UINT32 id = DBGetFieldULong(hResult, i, 0);
2589cc10 2674
b2a15edc
VK
2675 TCHAR *text = DBGetField(hResult, i, 3, NULL, 0);
2676 if (text != NULL)
2677 {
2678 ConvertObjectToolMacros(id, text, _T("confirmation_text"));
2679 free(text);
2680 }
2589cc10 2681
b2a15edc
VK
2682 int type = DBGetFieldLong(hResult, i, 1);
2683 if ((type == 1) || (type == 4) || (type == 5))
2684 {
2685 text = DBGetField(hResult, i, 2, NULL, 0);
2686 if (text != NULL)
2687 {
2688 ConvertObjectToolMacros(id, text, _T("tool_data"));
2689 free(text);
2690 }
2691 }
2692 }
2693 DBFreeResult(hResult);
2694 }
2695 else
2696 {
2697 if (!g_bIgnoreErrors)
2698 return FALSE;
2699 }
e4926628 2700 CHK_EXEC(SetSchemaVersion(360));
b2a15edc
VK
2701 return TRUE;
2702}
2703
7a8aa001
VK
2704/**
2705 * Upgrade from V358 to V359
2706 */
2707static BOOL H_UpgradeFromV358(int currVersion, int newVersion)
2708{
2709 static TCHAR batch[] =
2710 _T("ALTER TABLE network_maps ADD object_display_mode integer\n")
2711 _T("UPDATE network_maps SET object_display_mode=0\n")
2712 _T("<END>");
2713 CHK_EXEC(SQLBatch(batch));
2714
e4926628 2715 CHK_EXEC(SetSchemaVersion(359));
7a8aa001
VK
2716 return TRUE;
2717}
2718
c85c8ef2
VK
2719/**
2720 * Upgrade from V357 to V358
2721 */
2722static BOOL H_UpgradeFromV357(int currVersion, int newVersion)
2723{
2724 static TCHAR batch[] =
2725 _T("ALTER TABLE config ADD data_type char(1) not null default 'S'\n")
2726 _T("ALTER TABLE config ADD is_public char(1) not null default 'N'\n")
2727 _T("ALTER TABLE config ADD description varchar(255)\n")
2728 _T("ALTER TABLE config ADD possible_values $SQL:TEXT\n")
2729 _T("<END>");
2730 static TCHAR batchOracle[] =
2731 _T("ALTER TABLE config ADD data_type char(1) default 'S' not null\n")
2732 _T("ALTER TABLE config ADD is_public char(1) default 'N' not null\n")
2733 _T("ALTER TABLE config ADD description varchar(255)\n")
2734 _T("ALTER TABLE config ADD possible_values $SQL:TEXT\n")
2735 _T("<END>");
2736 CHK_EXEC(SQLBatch((g_dbSyntax == DB_SYNTAX_ORACLE) ? batchOracle : batch));
2737
2738 CHK_EXEC(CreateConfigParam(_T("DashboardDataExportEnableInterpolation"), _T("1"), _T("Enable/disable data interpolation in dashboard data export"), 'B', true, false, true));
2739
e4926628 2740 CHK_EXEC(SetSchemaVersion(358));
c85c8ef2
VK
2741 return TRUE;
2742}
2743
9db92307 2744/**
2745 * Upgrade from V356 to V357
2746 */
2747static BOOL H_UpgradeFromV356(int currVersion, int newVersion)
2748{
2749 TCHAR comunityString[256];
2750 comunityString[0] = 0;
2751 DB_RESULT hResult = SQLSelect(_T("SELECT var_value FROM config WHERE var_name='DefaultCommunityString'"));
2752 if (hResult != NULL)
2753 {
2754 if(DBGetNumRows(hResult) > 0)
2755 {
2756 DBGetField(hResult, 0, 0, comunityString, 256);
2757 }
2758 DBFreeResult(hResult);
2759 }
2760
c85c8ef2 2761 if (comunityString[0] != 0)
9db92307 2762 {
2763 DB_RESULT hResult = SQLSelect(_T("SELECT id, community FROM snmp_communities"));
2764 if (hResult != NULL)
2765 {
2766 CHK_EXEC(SQLQuery(_T("DELETE FROM snmp_communities")));
2767
2768 TCHAR query[1024];
2769 _sntprintf(query, 1024, _T("INSERT INTO snmp_communities (id,community) VALUES(%d,'%s')"), 1, comunityString);
2770 CHK_EXEC(SQLQuery(query));
2771
2772 int count = DBGetNumRows(hResult);
2773 for(int i = 0; i < count; i++)
2774 {
2775 _sntprintf(query, 1024, _T("INSERT INTO snmp_communities (id,community) VALUES(%d,'%s')"), i + 2, DBGetField(hResult, i, 1, comunityString, 256));
2776 CHK_EXEC(SQLQuery(query));
2777 }
2778 }
2779 }
2780
2781 CHK_EXEC(SQLQuery(_T("DELETE FROM config WHERE var_name='DefaultCommunityString'")));
2782
e4926628 2783 CHK_EXEC(SetSchemaVersion(357));
9db92307 2784 return TRUE;
2785}
2786
e1d2050f
VK
2787/**
2788 * Upgrade from V355 to V356
2789 */
2790static BOOL H_UpgradeFromV355(int currVersion, int newVersion)
2791{
2792 static TCHAR batch[] =
2793 _T("DELETE FROM config WHERE var_name='NumberOfBusinessServicePollers'\n")
2794 _T("DELETE FROM config WHERE var_name='NumberOfConditionPollers'\n")
2795 _T("DELETE FROM config WHERE var_name='NumberOfConfigurationPollers'\n")
2796 _T("DELETE FROM config WHERE var_name='NumberOfDiscoveryPollers'\n")
2797 _T("DELETE FROM config WHERE var_name='NumberOfInstancePollers'\n")
2798 _T("DELETE FROM config WHERE var_name='NumberOfRoutingTablePollers'\n")
2799 _T("DELETE FROM config WHERE var_name='NumberOfStatusPollers'\n")
2800 _T("DELETE FROM config WHERE var_name='NumberOfTopologyTablePollers'\n")
2801 _T("<END>");
2802 CHK_EXEC(SQLBatch(batch));
2803
c85c8ef2
VK
2804 CHK_EXEC(CreateConfigParam(_T("PollerThreadPoolBaseSize"), _T("10"), true, true));
2805 CHK_EXEC(CreateConfigParam(_T("PollerThreadPoolMaxSize"), _T("250"), true, true));
e1d2050f 2806
e4926628 2807 CHK_EXEC(SetSchemaVersion(356));
e1d2050f
VK
2808 return TRUE;
2809}
2810
9708eff4
VK
2811/**
2812 * Upgrade from V354 to V355
2813 */
2814static BOOL H_UpgradeFromV354(int currVersion, int newVersion)
2815{
2816 static TCHAR batch[] =
2817 _T("ALTER TABLE nodes ADD agent_cache_mode char(1)\n")
55d81770 2818 _T("UPDATE nodes SET agent_cache_mode='0'\n")
e9902466 2819 _T("DELETE FROM config WHERE var_name='ServerID'\n")
9708eff4
VK
2820 _T("<END>");
2821 CHK_EXEC(SQLBatch(batch));
2822
c85c8ef2 2823 CHK_EXEC(CreateConfigParam(_T("DefaultAgentCacheMode"), _T("2"), true, true));
9708eff4 2824
e4926628 2825 CHK_EXEC(SetSchemaVersion(355));
9708eff4
VK
2826 return TRUE;
2827}
2828
981d246a
VK
2829/**
2830 * Upgrade from V353 to V354
2831 */
2832static BOOL H_UpgradeFromV353(int currVersion, int newVersion)
2833{
2834 CHK_EXEC(ResizeColumn(_T("users"), _T("password"), 127, false));
e4926628 2835 CHK_EXEC(SetSchemaVersion(354));
981d246a
VK
2836 return TRUE;
2837}
2838
2096c8f0
VK
2839/**
2840 * Upgrade from V352 to V353
2841 */
2842static BOOL H_UpgradeFromV352(int currVersion, int newVersion)
2843{
2844 CHK_EXEC(SQLQuery(_T("ALTER TABLE dci_summary_tables ADD guid varchar(36)")));
50963ced 2845 CHK_EXEC(GenerateGUID(_T("dci_summary_tables"), _T("id"), _T("guid"), NULL));
e4926628 2846 CHK_EXEC(SetSchemaVersion(353));
2096c8f0
VK
2847 return TRUE;
2848}
2849
271e3971
VK
2850/**
2851 * Upgrade from V351 to V352
2852 */
2853static BOOL H_UpgradeFromV351(int currVersion, int newVersion)
2854{
2855 CHK_EXEC(SQLQuery(_T("ALTER TABLE object_tools ADD guid varchar(36)")));
50963ced 2856 CHK_EXEC(GenerateGUID(_T("object_tools"), _T("tool_id"), _T("guid"), NULL));
e4926628 2857 CHK_EXEC(SetSchemaVersion(352));
271e3971
VK
2858 return TRUE;
2859}
2860
ac58ffe9
VK
2861/**
2862 * Upgrade from V350 to V351
2863 */
2864static BOOL H_UpgradeFromV350(int currVersion, int newVersion)
2865{
2866 static TCHAR batch[] =
2867 _T("ALTER TABLE access_points ADD ap_index integer\n")
2868 _T("UPDATE access_points SET ap_index=0\n")
2869 _T("<END>");
2870 CHK_EXEC(SQLBatch(batch));
2871
e4926628 2872 CHK_EXEC(SetSchemaVersion(351));
ac58ffe9
VK
2873 return TRUE;
2874}
2875
fcf91b2e 2876/**
2877 * Upgrade from V349 to V350
2878 */
2879static BOOL H_UpgradeFromV349(int currVersion, int newVersion)
2880{
2881 switch(g_dbSyntax)
2882 {
2883 case DB_SYNTAX_ORACLE:
a8a0793d
VK
2884 CHK_EXEC(SQLQuery(_T("UPDATE object_properties SET comments = comments || chr(13) || chr(10) || (SELECT description FROM ap_common WHERE ap_common.id = object_properties.object_id) WHERE EXISTS (SELECT description FROM ap_common WHERE ap_common.id = object_properties.object_id AND description IS NOT NULL)")));
2885 break;
fcf91b2e 2886 case DB_SYNTAX_DB2:
a8a0793d
VK
2887 CHK_EXEC(SQLQuery(_T("UPDATE object_properties SET comments = comments || chr(13) || chr(10) || (SELECT description FROM ap_common WHERE ap_common.id = object_properties.object_id) WHERE EXISTS (SELECT description FROM ap_common WHERE ap_common.id = object_properties.object_id AND description IS NOT NULL AND description <> '')")));
2888 break;
96e03924 2889 case DB_SYNTAX_MSSQL:
b69710b9 2890 CHK_EXEC(SQLQuery(_T("UPDATE object_properties SET comments = CAST(comments AS varchar(4000)) + char(13) + char(10) + CAST((SELECT description FROM ap_common WHERE ap_common.id = object_properties.object_id) AS varchar(4000)) WHERE EXISTS (SELECT description FROM ap_common WHERE ap_common.id = object_properties.object_id AND description IS NOT NULL AND datalength(description) <> 0)")));
fcf91b2e 2891 break;
2892 case DB_SYNTAX_PGSQL:
a8a0793d 2893 CHK_EXEC(SQLQuery(_T("UPDATE object_properties SET comments = comments || '\\015\\012' || (SELECT description FROM ap_common WHERE ap_common.id = object_properties.object_id) WHERE EXISTS (SELECT description FROM ap_common WHERE ap_common.id = object_properties.object_id AND description IS NOT NULL AND description <> '')")));
fcf91b2e 2894 break;
2895 case DB_SYNTAX_SQLITE:
a8a0793d 2896 CHK_EXEC(SQLQuery(_T("UPDATE object_properties SET comments = comments || char(13,10) || (SELECT description FROM ap_common WHERE ap_common.id = object_properties.object_id) WHERE EXISTS (SELECT description FROM ap_common WHERE ap_common.id = object_properties.object_id AND description IS NOT NULL AND description <> '')")));
fcf91b2e 2897 break;
2898 case DB_SYNTAX_MYSQL:
a8a0793d 2899 CHK_EXEC(SQLQuery(_T("UPDATE object_properties, ap_common SET object_properties.comments=CONCAT(object_properties.comments, '\\r\\n', ap_common.description) WHERE object_properties.object_id=ap_common.id AND (ap_common.description!='' AND ap_common.description IS NOT NULL)")));
fcf91b2e 2900 break;
2901 default:
96e03924 2902 break;
fcf91b2e 2903 }
2904
3f543e56 2905 CHK_EXEC(SQLDropColumn(_T("ap_common"), _T("description")));
e4926628 2906 CHK_EXEC(SetSchemaVersion(350));
fcf91b2e 2907 return TRUE;
2908}
2909
b06ae508
VK
2910/**
2911 * Upgrade from V348 to V349
2912 */
2913static BOOL H_UpgradeFromV348(int currVersion, int newVersion)
2914{
2915 CHK_EXEC(SQLQuery(_T("DELETE FROM config WHERE var_name='HouseKeepingInterval'")));
c85c8ef2 2916 CHK_EXEC(CreateConfigParam(_T("HousekeeperStartTime"), _T("02:00"), true, true));
e4926628 2917 CHK_EXEC(SetSchemaVersion(349));
b06ae508
VK
2918 return TRUE;
2919}
2920
c30c0c0f
VK
2921/**
2922 * Upgrade from V347 to V348
2923 */
2924static BOOL H_UpgradeFromV347(int currVersion, int newVersion)
2925{
3da098f7 2926 CHK_EXEC(CreateEventTemplate(EVENT_IF_IPADDR_ADDED, _T("SYS_IF_IPADDR_ADDED"), SEVERITY_NORMAL, EF_LOG, NULL,
c30c0c0f
VK
2927 _T("IP address %3/%4 added to interface \"%2\""),
2928 _T("Generated when IP address added to interface.\r\n")
2929 _T("Parameters:\r\n")
2930 _T(" 1) Interface object ID\r\n")
2931 _T(" 2) Interface name\r\n")
2932 _T(" 3) IP address\r\n")
2933 _T(" 4) Network mask\r\n")
2934 _T(" 5) Interface index")));
2935
3da098f7 2936 CHK_EXEC(CreateEventTemplate(EVENT_IF_IPADDR_DELETED, _T("SYS_IF_IPADDR_DELETED"), SEVERITY_NORMAL, EF_LOG, NULL,
c30c0c0f
VK
2937 _T("IP address %3/%4 deleted from interface \"%2\""),
2938 _T("Generated when IP address deleted from interface.\r\n")
2939 _T("Parameters:\r\n")
2940 _T(" 1) Interface object ID\r\n")
2941 _T(" 2) Interface name\r\n")
2942 _T(" 3) IP address\r\n")
2943 _T(" 4) Network mask\r\n")
2944 _T(" 5) Interface index")));
2945
e4926628 2946 CHK_EXEC(SetSchemaVersion(348));
c30c0c0f
VK
2947 return TRUE;
2948}
2949
2950/**
2951 * Upgrade from V346 to V347
2952 */
2953static BOOL H_UpgradeFromV346(int currVersion, int newVersion)
2954{
2955 CHK_EXEC(CreateTable(
2956 _T("CREATE TABLE interface_address_list (")
2957 _T(" iface_id integer not null,")
2958 _T(" ip_addr varchar(48) not null,")
2959 _T(" ip_netmask integer not null,")
2960 _T(" PRIMARY KEY(iface_id,ip_addr))")));
2961
2962 DB_RESULT hResult = SQLSelect(_T("SELECT id,ip_addr,ip_netmask FROM interfaces WHERE ip_addr<>'0.0.0.0'"));
2963 if (hResult != NULL)
2964 {
2965 int count = DBGetNumRows(hResult);
2966 for(int i = 0; i < count; i++)
2967 {
2968 TCHAR query[256], addr[64];
2969 _sntprintf(query, 256, _T("INSERT INTO interface_address_list (iface_id,ip_addr,ip_netmask) VALUES (%d,'%s',%d)"),
2970 DBGetFieldLong(hResult, i, 0), DBGetField(hResult, i, 1, addr, 64), DBGetFieldLong(hResult, i, 2));
2971 CHK_EXEC(SQLQuery(query));
2972 }
2973 DBFreeResult(hResult);
2974 }
2975 else
2976 {
2977 if (!g_bIgnoreErrors)
2978 return FALSE;
2979 }
2980
2981 static TCHAR batch[] =
2982 _T("ALTER TABLE interfaces DROP COLUMN ip_addr\n")
2983 _T("ALTER TABLE interfaces DROP COLUMN ip_netmask\n")
2984 _T("<END>");
2985 CHK_EXEC(SQLBatch(batch));
2986
e4926628 2987 CHK_EXEC(SetSchemaVersion(347));
c30c0c0f
VK
2988 return TRUE;
2989}
2990
c75e9ee4
VK
2991/**
2992 * Upgrade from V345 to V346
2993 */
2994static BOOL H_UpgradeFromV345(int currVersion, int newVersion)
2995{
b69710b9
VK
2996 if (g_dbSyntax == DB_SYNTAX_MSSQL)
2997 {
2998 CHK_EXEC(DropPrimaryKey(_T("cluster_sync_subnets")));
2999 CHK_EXEC(DropPrimaryKey(_T("address_lists")));
3000 CHK_EXEC(DropPrimaryKey(_T("vpn_connector_networks")));
3001 }
3002
3003 CHK_EXEC(ResizeColumn(_T("cluster_sync_subnets"), _T("subnet_addr"), 48, false));
3004 CHK_EXEC(ResizeColumn(_T("cluster_resources"), _T("ip_addr"), 48, false));
3005 CHK_EXEC(ResizeColumn(_T("subnets"), _T("ip_addr"), 48, false));
3006 CHK_EXEC(ResizeColumn(_T("interfaces"), _T("ip_addr"), 48, false));
3007 CHK_EXEC(ResizeColumn(_T("network_services"), _T("ip_bind_addr"), 48, false));
3008 CHK_EXEC(ResizeColumn(_T("vpn_connector_networks"), _T("ip_addr"), 48, false));
3009 CHK_EXEC(ResizeColumn(_T("snmp_trap_log"), _T("ip_addr"), 48, false));
3010 CHK_EXEC(ResizeColumn(_T("address_lists"), _T("addr1"), 48, false));
3011 CHK_EXEC(ResizeColumn(_T("address_lists"), _T("addr2"), 48, false));
3012 CHK_EXEC(ResizeColumn(_T("nodes"), _T("primary_ip"), 48, false));
c75e9ee4
VK
3013
3014 CHK_EXEC(ConvertNetMasks(_T("cluster_sync_subnets"), _T("subnet_mask"), _T("cluster_id")));
3015 CHK_EXEC(ConvertNetMasks(_T("subnets"), _T("ip_netmask"), _T("id")));
3016 CHK_EXEC(ConvertNetMasks(_T("interfaces"), _T("ip_netmask"), _T("id")));
3017 CHK_EXEC(ConvertNetMasks(_T("vpn_connector_networks"), _T("ip_netmask"), _T("vpn_id"), _T("ip_addr")));
3018
ba889094 3019 DB_RESULT hResult = SQLSelect(_T("SELECT community_id,list_type,addr1,addr2 FROM address_lists WHERE addr_type=0"));
c75e9ee4
VK
3020 if (hResult != NULL)
3021 {
3022 int count = DBGetNumRows(hResult);
3023 if (count > 0)
3024 {
ba889094 3025 CHK_EXEC(SQLQuery(_T("DELETE FROM address_lists WHERE addr_type=0")));
c75e9ee4
VK
3026
3027 for(int i = 0; i < count; i++)
3028 {
3029 TCHAR query[256], addr[64];
ba889094 3030 _sntprintf(query, 256, _T("INSERT INTO address_lists (addr_type,community_id,list_type,addr1,addr2) VALUES (0,%d,%d,'%s','%d')"),
c75e9ee4
VK
3031 DBGetFieldLong(hResult, i, 0), DBGetFieldLong(hResult, i, 1), DBGetField(hResult, i, 2, addr, 64),
3032 BitsInMask(DBGetFieldIPAddr(hResult, i, 3)));
3033 CHK_EXEC(SQLQuery(query));
3034 }
3035 }
3036 DBFreeResult(hResult);
3037 }
3038 else
3039 {
3040 if (!g_bIgnoreErrors)
3041 return FALSE;
3042 }
3043
b69710b9
VK
3044 if (g_dbSyntax == DB_SYNTAX_MSSQL)
3045 {
3046 CHK_EXEC(SQLQuery(_T("ALTER TABLE cluster_sync_subnets ADD CONSTRAINT pk_cluster_sync_subnets PRIMARY KEY (cluster_id,subnet_addr)")));
3047 CHK_EXEC(SQLQuery(_T("ALTER TABLE address_lists ADD CONSTRAINT pk_address_lists PRIMARY KEY (list_type,community_id,addr_type,addr1,addr2)")));
3048 CHK_EXEC(SQLQuery(_T("ALTER TABLE vpn_connector_networks ADD CONSTRAINT pk_vpn_connector_networks PRIMARY KEY (vpn_id,ip_addr)")));
3049 }
3050
e4926628 3051 CHK_EXEC(SetSchemaVersion(346));
c75e9ee4
VK
3052 return TRUE;
3053}
3054
805171de
VK
3055/**
3056 * Upgrade from V344 to V345
3057 */
3058static BOOL H_UpgradeFromV344(int currVersion, int newVersion)
3059{
3060 CHK_EXEC(CreateConfigParam(_T("NumberOfInstancePollers"), _T("10"), 1, 1));
3061 CHK_EXEC(CreateConfigParam(_T("InstancePollingInterval"), _T("600"), 1, 1));
e4926628 3062 CHK_EXEC(SetSchemaVersion(345));
805171de
VK
3063 return TRUE;
3064}
3065
e95680e5
VK
3066/**
3067 * Upgrade from V343 to V344
3068 */
3069static BOOL H_UpgradeFromV343(int currVersion, int newVersion)
3070{
c30c0c0f 3071 static TCHAR batch[] =
e95680e5
VK
3072 _T("ALTER TABLE interfaces ADD mtu integer\n")
3073 _T("ALTER TABLE interfaces ADD alias varchar(255)\n")
3074 _T("UPDATE interfaces SET mtu=0\n")
3075 _T("<END>");
3076 CHK_EXEC(SQLBatch(batch));
e4926628 3077 CHK_EXEC(SetSchemaVersion(344));
e95680e5
VK
3078 return TRUE;
3079}
3080
d140955e
VK
3081/**
3082 * Upgrade from V342 to V343
3083 */
3084static BOOL H_UpgradeFromV342(int currVersion, int newVersion)
3085{
3086 if (g_dbSyntax != DB_SYNTAX_MSSQL)
3087 {
3088 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='CREATE INDEX idx_idata_%d_id_timestamp ON idata_%d(item_id,idata_timestamp DESC)' WHERE var_name='IDataIndexCreationCommand_0'")));
5096f5a5 3089 CHK_EXEC(DBCommit(g_hCoreDB)); // do reindexing outside current transaction
d140955e 3090 ReindexIData();
5096f5a5 3091 CHK_EXEC(DBBegin(g_hCoreDB));
d140955e 3092 }
e4926628 3093 CHK_EXEC(SetSchemaVersion(343));
d140955e
VK
3094 return TRUE;
3095}
3096
4b70cb26 3097/**
3098 * Upgrade from V341 to V342
3099 */
3100static BOOL H_UpgradeFromV341(int currVersion, int newVersion)
3101{
d140955e 3102 CHK_EXEC(SQLQuery(_T("ALTER TABLE object_tools ADD tool_filter $SQL:TEXT")));
4b70cb26 3103 DB_RESULT hResult = SQLSelect(_T("SELECT tool_id, matching_oid FROM object_tools"));
3104 if (hResult != NULL)
3105 {
3106 int count = DBGetNumRows(hResult);
3107 for(int i = 0; i < count; i++)
3108 {
3109 TCHAR *oid = DBGetField(hResult, i, 1, NULL, 0);
3110 if (oid == NULL || !_tcscmp(oid, _T(" ")))
3111 {
3112 oid = _tcsdup(_T(""));
3113 }
3114 else
3115 {
3116 TCHAR *newConfig = (TCHAR *)malloc((_tcslen(oid) + 512) * sizeof(TCHAR));
3117 _tcscpy(newConfig, _T("<objectToolFilter>"));
3118 _tcscat(newConfig, _T("<snmpOid>"));
3119 _tcscat(newConfig, oid);
3120 _tcscat(newConfig, _T("</snmpOid>"));
3121 _tcscat(newConfig, _T("</objectToolFilter>"));
3122
3123 DB_STATEMENT statment = DBPrepare(g_hCoreDB, _T("UPDATE object_tools SET tool_filter=? WHERE tool_id=?"));
3124 if (statment != NULL)
3125 {
3126 DBBind(statment, 1, DB_SQLTYPE_TEXT, newConfig, DB_BIND_STATIC);
3127 DBBind(statment, 2, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 0));
3128 CHK_EXEC(DBExecute(statment));
3129 DBFreeStatement(statment);
3130 }
3131 else
3132 {
3133 if (!g_bIgnoreErrors)
3134 return FALSE;
3135 }
3136 }
3137 }
3138 }
a19fa589 3139 CHK_EXEC(SQLDropColumn(_T("object_tools"), _T("matching_oid"))); //delete old column
e4926628 3140 CHK_EXEC(SetSchemaVersion(342));
4b70cb26 3141 return TRUE;
3142}
3143
56fa1092
VK
3144/**
3145 * Upgrade from V340 to V341
3146 */
3147static BOOL H_UpgradeFromV340(int currVersion, int newVersion)
3148{
3149 static TCHAR batch[] =
3150 _T("ALTER TABLE object_properties ADD country varchar(63)\n")
3151 _T("ALTER TABLE object_properties ADD city varchar(63)\n")
3152 _T("ALTER TABLE object_properties ADD street_address varchar(255)\n")
3153 _T("ALTER TABLE object_properties ADD postcode varchar(31)\n")
3154 _T("<END>");
3155 CHK_EXEC(SQLBatch(batch));
e4926628 3156 CHK_EXEC(SetSchemaVersion(341));
56fa1092
VK
3157 return TRUE;
3158}
3159
b00236dd 3160/**
3161 * Upgrade from V339 to V340
3162 */
3163static BOOL H_UpgradeFromV339(int currVersion, int newVersion)
3164{
3165 CHK_EXEC(CreateConfigParam(_T("LdapPageSize"), _T("1000"), 1, 0));
3166 CHK_EXEC(SQLQuery(_T("UPDATE config SET var_value='1' WHERE var_name='LdapUserDeleteAction'")));
e4926628 3167 CHK_EXEC(SetSchemaVersion(340));
b00236dd 3168 return TRUE;
3169}
3170
815638fe
VK
3171/**
3172 * Upgrade from V338 to V339
3173 */
3174static BOOL H_UpgradeFromV338(int currVersion, int newVersion)
3175{
3176 CHK_EXEC(CreateConfigParam(_T("EscapeLocalCommands"), _T("0"), 1, 0));
e4926628 3177 CHK_EXEC(SetSchemaVersion(339));
815638fe
VK
3178 return TRUE;
3179}
3180
9208c84b
VK
3181/**
3182 * Upgrade from V337 to V338
3183 */
3184static BOOL H_UpgradeFromV337(int currVersion, int newVersion)
3185{
3186 static TCHAR batch[] =
3187 _T("ALTER TABLE nodes ADD icmp_proxy integer\n")
3188 _T("UPDATE nodes SET icmp_proxy=0\n")
3189 _T("<END>");
3190 CHK_EXEC(SQLBatch(batch));
e4926628 3191 CHK_EXEC(SetSchemaVersion(338));
9208c84b
VK
3192 return TRUE;
3193}
3194
d368074d
VK
3195/**
3196 * Upgrade from V336 to V337
3197 */
3198static BOOL H_UpgradeFromV336(int currVersion, int newVersion)
3199{
3200 CHK_EXEC(CreateConfigParam(_T("SyslogNodeMatchingPolicy"), _T("0"), 1, 1));
e4926628 3201 CHK_EXEC(SetSchemaVersion(337));
d368074d
VK
3202 return TRUE;
3203}
3204
2b01f47c 3205/**
3206 * Upgrade from V335 to V336
3207 */
3208static BOOL H_UpgradeFromV335(int currVersion, int newVersion)
3209{
b69710b9
VK
3210 CHK_EXEC(ResizeColumn(_T("network_map_links"), _T("connector_name1"), 255, true));
3211 CHK_EXEC(ResizeColumn(_T("network_map_links"), _T("connector_name2"), 255, true));
e4926628 3212 CHK_EXEC(SetSchemaVersion(336));
2b01f47c 3213 return TRUE;
3214}
3215
b30bb1bc 3216/**
3217 * Upgrade from V334 to V335
3218 */
3219static BOOL H_UpgradeFromV334(int currVersion, int newVersion)
3220{
3da098f7 3221 CHK_EXEC(CreateEventTemplate(EVENT_IF_MASK_CHANGED, _T("SYS_IF_MASK_CHANGED"), SEVERITY_NORMAL, EF_LOG, NULL,
17b15353
VK
3222 _T("Interface \"%2\" changed mask from %6 to %4 (IP Addr: %3/%4, IfIndex: %5)"),
3223 _T("Generated when when network mask on interface is changed.\r\n")
3224 _T("Parameters:\r\n")
3225 _T(" 1) Interface object ID\r\n")
3226 _T(" 2) Interface name\r\n")
3227 _T(" 3) IP address\r\n")
3228 _T(" 4) New network mask\r\n")
3229 _T(" 5) Interface index\r\n")
3230 _T(" 6) Old network mask")));
e4926628 3231 CHK_EXEC(SetSchemaVersion(335));
b30bb1bc 3232 return TRUE;
3233}
3234
39e60274
AK
3235/**
3236 * Upgrade from V333 to V334
3237 */
3238static BOOL H_UpgradeFromV333(int currVersion, int newVersion)
3239{
241541f4 3240 CHK_EXEC(RemoveNotNullConstraint(_T("user_groups"), _T("description")));
e4926628 3241 CHK_EXEC(SetSchemaVersion(334));
39e60274
AK
3242 return TRUE;
3243}
3244
4899db4d 3245/**
3246 * Upgrade from V332 to V333
3247 */
3248static BOOL H_UpgradeFromV332(int currVersion, int newVersion)
3249{
3250 static TCHAR batch[] =
3251 _T("INSERT INTO metadata (var_name,var_value)")
3252 _T(" VALUES ('LocationHistory','CREATE TABLE gps_history_%d (latitude varchar(20), longitude varchar(20), accuracy integer not null, start_timestamp integer not null, end_timestamp integer not null, PRIMARY KEY(start_timestamp))')\n")