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