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