Implemented seperate access rights for reading Agent data, SNMP data and taking scree...
[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
4f50e45c 32/**
50963ced
VK
33 * Pre-defined GUID mapping for GenerateGUID
34 */
35struct GUID_MAPPING
36{
37 UINT32 id;
38 const TCHAR *guid;
39};
40
41/**
271e3971
VK
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
85/**
4f50e45c
VK
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/**
2d1a2003 118 * Create configuration parameter if it doesn't exist (unless forceUpdate 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 {
2d1a2003
VK
126 if (DBGetSchemaVersion(g_hCoreDB) >= 454)
127 _sntprintf(szQuery, 3024, _T("INSERT INTO config (var_name,var_value,default_value,is_visible,need_server_restart,is_public,data_type,description) VALUES (%s,%s,%s,%d,%d,'%c','%c',%s)"),
128 (const TCHAR *)DBPrepareString(g_hCoreDB, name, 63),
129 (const TCHAR *)DBPrepareString(g_hCoreDB, value, 2000),
130 (const TCHAR *)DBPrepareString(g_hCoreDB, value, 2000),
131 isVisible ? 1 : 0, needRestart ? 1 : 0,
132 isPublic ? _T('Y') : _T('N'), dataType, (const TCHAR *)DBPrepareString(g_hCoreDB, description, 255));
133 else
134 _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)"),
135 (const TCHAR *)DBPrepareString(g_hCoreDB, name, 63),
136 (const TCHAR *)DBPrepareString(g_hCoreDB, value, 2000), isVisible ? 1 : 0, needRestart ? 1 : 0,
137 isPublic ? _T('Y') : _T('N'), dataType, (const TCHAR *)DBPrepareString(g_hCoreDB, description, 255));
c85c8ef2 138 success = SQLQuery(szQuery);
5039dede 139 }
c85c8ef2 140 else if (forceUpdate)
5039dede 141 {
2589cc10 142 _sntprintf(szQuery, 3024, _T("UPDATE config SET var_value=%s WHERE var_name=%s"),
143 (const TCHAR *)DBPrepareString(g_hCoreDB, value, 2000), (const TCHAR *)DBPrepareString(g_hCoreDB, name, 63));
c85c8ef2 144 success = SQLQuery(szQuery);
5039dede 145 }
c85c8ef2
VK
146 return success;
147}
148
149/**
150 * Create configuration parameter if it doesn't exist (unless bForceUpdate set to true)
151 */
152bool CreateConfigParam(const TCHAR *name, const TCHAR *value, bool isVisible, bool needRestart, bool forceUpdate)
153{
154 bool success = true;
2589cc10 155 TCHAR szQuery[3024];
c85c8ef2
VK
156 if (!IsConfigurationVariableExist(name))
157 {
2d1a2003
VK
158 if (DBGetSchemaVersion(g_hCoreDB) >= 454)
159 _sntprintf(szQuery, 3024, _T("INSERT INTO config (var_name,var_value,default_value,is_visible,need_server_restart) VALUES (%s,%s,%s,%d,%d)"),
160 (const TCHAR *)DBPrepareString(g_hCoreDB, name, 63),
161 (const TCHAR *)DBPrepareString(g_hCoreDB, value, 2000),
162 (const TCHAR *)DBPrepareString(g_hCoreDB, value, 2000),
163 isVisible ? 1 : 0, needRestart ? 1 : 0);
164 else
165 _sntprintf(szQuery, 3024, _T("INSERT INTO config (var_name,var_value,is_visible,need_server_restart) VALUES (%s,%s,%d,%d)"),
166 (const TCHAR *)DBPrepareString(g_hCoreDB, name, 63),
167 (const TCHAR *)DBPrepareString(g_hCoreDB, value, 2000), isVisible ? 1 : 0, needRestart ? 1 : 0);
c85c8ef2
VK
168 success = SQLQuery(szQuery);
169 }
170 else if (forceUpdate)
171 {
2589cc10 172 _sntprintf(szQuery, 3024, _T("UPDATE config SET var_value=%s WHERE var_name=%s"),
173 (const TCHAR *)DBPrepareString(g_hCoreDB, value, 2000), (const TCHAR *)DBPrepareString(g_hCoreDB, name, 63));
c85c8ef2
VK
174 success = SQLQuery(szQuery);
175 }
176 return success;
5039dede
AK
177}
178
4f50e45c 179/**
4f50e45c
VK
180 * Convert strings from # encoded form to normal form
181 */
d6bf58f9 182static BOOL ConvertStrings(const TCHAR *table, const TCHAR *idColumn, const TCHAR *idColumn2, const TCHAR *column, bool isStringId)
643c9dcb
VK
183{
184 DB_RESULT hResult;
185 TCHAR *query;
4e0e77e6 186 size_t queryLen = 512;
643c9dcb
VK
187 BOOL success = FALSE;
188
c29fb885 189 query = (TCHAR *)malloc(queryLen * sizeof(TCHAR));
fe12a1ea 190
2a964810 191 switch(g_dbSyntax)
a4743a0f
VK
192 {
193 case DB_SYNTAX_MSSQL:
9f6712bc 194 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE CAST(%s AS nvarchar(4000))=N'#00'"), table, column, column);
a4743a0f
VK
195 break;
196 case DB_SYNTAX_ORACLE:
197 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE to_char(%s)='#00'"), table, column, column);
198 break;
199 default:
200 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE %s='#00'"), table, column, column);
201 break;
202 }
fe12a1ea
VK
203 if (!SQLQuery(query))
204 {
205 free(query);
206 return FALSE;
207 }
208
6f33021d 209 _sntprintf(query, queryLen, _T("SELECT %s,%s%s%s FROM %s WHERE %s LIKE '%%#%%'"),
98cd01bb 210 idColumn, column, (idColumn2 != NULL) ? _T(",") : _T(""), (idColumn2 != NULL) ? idColumn2 : _T(""), table, column);
643c9dcb
VK
211 hResult = SQLSelect(query);
212 if (hResult == NULL)
213 {
214 free(query);
215 return FALSE;
216 }
217
218 int count = DBGetNumRows(hResult);
219 for(int i = 0; i < count; i++)
220 {
643c9dcb 221 TCHAR *value = DBGetField(hResult, i, 1, NULL, 0);
035a4d73 222 if (_tcschr(value, _T('#')) != NULL)
643c9dcb 223 {
035a4d73
VK
224 DecodeSQLString(value);
225 String newValue = DBPrepareString(g_hCoreDB, value);
4e0e77e6 226 if (newValue.length() + 256 > queryLen)
035a4d73 227 {
4e0e77e6 228 queryLen = newValue.length() + 256;
c29fb885 229 query = (TCHAR *)realloc(query, queryLen * sizeof(TCHAR));
035a4d73 230 }
d6bf58f9 231 if (isStringId)
98cd01bb 232 {
d6bf58f9
VK
233 TCHAR *id = DBGetField(hResult, i, 0, NULL, 0);
234 if (idColumn2 != NULL)
235 {
236 TCHAR *id2 = DBGetField(hResult, i, 2, NULL, 0);
237 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=%s AND %s=%s"),
238 table, column, (const TCHAR *)newValue,
6f33021d 239 idColumn, (const TCHAR *)DBPrepareString(g_hCoreDB, id),
d6bf58f9
VK
240 idColumn2, (const TCHAR *)DBPrepareString(g_hCoreDB, id2));
241 }
242 else
243 {
244 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=%s"), table, column,
245 (const TCHAR *)newValue, idColumn, (const TCHAR *)DBPrepareString(g_hCoreDB, id));
246 }
247 free(id);
98cd01bb
VK
248 }
249 else
250 {
d6bf58f9
VK
251 INT64 id = DBGetFieldInt64(hResult, i, 0);
252 if (idColumn2 != NULL)
253 {
254 INT64 id2 = DBGetFieldInt64(hResult, i, 2);
6f33021d 255 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=") INT64_FMT _T(" AND %s=") INT64_FMT,
d6bf58f9
VK
256 table, column, (const TCHAR *)newValue, idColumn, id, idColumn2, id2);
257 }
258 else
259 {
260 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=") INT64_FMT, table, column,
261 (const TCHAR *)newValue, idColumn, id);
262 }
98cd01bb 263 }
035a4d73
VK
264 if (!SQLQuery(query))
265 goto cleanup;
643c9dcb 266 }
643c9dcb
VK
267 }
268 success = TRUE;
269
270cleanup:
271 DBFreeResult(hResult);
a4743a0f 272 free(query);
643c9dcb
VK
273 return success;
274}
275
98cd01bb
VK
276static BOOL ConvertStrings(const TCHAR *table, const TCHAR *idColumn, const TCHAR *column)
277{
d6bf58f9 278 return ConvertStrings(table, idColumn, NULL, column, false);
98cd01bb
VK
279}
280
4f50e45c 281/**
4f50e45c
VK
282 * Create new event template
283 */
3da098f7 284static BOOL CreateEventTemplate(int code, const TCHAR *name, int severity, int flags, const TCHAR *guid, const TCHAR *message, const TCHAR *description)
aa16f82b 285{
480e036b 286 TCHAR query[4096];
aa16f82b 287
3da098f7
VK
288 if (guid != NULL)
289 {
290 _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')"),
291 code, name, severity, flags, (const TCHAR *)DBPrepareString(g_hCoreDB, message),
292 (const TCHAR *)DBPrepareString(g_hCoreDB, description), guid);
293 }
294 else
295 {
296 _sntprintf(query, 4096, _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES (%d,'%s',%d,%d,%s,%s)"),
297 code, name, severity, flags, (const TCHAR *)DBPrepareString(g_hCoreDB, message),
298 (const TCHAR *)DBPrepareString(g_hCoreDB, description));
299 }
aa16f82b
VK
300 return SQLQuery(query);
301}
302
4f50e45c 303/**
22aaa779
VK
304 * Re-create TDATA tables
305 */
2f1bc68b 306static BOOL RecreateTData(const TCHAR *className, bool multipleTables, bool indexFix)
22aaa779 307{
1d4f7890 308 TCHAR query[1024];
22aaa779
VK
309 _sntprintf(query, 256, _T("SELECT id FROM %s"), className);
310 DB_RESULT hResult = SQLSelect(query);
311 if (hResult != NULL)
312 {
313 int count = DBGetNumRows(hResult);
314 for(int i = 0; i < count; i++)
315 {
2f1bc68b 316 bool recreateTables = true;
22aaa779
VK
317 DWORD id = DBGetFieldULong(hResult, i, 0);
318
2f1bc68b 319 if (indexFix)
1d4f7890 320 {
2f1bc68b
VK
321 _sntprintf(query, 256, _T("SELECT count(*) FROM dc_tables WHERE node_id=%d"), id);
322 DB_RESULT hResultCount = SQLSelect(query);
323 if (hResultCount != NULL)
22aaa779 324 {
7d4f8ace 325 recreateTables = (DBGetFieldLong(hResultCount, 0, 0) == 0);
2f1bc68b
VK
326 DBFreeResult(hResultCount);
327 }
328
329 if (!recreateTables)
330 {
a9f5aa55 331 _sntprintf(query, 256, _T("CREATE INDEX idx_tdata_rec_%d_id ON tdata_records_%d(record_id)"), id, id);
2f1bc68b
VK
332 if (!SQLQuery(query))
333 {
334 if (!g_bIgnoreErrors)
335 {
336 DBFreeResult(hResult);
337 return FALSE;
338 }
339 }
22aaa779
VK
340 }
341 }
342
2f1bc68b 343 if (recreateTables)
22aaa779 344 {
2f1bc68b 345 if (multipleTables)
22aaa779 346 {
2f1bc68b
VK
347 _sntprintf(query, 1024, _T("DROP TABLE tdata_rows_%d\nDROP TABLE tdata_records_%d\nDROP TABLE tdata_%d\n<END>"), id, id, id);
348 }
349 else
350 {
351 _sntprintf(query, 256, _T("DROP TABLE tdata_%d\n<END>"), id);
352 }
353 if (!SQLBatch(query))
354 {
355 if (!g_bIgnoreErrors)
356 {
357 DBFreeResult(hResult);
358 return FALSE;
359 }
360 }
361
63604cda 362 if (!CreateTDataTable(id))
2f1bc68b
VK
363 {
364 if (!g_bIgnoreErrors)
365 {
366 DBFreeResult(hResult);
367 return FALSE;
368 }
22aaa779
VK
369 }
370 }
371 }
372 DBFreeResult(hResult);
373 }
374 else
375 {
376 if (!g_bIgnoreErrors)
377 return FALSE;
378 }
385b1f20 379 return TRUE;
380}
381
382/**
c75e9ee4
VK
383 * Convert network masks from dotted decimal format to number of bits
384 */
385static BOOL ConvertNetMasks(const TCHAR *table, const TCHAR *column, const TCHAR *idColumn, const TCHAR *idColumn2 = NULL, const TCHAR *condition = NULL)
386{
387 TCHAR query[256];
fcf91b2e 388
c75e9ee4
VK
389 if (idColumn2 != NULL)
390 _sntprintf(query, 256, _T("SELECT %s,%s,%s FROM %s"), idColumn, column, idColumn2, table);
391 else
392 _sntprintf(query, 256, _T("SELECT %s,%s FROM %s"), idColumn, column, table);
393 DB_RESULT hResult = SQLSelect(query);
394 if (hResult == NULL)
395 return FALSE;
396
16684f16 397 bool success = DBDropColumn(g_hCoreDB, table, column);
fcf91b2e 398
c75e9ee4
VK
399 if (success)
400 {
401 _sntprintf(query, 256, _T("ALTER TABLE %s ADD %s integer"), table, column);
402 success = SQLQuery(query);
403 }
404
405 if (success)
406 {
407 int count = DBGetNumRows(hResult);
408 for(int i = 0; (i < count) && success; i++)
409 {
410 if (idColumn2 != NULL)
411 {
412 TCHAR id2[256];
fcf91b2e 413 _sntprintf(query, 256, _T("UPDATE %s SET %s=%d WHERE %s=%d AND %s='%s'"),
c75e9ee4
VK
414 table, column, BitsInMask(DBGetFieldIPAddr(hResult, i, 1)), idColumn, DBGetFieldLong(hResult, i, 0),
415 idColumn2, DBGetField(hResult, i, 2, id2, 256));
416 }
417 else
418 {
fcf91b2e 419 _sntprintf(query, 256, _T("UPDATE %s SET %s=%d WHERE %s=%d"),
c75e9ee4
VK
420 table, column, BitsInMask(DBGetFieldIPAddr(hResult, i, 1)), idColumn, DBGetFieldLong(hResult, i, 0));
421 }
422 success = SQLQuery(query);
423 }
424 }
425
426 DBFreeResult(hResult);
427 return success;
428}
429
430/**
b2a15edc
VK
431 * Convert object tool macros to new format
432 */
433static bool ConvertObjectToolMacros(UINT32 id, const TCHAR *text, const TCHAR *column)
434{
435 if (_tcschr(text, _T('%')) == NULL)
436 return true; // nothing to convert
437
438 String s;
439 for(const TCHAR *p = text; *p != 0; p++)
440 {
441 if (*p == _T('%'))
442 {
443 TCHAR name[256];
444 int i = 0;
445 for(p++; (*p != _T('%')) && (*p != 0); p++)
446 {
447 if (i < 255)
448 name[i++] = *p;
449 }
450 if (*p == 0)
451 break; // malformed string
452 name[i] = 0;
453 if (!_tcscmp(name, _T("ALARM_ID")))
454 {
455 s.append(_T("%Y"));
456 }
457 else if (!_tcscmp(name, _T("ALARM_MESSAGE")))
458 {
459 s.append(_T("%A"));
460 }
461 else if (!_tcscmp(name, _T("ALARM_SEVERITY")))
462 {
463 s.append(_T("%s"));
464 }
465 else if (!_tcscmp(name, _T("ALARM_SEVERITY_TEXT")))
466 {
467 s.append(_T("%S"));
468 }
469 else if (!_tcscmp(name, _T("ALARM_STATE")))
470 {
471 s.append(_T("%y"));
472 }
473 else if (!_tcscmp(name, _T("OBJECT_ID")))
474 {
475 s.append(_T("%I"));
476 }
477 else if (!_tcscmp(name, _T("OBJECT_IP_ADDR")))
478 {
479 s.append(_T("%a"));
480 }
481 else if (!_tcscmp(name, _T("OBJECT_NAME")))
482 {
483 s.append(_T("%n"));
484 }
485 else if (!_tcscmp(name, _T("USERNAME")))
486 {
487 s.append(_T("%U"));
488 }
489 else
490 {
491 s.append(_T("%{"));
492 s.append(name);
493 s.append(_T('}'));
494 }
495 }
496 else
497 {
498 s.append(*p);
499 }
500 }
501
502 String query = _T("UPDATE object_tools SET ");
503 query.append(column);
504 query.append(_T('='));
505 query.append(DBPrepareString(g_hCoreDB, s));
506 query.append(_T(" WHERE tool_id="));
507 query.append(id);
508 return SQLQuery(query);
509}
8a1519ce
VK
510
511/**
83aa5ebd
VK
512 * Create library script
513 */
514static bool CreateLibraryScript(UINT32 id, const TCHAR *name, const TCHAR *code)
515{
516 // Check if script exists
517 TCHAR query[256];
518 _sntprintf(query, 256, _T("SELECT script_id FROM script_library WHERE script_id=%d OR script_name=%s"),
519 id, (const TCHAR *)DBPrepareString(g_hCoreDB, name));
520 DB_RESULT hResult = SQLSelect(query);
521 if (hResult == NULL)
522 return false;
523 bool exist = (DBGetNumRows(hResult) > 0);
524 DBFreeResult(hResult);
525 if (exist)
526 return true;
527
528 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("INSERT INTO script_library (script_id,script_name,script_code) VALUES (?,?,?)"));
529 if (hStmt == NULL)
530 return false;
531
532 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, id);
533 DBBind(hStmt, 2, DB_SQLTYPE_VARCHAR, name, DB_BIND_STATIC);
534 DBBind(hStmt, 3, DB_SQLTYPE_TEXT, code, DB_BIND_STATIC);
535
536 bool success = SQLExecute(hStmt);
537 DBFreeStatement(hStmt);
538 return success;
539}
540
541/**
e2a9c5fc
VK
542 * Check if an event pair is handled by any EPP rules
543 */
544static bool IsEventPairInUse(UINT32 code1, UINT32 code2)
545{
546 TCHAR query[256];
547 _sntprintf(query, 256, _T("SELECT count(*) FROM policy_event_list WHERE event_code=%d OR event_code=%d"), code1, code2);
548 DB_RESULT hResult = SQLSelect(query);
549 if (hResult == NULL)
550 return false;
551 bool inUse = (DBGetFieldLong(hResult, 0, 0) > 0);
552 DBFreeResult(hResult);
553 return inUse;
554}
555
556/**
557 * Return the next free EPP rule ID
558 */
559static int NextFreeEPPruleID()
560{
561 int ruleId = 1;
562 DB_RESULT hResult = SQLSelect(_T("SELECT max(rule_id) FROM event_policy"));
563 if (hResult != NULL)
564 {
565 ruleId = DBGetFieldLong(hResult, 0, 0) + 1;
566 DBFreeResult(hResult);
567 }
568 return ruleId;
569}
570
bad2c02e 571/**
de1be1b5
VK
572 * Add event to EPP rule by rule GUID
573 */
574static bool AddEventToEPPRule(const TCHAR *guid, UINT32 eventCode)
575{
576 TCHAR query[256];
577 _sntprintf(query, 256, _T("SELECT rule_id FROM event_policy WHERE rule_guid='%s'"), guid);
578 DB_RESULT hResult = SQLSelect(query);
579 if (hResult == NULL)
580 return false;
581
582 bool success = true;
583 if (DBGetNumRows(hResult) > 0)
584 {
585 _sntprintf(query, 256, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), DBGetFieldLong(hResult, 0, 0), eventCode);
586 success = SQLQuery(query);
587 }
588 DBFreeResult(hResult);
589 return success;
590}
591
592/**
e4926628
VK
593 * Set schema version
594 */
595static bool SetSchemaVersion(int version)
596{
597 TCHAR query[256];
598 _sntprintf(query, 256, _T("UPDATE metadata SET var_value='%d' WHERE var_name='SchemaVersion'"), version);
599 return SQLQuery(query);
600}
601
91b3cba9 602BOOL moveFlagsFromOldTables(const TCHAR *tableName)
603{
604 //_tprintf(_T("Move flags from %s\n"), tableName);
605 TCHAR query[256];
606 _sntprintf(query, 256, _T("SELECT id,flags FROM %s"), tableName);
607 DB_RESULT hResult = DBSelect(g_hCoreDB, query);
608 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("UPDATE object_properties SET flags=? WHERE object_id=?"));
609 if (hResult != NULL)
610 {
611 if (hStmt != NULL)
612 {
613 int nRows = DBGetNumRows(hResult);
614 for(int i = 0; i < nRows; i++)
615 {
616 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 1));
617 DBBind(hStmt, 2, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 0));
618
619 if (!SQLExecute(hStmt))
620 {
621 if (!g_bIgnoreErrors)
622 {
623 DBFreeStatement(hStmt);
624 DBFreeResult(hResult);
625 return FALSE;
626 }
627 }
628 }
629 DBFreeStatement(hStmt);
630 }
631 else if (!g_bIgnoreErrors)
632 {
633 return FALSE;
634 }
635 DBFreeResult(hResult);
636 }
637 else if (!g_bIgnoreErrors)
638 {
639 return FALSE;
640 }
641
642
643 CHK_EXEC(DBDropColumn(g_hCoreDB, tableName, _T("flags")));
644 return TRUE;
645}
646
4c9334b4 647/**
a09e19b1
EJ
648 * Upgrade from V505 to V506 included in stable as 461
649 */
650static BOOL H_UpgradeFromV505(int currVersion, int newVersion)
651{
652 DB_RESULT hResult = DBSelect(g_hCoreDB, _T("SELECT access_rights,object_id FROM acl WHERE user_id=-2147483647")); // Get group Admins object acl
653 if (hResult != NULL)
654 {
655 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("UPDATE acl SET access_rights=? WHERE user_id=-2147483647 AND object_id=? "));
656 if (hStmt != NULL)
657 {
658 int nRows = DBGetNumRows(hResult);
659 UINT32 rights;
660 for(int i = 0; i < nRows; i++)
661 {
662 rights = DBGetFieldULong(hResult, i, 0);
663 if (rights & OBJECT_ACCESS_READ)
664 {
665 rights |= (OBJECT_ACCESS_READ_AGENT | OBJECT_ACCESS_READ_SNMP | OBJECT_ACCESS_SCREENSHOT);
666 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, rights);
667 DBBind(hStmt, 2, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 1));
668
669 if (!SQLExecute(hStmt))
670 {
671 if (!g_bIgnoreErrors)
672 {
673 DBFreeStatement(hStmt);
674 DBFreeResult(hResult);
675 return FALSE;
676 }
677 }
678 }
679 }
680
681 DBFreeStatement(hStmt);
682 }
683 else if (!g_bIgnoreErrors)
684 return FALSE;
685 DBFreeResult(hResult);
686 }
687 else if (!g_bIgnoreErrors)
688 return FALSE;
689
690 CHK_EXEC(SetSchemaVersion(506));
691 return TRUE;
692}
693
694/**
a5bfc694 695 * Upgrade from V504 to V505 included in stable as 460
696 */
697static BOOL H_UpgradeFromV504(int currVersion, int newVersion)
698{
699 static const TCHAR *batch =
700 _T("UPDATE nodes SET fail_time_snmp=0 WHERE fail_time_snmp IS NULL\n")
701 _T("UPDATE nodes SET fail_time_agent=0 WHERE fail_time_agent IS NULL\n")
702 _T("<END>");
703 CHK_EXEC(SQLBatch(batch));
704
705 DBSetNotNullConstraint(g_hCoreDB, _T("nodes"), _T("fail_time_snmp"));
706 DBSetNotNullConstraint(g_hCoreDB, _T("nodes"), _T("fail_time_agent"));
707
708 CHK_EXEC(SetSchemaVersion(505));
709 return TRUE;
710}
711
712/**
713 * Upgrade from V503 to V504 included in stable as 459
588c88e6 714 */
715static BOOL H_UpgradeFromV503(int currVersion, int newVersion)
716{
717 static const TCHAR *batch =
718 _T("ALTER TABLE nodes ADD fail_time_snmp integer\n")
719 _T("ALTER TABLE nodes ADD fail_time_agent integer\n")
720 _T("<END>");
721 CHK_EXEC(SQLBatch(batch));
a5bfc694 722
588c88e6 723 CHK_EXEC(SetSchemaVersion(504));
724 return TRUE;
725}
726
727/**
4c9334b4
VK
728 * Move single flag
729 */
730inline void MoveFlag(UINT32 oldVar, UINT32 *newVar, UINT32 oldFlag, UINT32 newFlag)
91b3cba9 731{
eb747bd9 732 *newVar |= ((oldVar & oldFlag) != 0) ? newFlag : 0;
91b3cba9 733}
734
4c9334b4
VK
735/**
736 * Move node flags
737 */
738static void MoveNodeFlags(UINT32 oldFlag, UINT32 *flags)
91b3cba9 739{
4c9334b4
VK
740 MoveFlag(oldFlag, flags, 0x10000000, DCF_DISABLE_STATUS_POLL);
741 MoveFlag(oldFlag, flags, 0x20000000, DCF_DISABLE_CONF_POLL);
742 MoveFlag(oldFlag, flags, 0x80000000, DCF_DISABLE_DATA_COLLECT);
743 MoveFlag(oldFlag, flags, 0x00000080, NF_REMOTE_AGENT);
744 MoveFlag(oldFlag, flags, 0x00400000, NF_DISABLE_DISCOVERY_POLL);
745 MoveFlag(oldFlag, flags, 0x00800000, NF_DISABLE_TOPOLOGY_POLL);
746 MoveFlag(oldFlag, flags, 0x01000000, NF_DISABLE_SNMP);
747 MoveFlag(oldFlag, flags, 0x02000000, NF_DISABLE_NXCP);
748 MoveFlag(oldFlag, flags, 0x04000000, NF_DISABLE_ICMP);
749 MoveFlag(oldFlag, flags, 0x08000000, NF_FORCE_ENCRYPTION);
750 MoveFlag(oldFlag, flags, 0x40000000, NF_DISABLE_ROUTE_POLL);
91b3cba9 751}
752
4c9334b4
VK
753/**
754 * Move node capabilities flags
755 */
756static void MoveNodeCapabilities(UINT32 oldFlag, UINT32 *capabilities)
91b3cba9 757{
4c9334b4
VK
758 MoveFlag(oldFlag, capabilities, 0x00000001, NC_IS_SNMP);
759 MoveFlag(oldFlag, capabilities, 0x00000002, NC_IS_NATIVE_AGENT);
760 MoveFlag(oldFlag, capabilities, 0x00000004, NC_IS_BRIDGE);
761 MoveFlag(oldFlag, capabilities, 0x00000008, NC_IS_ROUTER);
762 MoveFlag(oldFlag, capabilities, 0x00000010, NC_IS_LOCAL_MGMT);
763 MoveFlag(oldFlag, capabilities, 0x00000020, NC_IS_PRINTER);
764 MoveFlag(oldFlag, capabilities, 0x00000040, NC_IS_OSPF);
765 MoveFlag(oldFlag, capabilities, 0x00000100, NC_IS_CPSNMP);
766 MoveFlag(oldFlag, capabilities, 0x00000200, NC_IS_CDP);
767 MoveFlag(oldFlag, capabilities, 0x00000400, NC_IS_NDP);
768 MoveFlag(oldFlag, capabilities, 0x00000800, NC_IS_LLDP);
769 MoveFlag(oldFlag, capabilities, 0x00001000, NC_IS_VRRP);
770 MoveFlag(oldFlag, capabilities, 0x00002000, NC_HAS_VLANS);
771 MoveFlag(oldFlag, capabilities, 0x00004000, NC_IS_8021X);
772 MoveFlag(oldFlag, capabilities, 0x00008000, NC_IS_STP);
773 MoveFlag(oldFlag, capabilities, 0x00010000, NC_HAS_ENTITY_MIB);
774 MoveFlag(oldFlag, capabilities, 0x00020000, NC_HAS_IFXTABLE);
775 MoveFlag(oldFlag, capabilities, 0x00040000, NC_HAS_AGENT_IFXCOUNTERS);
776 MoveFlag(oldFlag, capabilities, 0x00080000, NC_HAS_WINPDH);
777 MoveFlag(oldFlag, capabilities, 0x00100000, NC_IS_WIFI_CONTROLLER);
778 MoveFlag(oldFlag, capabilities, 0x00200000, NC_IS_SMCLP);
91b3cba9 779}
780
4c9334b4
VK
781/**
782 * Move node state flags
783 */
784static void MoveNodeState(UINT32 oldRuntime, UINT32 *state)
91b3cba9 785{
a0cc56b3 786 MoveFlag(oldRuntime, state, 0x000004, DCSF_UNREACHABLE);
4c9334b4
VK
787 MoveFlag(oldRuntime, state, 0x000008, NSF_AGENT_UNREACHABLE);
788 MoveFlag(oldRuntime, state, 0x000010, NSF_SNMP_UNREACHABLE);
789 MoveFlag(oldRuntime, state, 0x000200, NSF_CPSNMP_UNREACHABLE);
a0cc56b3 790 MoveFlag(oldRuntime, state, 0x008000, DCSF_NETWORK_PATH_PROBLEM);
4c9334b4 791 MoveFlag(oldRuntime, state, 0x020000, NSF_CACHE_MODE_NOT_SUPPORTED);
91b3cba9 792}
793
4c9334b4
VK
794/**
795 * Move sensor state flags
796 */
797static void MoveSensorState(UINT32 oldFlag, UINT32 oldRuntime, UINT32 *status)
91b3cba9 798{
4c9334b4
VK
799 MoveFlag(oldFlag, status, 0x00000001, SSF_PROVISIONED);
800 MoveFlag(oldFlag, status, 0x00000002, SSF_REGISTERED);
801 MoveFlag(oldFlag, status, 0x00000004, SSF_ACTIVE);
802 MoveFlag(oldFlag, status, 0x00000008, SSF_CONF_UPDATE_PENDING);
a0cc56b3 803 MoveFlag(oldRuntime, status, 0x000004, DCSF_UNREACHABLE);
91b3cba9 804}
805
806/**
b8d12b03 807 * Upgrade from V502 to V503
91b3cba9 808 */
b8d12b03 809static BOOL H_UpgradeFromV502(int currVersion, int newVersion)
91b3cba9 810{
91b3cba9 811 static const TCHAR *batch =
812 _T("ALTER TABLE object_properties ADD flags integer null\n")
813 _T("ALTER TABLE object_properties ADD state integer null\n")
814 _T("ALTER TABLE nodes ADD capabilities integer null\n")
815 _T("UPDATE object_properties set flags=0,state=0\n")
816 _T("<END>");
817 CHK_EXEC(SQLBatch(batch));
4c9334b4 818
91b3cba9 819 //move flags from old tables to the new one
820 CHK_EXEC(moveFlagsFromOldTables(_T("interfaces")));
821 CHK_EXEC(moveFlagsFromOldTables(_T("templates")));
822 CHK_EXEC(moveFlagsFromOldTables(_T("chassis")));
823 CHK_EXEC(moveFlagsFromOldTables(_T("object_containers")));
824 CHK_EXEC(moveFlagsFromOldTables(_T("network_maps")));
4c9334b4 825 //create special behavior for node and sensor, cluster
91b3cba9 826 //node
827 DB_RESULT hResult = DBSelect(g_hCoreDB, _T("SELECT id,runtime_flags FROM nodes"));
828 DB_STATEMENT stmtNetObj = DBPrepare(g_hCoreDB, _T("UPDATE object_properties SET flags=?, state=? WHERE object_id=?"));
829 DB_STATEMENT stmtNode = DBPrepare(g_hCoreDB, _T("UPDATE nodes SET capabilities=? WHERE id=?"));
830 if (hResult != NULL)
831 {
832 if (stmtNetObj != NULL && stmtNode != NULL)
833 {
834 int nRows = DBGetNumRows(hResult);
835 for(int i = 0; i < nRows; i++)
836 {
837 UINT32 id = DBGetFieldULong(hResult, i, 0);
838 UINT32 oldFlags = 0;
839 UINT32 oldRuntime = DBGetFieldULong(hResult, i, 1);
840 UINT32 flags = 0;
841 UINT32 state = 0;
842 UINT32 capabilities = 0;
843 TCHAR query[256];
844 _sntprintf(query, 256, _T("SELECT node_flags FROM nodes WHERE id=%d"), id);
845 DB_RESULT flagResult = DBSelect(g_hCoreDB, query);
846 if(DBGetNumRows(flagResult) >= 1)
847 {
864ac54b 848 oldFlags = DBGetFieldULong(flagResult, 0, 0);
91b3cba9 849 }
850 else
851 {
852 if(!g_bIgnoreErrors)
853 {
854 DBFreeStatement(stmtNetObj);
855 DBFreeStatement(stmtNode);
856 DBFreeResult(hResult);
857 return FALSE;
858 }
859 }
4c9334b4
VK
860 MoveNodeFlags(oldFlags, &flags);
861 MoveNodeCapabilities(oldFlags, &capabilities);
862 MoveNodeState(oldRuntime, &state);
91b3cba9 863
864 DBBind(stmtNetObj, 1, DB_SQLTYPE_INTEGER, flags);
865 DBBind(stmtNetObj, 2, DB_SQLTYPE_INTEGER, state);
866 DBBind(stmtNetObj, 3, DB_SQLTYPE_INTEGER, id);
867
868 DBBind(stmtNode, 1, DB_SQLTYPE_INTEGER, capabilities);
869 DBBind(stmtNode, 2, DB_SQLTYPE_INTEGER, id);
870
871 if (!(SQLExecute(stmtNetObj)))
872 {
873 if (!g_bIgnoreErrors)
874 {
875 DBFreeStatement(stmtNetObj);
876 DBFreeStatement(stmtNode);
877 DBFreeResult(hResult);
878 return FALSE;
879 }
880 }
881
882 if (!SQLExecute(stmtNode))
883 {
884 if (!g_bIgnoreErrors)
885 {
886 DBFreeStatement(stmtNetObj);
887 DBFreeStatement(stmtNode);
888 DBFreeResult(hResult);
889 return FALSE;
890 }
891 }
892 }
893 DBFreeStatement(stmtNetObj);
894 DBFreeStatement(stmtNode);
895 }
896 else
897 {
898 if(stmtNetObj != NULL)
899 DBFreeStatement(stmtNetObj);
900
901 if(stmtNode != NULL)
902 DBFreeStatement(stmtNode);
903 if (!g_bIgnoreErrors)
904 {
905 return FALSE;
906 }
907 }
908 DBFreeResult(hResult);
909 }
910 CHK_EXEC(DBDropColumn(g_hCoreDB, _T("nodes"), _T("runtime_flags")));
911 CHK_EXEC(DBDropColumn(g_hCoreDB, _T("nodes"), _T("node_flags")));
912
913 //sensor
914 hResult = DBSelect(g_hCoreDB, _T("SELECT id,runtime_flags,flags FROM sensors"));
915 DB_STATEMENT stmt = DBPrepare(g_hCoreDB, _T("UPDATE object_properties SET status=? WHERE object_id=?"));
916 if (hResult != NULL)
917 {
918 if (stmt != NULL)
919 {
920 int nRows = DBGetNumRows(hResult);
921 for(int i = 0; i < nRows; i++)
922 {
923 UINT32 status = 0;
4c9334b4 924 MoveSensorState(DBGetFieldULong(hResult, i, 2), DBGetFieldULong(hResult, i, 1), &status);
91b3cba9 925
926 DBBind(stmt, 1, DB_SQLTYPE_INTEGER, status);
927 DBBind(stmt, 2, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 0));
928
929 if (!(SQLExecute(stmt)))
930 {
931 if (!g_bIgnoreErrors)
932 {
933 DBFreeStatement(stmt);
934 DBFreeResult(hResult);
935 return FALSE;
936 }
937 }
938 }
939 DBFreeStatement(stmt);
940 }
941 else if (!g_bIgnoreErrors)
942 {
943 return FALSE;
944 }
945 DBFreeResult(hResult);
946 }
947 CHK_EXEC(DBDropColumn(g_hCoreDB, _T("sensors"), _T("runtime_flags")));
948 CHK_EXEC(DBDropColumn(g_hCoreDB, _T("sensors"), _T("flags")));
949
b8d12b03 950 CHK_EXEC(SetSchemaVersion(503));
91b3cba9 951 return TRUE;
952}
953
80d9447b 954/**
1b281c3e
EJ
955 * Upgrade from V501 to V502
956 */
957static BOOL H_UpgradeFromV501(int currVersion, int newVersion)
958{
0993f384
VK
959 CHK_EXEC(DBDropColumn(g_hCoreDB, _T("event_groups"), _T("range_start")));
960 CHK_EXEC(DBDropColumn(g_hCoreDB, _T("event_groups"), _T("range_end")));
961
1b281c3e 962 static const TCHAR *batch =
1b281c3e
EJ
963 _T("ALTER TABLE event_groups ADD guid varchar(36) null\n")
964 _T("UPDATE event_groups SET guid='04b326c0-5cc0-411f-8587-2836cb87c920' WHERE id=-2147483647\n")
965 _T("UPDATE event_groups SET guid='b61859c6-1768-4a61-a0cf-eed07d688f66' WHERE id=-2147483646\n")
966 _T("<END>");
967 CHK_EXEC(SQLBatch(batch));
968 DBSetNotNullConstraint(g_hCoreDB, _T("event_groups"), _T("guid"));
0993f384 969
1b281c3e
EJ
970 CHK_EXEC(SetSchemaVersion(502));
971 return TRUE;
972}
973
974/**
2d1a2003 975 * Upgrade from V500 to V501
8d4fd499 976 */
2d1a2003 977static BOOL H_UpgradeFromV500(int currVersion, int newVersion)
8d4fd499
EJ
978{
979 static const TCHAR *batch =
980 _T("ALTER TABLE users ADD created integer null\n")
981 _T("ALTER TABLE user_groups ADD created integer null\n")
982 _T("UPDATE users SET created=0\n")
983 _T("UPDATE user_groups SET created=0\n")
984 _T("<END>");
985 CHK_EXEC(SQLBatch(batch));
986 CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("users"), _T("created")));
987 CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("user_groups"), _T("created")));
988
2d1a2003 989 CHK_EXEC(SetSchemaVersion(501));
8d4fd499
EJ
990 return TRUE;
991}
992
993/**
9e731f19 994 * Upgrade from V459 to V500
4a64a795 995 */
9e731f19 996static BOOL H_UpgradeFromV459(int currVersion, int newVersion)
ce9e00cc
VK
997{
998 CHK_EXEC(CreateTable(
999 _T("CREATE TABLE sensors (")
1000 _T(" id integer not null,")
1001 _T(" proxy_node integer not null,")
1002 _T(" flags integer not null,")
1003 _T(" mac_address varchar(16) null,")
1004 _T(" device_class integer not null,")
1005 _T(" vendor varchar(128) null,")
1006 _T(" communication_protocol integer not null,")
1007 _T(" xml_config varchar(4000) null,")
1008 _T(" xml_reg_config varchar(4000) null,")
1009 _T(" serial_number varchar(256) null,")
1010 _T(" device_address varchar(256) null,")
1011 _T(" meta_type varchar(256) null,")
1012 _T(" description varchar(512) null,")
1013 _T(" last_connection_time integer not null,")
1014 _T(" frame_count integer not null,")
1015 _T(" signal_strenght integer not null,")
1016 _T(" signal_noise integer not null,")
1017 _T(" frequency integer not null,")
1018 _T(" runtime_flags integer null,")
1019 _T("PRIMARY KEY(id))")));
1020
2d1a2003
VK
1021 CHK_EXEC(SetSchemaVersion(500));
1022 return TRUE;
1023}
1024
1025/**
9e731f19
VK
1026 * Upgrade from V458 to V459
1027 */
1028static BOOL H_UpgradeFromV458(int currVersion, int newVersion)
1029{
1030 CHK_EXEC(SQLQuery(_T("ALTER TABLE dci_summary_tables ADD table_dci_name varchar(255)")));
1031 CHK_EXEC(SetSchemaVersion(459));
1032 return TRUE;
1033}
1034
1035/**
2d1a2003
VK
1036 * Upgrade from V457 to V458
1037 */
1038static BOOL H_UpgradeFromV457(int currVersion, int newVersion)
1039{
1040 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',need_server_restart=0 WHERE var_name='DeleteUnreachableNodesPeriod'")));
1041 CHK_EXEC(CreateConfigParam(_T("LongRunningQueryThreshold"), _T("0"), _T("Threshold in milliseconds to report long running SQL queries (0 to disable)"), 'I', true, true, false, false));
ce9e00cc
VK
1042 CHK_EXEC(SetSchemaVersion(458));
1043 return TRUE;
1044}
1045
1046/**
1047 * Upgrade from V456 to V457
1048 */
4a64a795
VK
1049static BOOL H_UpgradeFromV456(int currVersion, int newVersion)
1050{
1051 CHK_EXEC(SQLQuery(_T("DELETE FROM config WHERE var_name='EnableAdminInterface'")));
1052 CHK_EXEC(SetSchemaVersion(457));
1053 return TRUE;
1054}
1055
1056/**
1d7917d5
VK
1057 * Upgrade from V455 to V456
1058 */
1059static BOOL H_UpgradeFromV455(int currVersion, int newVersion)
1060{
1061 CHK_EXEC(
1062 CreateEventTemplate(EVENT_PACKAGE_INSTALLED, _T("SYS_PACKAGE_INSTALLED"),
1063 SEVERITY_NORMAL, EF_LOG, _T("92e5cf98-a415-4414-9ad8-d155dac77e96"),
1064 _T("Package %1 %2 installed"),
1065 _T("Generated when new software package is found.\r\n")
1066 _T("Parameters:\r\n")
1067 _T(" 1) Package name\r\n")
1068 _T(" 2) Package version"))
1069 );
1070
1071 CHK_EXEC(
1072 CreateEventTemplate(EVENT_PACKAGE_UPDATED, _T("SYS_PACKAGE_UPDATED"),
1073 SEVERITY_NORMAL, EF_LOG, _T("9d5878c1-525e-4cab-8f02-2a6c46d7fc36"),
1074 _T("Package %1 updated from %3 to %2"),
1075 _T("Generated when software package version change is detected.\r\n")
1076 _T("Parameters:\r\n")
1077 _T(" 1) Package name\r\n")
1078 _T(" 2) New package version\r\n")
1079 _T(" 3) Old package version"))
1080 );
1081
1082 CHK_EXEC(
1083 CreateEventTemplate(EVENT_PACKAGE_REMOVED, _T("SYS_PACKAGE_REMOVED"),
1084 SEVERITY_NORMAL, EF_LOG, _T("6ada4ea4-43e4-4444-9d19-ef7366110bb9"),
1085 _T("Package %1 %2 removed"),
1086 _T("Generated when software package removal is detected.\r\n")
1087 _T("Parameters:\r\n")
1088 _T(" 1) Package name\r\n")
1089 _T(" 2) Last known package version"))
1090 );
1091
1092 int ruleId = NextFreeEPPruleID();
1093 TCHAR query[1024];
1094 _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) ")
1095 _T("VALUES (%d,'2bb3df47-482b-4e4b-9b49-8c72c6b33011',7944,'Generate alarm on software package changes','%%m',5,'SW_PKG_%%i_%%<name>','',0,%d)"),
1096 ruleId, EVENT_ALARM_TIMEOUT);
1097 CHK_EXEC(SQLQuery(query));
1098
1099 _sntprintf(query, 256, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_PACKAGE_INSTALLED);
1100 CHK_EXEC(SQLQuery(query));
1101 _sntprintf(query, 256, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_PACKAGE_UPDATED);
1102 CHK_EXEC(SQLQuery(query));
1103 _sntprintf(query, 256, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_PACKAGE_REMOVED);
1104 CHK_EXEC(SQLQuery(query));
1105
1106 CHK_EXEC(SetSchemaVersion(456));
1107 return TRUE;
1108}
1109
1110/**
26cfeea3
VK
1111 * Upgrade from V454 to V455
1112 */
1113static BOOL H_UpgradeFromV454(int currVersion, int newVersion)
1114{
1115 static const TCHAR *batch =
1116 _T("ALTER TABLE interfaces ADD parent_iface integer\n")
1117 _T("UPDATE interfaces SET parent_iface=0\n")
1118 _T("<END>");
1119 CHK_EXEC(SQLBatch(batch));
797a2b25 1120 CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("interfaces"), _T("parent_iface")));
1b281c3e 1121
26cfeea3
VK
1122 CHK_EXEC(SetSchemaVersion(455));
1123 return TRUE;
1124}
1125
1126/**
c7aa788e
EJ
1127 * Upgrade from V453 to V454
1128 */
1129static BOOL H_UpgradeFromV453(int currVersion, int newVersion)
1130{
1131 static const TCHAR *batch =
1132 _T("ALTER TABLE config ADD default_value varchar(2000) null\n")
1133 _T("UPDATE config SET default_value='7200' WHERE var_name='ActiveDiscoveryInterval'\n")
1134 _T("UPDATE config SET default_value='0' WHERE var_name='ActiveNetworkDiscovery'\n")
1135 _T("UPDATE config SET default_value='4000' WHERE var_name='AgentCommandTimeout'\n")
1136 _T("UPDATE config SET default_value='netxms' WHERE var_name='AgentDefaultSharedSecret'\n")
1137 _T("UPDATE config SET default_value='600' WHERE var_name='AgentUpgradeWaitTime'\n")
1138 _T("UPDATE config SET default_value='180' WHERE var_name='AlarmHistoryRetentionTime'\n")
1139 _T("UPDATE config SET default_value='4096' WHERE var_name='AlarmListDisplayLimit'\n")
1140 _T("UPDATE config SET default_value='0 0 * * *' WHERE var_name='AlarmSummaryEmailSchedule'\n")
1141 _T("UPDATE config SET default_value='0' WHERE var_name='AllowDirectSMS'\n")
1142 _T("UPDATE config SET default_value='63' WHERE var_name='AllowedCiphers'\n")
1143 _T("UPDATE config SET default_value='1' WHERE var_name='AllowTrapVarbindsConversion'\n")
1144 _T("UPDATE config SET default_value='0' WHERE var_name='AnonymousFileAccess'\n")
1145 _T("UPDATE config SET default_value='1' WHERE var_name='ApplyDCIFromTemplateToDisabledDCI'\n")
1146 _T("UPDATE config SET default_value='90' WHERE var_name='AuditLogRetentionTime'\n")
1147 _T("UPDATE config SET default_value='1000' WHERE var_name='BeaconPollingInterval'\n")
1148 _T("UPDATE config SET default_value='1000' WHERE var_name='BeaconTimeout'\n")
1149 _T("UPDATE config SET default_value='0' WHERE var_name='BlockInactiveUserAccounts'\n")
1150 _T("UPDATE config SET default_value='604800' WHERE var_name='CapabilityExpirationTime'\n")
1151 _T("UPDATE config SET default_value='0' WHERE var_name='CaseInsensitiveLoginNames'\n")
1152 _T("UPDATE config SET default_value='0' WHERE var_name='CheckTrustedNodes'\n")
1153 _T("UPDATE config SET default_value='4701' WHERE var_name='ClientListenerPort'\n")
1154 _T("UPDATE config SET default_value='0' WHERE var_name='ClusterContainerAutoBind'\n")
1155 _T("UPDATE config SET default_value='0' WHERE var_name='ClusterTemplateAutoApply'\n")
1156 _T("UPDATE config SET default_value='60' WHERE var_name='ConditionPollingInterval'\n")
1157 _T("UPDATE config SET default_value='3600' WHERE var_name='ConfigurationPollingInterval'\n")
1158 _T("UPDATE config SET default_value='1' WHERE var_name='DashboardDataExportEnableInterpolation'\n")
1159 _T("UPDATE config SET default_value='10' WHERE var_name='DBConnectionPoolBaseSize'\n")
1160 _T("UPDATE config SET default_value='300' WHERE var_name='DBConnectionPoolCooldownTime'\n")
1161 _T("UPDATE config SET default_value='14400' WHERE var_name='DBConnectionPoolMaxLifetime'\n")
1162 _T("UPDATE config SET default_value='30' WHERE var_name='DBConnectionPoolMaxSize'\n")
1163 _T("UPDATE config SET default_value='0' WHERE var_name='DBLockPID'\n")
1164 _T("UPDATE config SET default_value='UNLOCKED' WHERE var_name='DBLockStatus'\n")
1165 _T("UPDATE config SET default_value='2' WHERE var_name='DefaultAgentCacheMode'\n")
1166 _T("UPDATE config SET default_value='1' WHERE var_name='DefaultAgentProtocolCompressionMode'\n")
1167 _T("UPDATE config SET default_value='dd.MM.yyyy' WHERE var_name='DefaultConsoleDateFormat'\n")
1168 _T("UPDATE config SET default_value='HH:mm' WHERE var_name='DefaultConsoleShortTimeFormat'\n")
1169 _T("UPDATE config SET default_value='HH:mm:ss' WHERE var_name='DefaultConsoleTimeFormat'\n")
1170 _T("UPDATE config SET default_value='60' WHERE var_name='DefaultDCIPollingInterval'\n")
1171 _T("UPDATE config SET default_value='30' WHERE var_name='DefaultDCIRetentionTime'\n")
1172 _T("UPDATE config SET default_value='1' WHERE var_name='DefaultEncryptionPolicy'\n")
1173 _T("UPDATE config SET default_value='1' WHERE var_name='DefaultInterfaceExpectedState'\n")
1174 _T("UPDATE config SET default_value='0xffffff' WHERE var_name='DefaultMapBackgroundColor'\n")
1175 _T("UPDATE config SET default_value='24' WHERE var_name='DefaultSubnetMaskIPv4'\n")
1176 _T("UPDATE config SET default_value='64' WHERE var_name='DefaultSubnetMaskIPv6'\n")
1177 _T("UPDATE config SET default_value='1' WHERE var_name='DeleteAlarmsOfDeletedObject'\n")
1178 _T("UPDATE config SET default_value='0' WHERE var_name='DeleteEmptySubnets'\n")
1179 _T("UPDATE config SET default_value='1' WHERE var_name='DeleteEventsOfDeletedObject'\n")
1180 _T("UPDATE config SET default_value='0' WHERE var_name='DeleteUnreachableNodesPeriod'\n")
1181 _T("UPDATE config SET default_value='none' WHERE var_name='DiscoveryFilter'\n")
1182 _T("UPDATE config SET default_value='0' WHERE var_name='DiscoveryFilterFlags'\n")
1183 _T("UPDATE config SET default_value='900' WHERE var_name='DiscoveryPollingInterval'\n")
1184 _T("UPDATE config SET default_value='1' WHERE var_name='EnableAdminInterface'\n")
1185 _T("UPDATE config SET default_value='1' WHERE var_name='EnableAgentRegistration'\n")
1186 _T("UPDATE config SET default_value='1' WHERE var_name='EnableAuditLog'\n")
1187 _T("UPDATE config SET default_value='0' WHERE var_name='EnableCheckPointSNMP'\n")
1188 _T("UPDATE config SET default_value='0' WHERE var_name='EnableReportingServer'\n")
1189 _T("UPDATE config SET default_value='0' WHERE var_name='EnableEventStormDetection'\n")
1190 _T("UPDATE config SET default_value='0' WHERE var_name='EnableISCListener'\n")
1191 _T("UPDATE config SET default_value='1' WHERE var_name='EnableNXSLContainerFunctions'\n")
1192 _T("UPDATE config SET default_value='0' WHERE var_name='EnableObjectTransactions'\n")
1193 _T("UPDATE config SET default_value='1' WHERE var_name='EnableSNMPTraps'\n")
1194 _T("UPDATE config SET default_value='0' WHERE var_name='EnableAlarmSummaryEmails'\n")
1195 _T("UPDATE config SET default_value='0' WHERE var_name='EnableSyslogReceiver'\n")
1196 _T("UPDATE config SET default_value='1' WHERE var_name='EnableTimedAlarmAck'\n")
1197 _T("UPDATE config SET default_value='0' WHERE var_name='EnableXMPPConnector'\n")
1198 _T("UPDATE config SET default_value='0' WHERE var_name='EnableZoning'\n")
1199 _T("UPDATE config SET default_value='0' WHERE var_name='EscapeLocalCommands'\n")
1200 _T("UPDATE config SET default_value='90' WHERE var_name='EventLogRetentionTime'\n")
1201 _T("UPDATE config SET default_value='15' WHERE var_name='EventStormDuration'\n")
1202 _T("UPDATE config SET default_value='100' WHERE var_name='EventStormEventsPerSecond'\n")
1203 _T("UPDATE config SET default_value='0' WHERE var_name='ExtendedLogQueryAccessControl'\n")
1204 _T("UPDATE config SET default_value='13' WHERE var_name='ExternalAuditFacility'\n")
1205 _T("UPDATE config SET default_value='514' WHERE var_name='ExternalAuditPort'\n")
1206 _T("UPDATE config SET default_value='none' WHERE var_name='ExternalAuditServer'\n")
1207 _T("UPDATE config SET default_value='5' WHERE var_name='ExternalAuditSeverity'\n")
1208 _T("UPDATE config SET default_value='netxmsd-audit' WHERE var_name='ExternalAuditTag'\n")
1209 _T("UPDATE config SET default_value='100' WHERE var_name='FirstFreeObjectId'\n")
1210 _T("UPDATE config SET default_value='0' WHERE var_name='FixedStatusValue'\n")
1211 _T("UPDATE config SET default_value='5' WHERE var_name='GraceLoginCount'\n")
1212 _T("UPDATE config SET default_value='none' WHERE var_name='HelpDeskLink'\n")
1213 _T("UPDATE config SET default_value='02:00' WHERE var_name='HousekeeperStartTime'\n")
1214 _T("UPDATE config SET default_value='46' WHERE var_name='IcmpPingSize'\n")
1215 _T("UPDATE config SET default_value='1500' WHERE var_name='IcmpPingTimeout'\n")
1216 _T("UPDATE config SET default_value='1' WHERE var_name='ImportConfigurationOnStartup'\n")
1217 _T("UPDATE config SET default_value='600' WHERE var_name='InstancePollingInterval'\n")
1218 _T("UPDATE config SET default_value='0' WHERE var_name='InternalCA'\n")
1219 _T("UPDATE config SET default_value='0' WHERE var_name='IntruderLockoutThreshold'\n")
1220 _T("UPDATE config SET default_value='30' WHERE var_name='IntruderLockoutTime'\n")
1221 _T("UPDATE config SET default_value='Task' WHERE var_name='JiraIssueType'\n")
1222 _T("UPDATE config SET default_value='netxms' WHERE var_name='JiraLogin'\n")
1223 _T("UPDATE config SET default_value='NETXMS' WHERE var_name='JiraProjectCode'\n")
1224 _T("UPDATE config SET default_value='http://localhost' WHERE var_name='JiraServerURL'\n")
1225 _T("UPDATE config SET default_value='90' WHERE var_name='JobHistoryRetentionTime'\n")
1226 _T("UPDATE config SET default_value='5' WHERE var_name='JobRetryCount'\n")
1227 _T("UPDATE config SET default_value='60' WHERE var_name='KeepAliveInterval'\n")
1228 _T("UPDATE config SET default_value='ldap://localhost:389' WHERE var_name='LdapConnectionString'\n")
1229 _T("UPDATE config SET default_value='displayName' WHERE var_name='LdapMappingFullName'\n")
1230 _T("UPDATE config SET default_value='1000' WHERE var_name='LdapPageSize'\n")
1231 _T("UPDATE config SET default_value='0' WHERE var_name='LdapSyncInterval'\n")
1232 _T("UPDATE config SET default_value='1' WHERE var_name='LdapUserDeleteAction'\n")
1233 _T("UPDATE config SET default_value='60000' WHERE var_name='LockTimeout'\n")
1234 _T("UPDATE config SET default_value='0' WHERE var_name='LogAllSNMPTraps'\n")
1235 _T("UPDATE config SET default_value='utf8' WHERE var_name='MailEncoding'\n")
1236 _T("UPDATE config SET default_value='0' WHERE var_name='MinPasswordLength'\n")
1237 _T("UPDATE config SET default_value='1000' WHERE var_name='MinViewRefreshInterval'\n")
1238 _T("UPDATE config SET default_value='4747' WHERE var_name='MobileDeviceListenerPort'\n")
1239 _T("UPDATE config SET default_value='25' WHERE var_name='NumberOfDataCollectors'\n")
1240 _T("UPDATE config SET default_value='10' WHERE var_name='NumberOfUpgradeThreads'\n")
1241 _T("UPDATE config SET default_value='86400' WHERE var_name='OfflineDataRelevanceTime'\n")
1242 _T("UPDATE config SET default_value='0' WHERE var_name='PasswordComplexity'\n")
1243 _T("UPDATE config SET default_value='0' WHERE var_name='PasswordExpiration'\n")
1244 _T("UPDATE config SET default_value='0' WHERE var_name='PasswordHistoryLength'\n")
1245 _T("UPDATE config SET default_value='1' WHERE var_name='PollCountForStatusChange'\n")
1246 _T("UPDATE config SET default_value='10' WHERE var_name='PollerThreadPoolBaseSize'\n")
1247 _T("UPDATE config SET default_value='250' WHERE var_name='PollerThreadPoolMaxSize'\n")
1248 _T("UPDATE config SET default_value='PAP' WHERE var_name='RADIUSAuthMethod'\n")
1249 _T("UPDATE config SET default_value='5' WHERE var_name='RADIUSNumRetries'\n")
1250 _T("UPDATE config SET default_value='1645' WHERE var_name='RADIUSPort'\n")
1251 _T("UPDATE config SET default_value='1645' WHERE var_name='RADIUSSecondaryPort'\n")
1252 _T("UPDATE config SET default_value='netxms' WHERE var_name='RADIUSSecondarySecret'\n")
1253 _T("UPDATE config SET default_value='none' WHERE var_name='RADIUSSecondaryServer'\n")
1254 _T("UPDATE config SET default_value='netxms' WHERE var_name='RADIUSSecret'\n")
1255 _T("UPDATE config SET default_value='none' WHERE var_name='RADIUSServer'\n")
1256 _T("UPDATE config SET default_value='3' WHERE var_name='RADIUSTimeout'\n")
1257 _T("UPDATE config SET default_value='0' WHERE var_name='ReceiveForwardedEvents'\n")
1258 _T("UPDATE config SET default_value='localhost' WHERE var_name='ReportingServerHostname'\n")
1259 _T("UPDATE config SET default_value='4710' WHERE var_name='ReportingServerPort'\n")
1260 _T("UPDATE config SET default_value='0' WHERE var_name='ResolveDNSToIPOnStatusPoll'\n")
1261 _T("UPDATE config SET default_value='1' WHERE var_name='ResolveNodeNames'\n")
1262 _T("UPDATE config SET default_value='300' WHERE var_name='RoutingTableUpdateInterval'\n")
1263 _T("UPDATE config SET default_value='0' WHERE var_name='RunNetworkDiscovery'\n")
1264 _T("UPDATE config SET default_value='60' WHERE var_name='ServerCommandOutputTimeout'\n")
1265 _T("UPDATE config SET default_value='<none>' WHERE var_name='SMSDriver'\n")
1266 _T("UPDATE config SET default_value='161' WHERE var_name='SNMPPorts'\n")
1267 _T("UPDATE config SET default_value='1500' WHERE var_name='SNMPRequestTimeout'\n")
1268 _T("UPDATE config SET default_value='90' WHERE var_name='SNMPTrapLogRetentionTime'\n")
1269 _T("UPDATE config SET default_value='162' WHERE var_name='SNMPTrapPort'\n")
1270 _T("UPDATE config SET default_value='netxms@localhost' WHERE var_name='SMTPFromAddr'\n")
1271 _T("UPDATE config SET default_value='NetXMS Server' WHERE var_name='SMTPFromName'\n")
1272 _T("UPDATE config SET default_value='25' WHERE var_name='SMTPPort'\n")
1273 _T("UPDATE config SET default_value='1' WHERE var_name='SMTPRetryCount'\n")
1274 _T("UPDATE config SET default_value='localhost' WHERE var_name='SMTPServer'\n")
1275 _T("UPDATE config SET default_value='1' WHERE var_name='StatusCalculationAlgorithm'\n")
1276 _T("UPDATE config SET default_value='60' WHERE var_name='StatusPollingInterval'\n")
1277 _T("UPDATE config SET default_value='1' WHERE var_name='StatusPropagationAlgorithm'\n")
1278 _T("UPDATE config SET default_value='0' WHERE var_name='StatusShift'\n")
1279 _T("UPDATE config SET default_value='75' WHERE var_name='StatusSingleThreshold'\n")
1280 _T("UPDATE config SET default_value='503C2814' WHERE var_name='StatusThresholds'\n")
1281 _T("UPDATE config SET default_value='01020304' WHERE var_name='StatusTranslation'\n")
1282 _T("UPDATE config SET default_value='0' WHERE var_name='StrictAlarmStatusFlow'\n")
1283 _T("UPDATE config SET default_value='60' WHERE var_name='SyncInterval'\n")
1284 _T("UPDATE config SET default_value='0' WHERE var_name='SyncNodeNamesWithDNS'\n")
1285 _T("UPDATE config SET default_value='0' WHERE var_name='SyslogIgnoreMessageTimestamp'\n")
1286 _T("UPDATE config SET default_value='514' WHERE var_name='SyslogListenPort'\n")
1287 _T("UPDATE config SET default_value='0' WHERE var_name='SyslogNodeMatchingPolicy'\n")
1288 _T("UPDATE config SET default_value='90' WHERE var_name='SyslogRetentionTime'\n")
1289 _T("UPDATE config SET default_value='0' WHERE var_name='ThresholdRepeatInterval'\n")
1290 _T("UPDATE config SET default_value='http://tile.openstreetmap.org/' WHERE var_name='TileServerURL'\n")
1291 _T("UPDATE config SET default_value='3' WHERE var_name='TopologyDiscoveryRadius'\n")
1292 _T("UPDATE config SET default_value='900' WHERE var_name='TopologyExpirationTime'\n")
1293 _T("UPDATE config SET default_value='1800' WHERE var_name='TopologyPollingInterval'\n")
1294 _T("UPDATE config SET default_value='0' WHERE var_name='TrapSourcesInAllZones'\n")
1295 _T("UPDATE config SET default_value='0' WHERE var_name='UseDNSNameForDiscoveredNodes'\n")
1296 _T("UPDATE config SET default_value='1' WHERE var_name='UseFQDNForNodeNames'\n")
1297 _T("UPDATE config SET default_value='1' WHERE var_name='UseIfXTable'\n")
1298 _T("UPDATE config SET default_value='0' WHERE var_name='UseInterfaceAliases'\n")
1299 _T("UPDATE config SET default_value='0' WHERE var_name='UseSNMPTrapsForDiscovery'\n")
1300 _T("UPDATE config SET default_value='0' WHERE var_name='UseSyslogForDiscovery'\n")
1301 _T("UPDATE config SET default_value='netxms@localhost' WHERE var_name='XMPPLogin'\n")
1302 _T("UPDATE config SET default_value='netxms' WHERE var_name='XMPPPassword'\n")
1303 _T("UPDATE config SET default_value='5222' WHERE var_name='XMPPPort'\n")
1304 _T("UPDATE config SET default_value='localhost' WHERE var_name='XMPPServer'\n")
1305 _T("<END>");
1306 CHK_EXEC(SQLBatch(batch));
1307
1308 CHK_EXEC(SetSchemaVersion(454));
1309 return TRUE;
1310}
1311
1312/**
3c37ab80
VK
1313 * Upgrade from V452 to V453
1314 */
1315static BOOL H_UpgradeFromV452(int currVersion, int newVersion)
1316{
1317 static const TCHAR *batch =
1318 _T("ALTER TABLE audit_log ADD value_diff $SQL:TEXT\n")
1319 _T("<END>");
1320 CHK_EXEC(SQLBatch(batch));
1321 CHK_EXEC(SetSchemaVersion(453));
1322 return TRUE;
1323}
1324
1325/**
dbb49f94
VK
1326 * Upgrade from V451 to V452
1327 */
1328static BOOL H_UpgradeFromV451(int currVersion, int newVersion)
1329{
1330 static const TCHAR *batch =
1331 _T("ALTER TABLE audit_log ADD old_value $SQL:TEXT\n")
1332 _T("ALTER TABLE audit_log ADD new_value $SQL:TEXT\n")
1333 _T("<END>");
1334 CHK_EXEC(SQLBatch(batch));
1335 CHK_EXEC(SetSchemaVersion(452));
1336 return TRUE;
1337}
1338
1339/**
542627ea
VK
1340 * Upgrade from V450 to V451
1341 */
1342static BOOL H_UpgradeFromV450(int currVersion, int newVersion)
1343{
1344 CHK_EXEC(CreateTable(
1345 _T("CREATE TABLE object_access_snapshot (")
1346 _T(" user_id integer not null,")
1347 _T(" object_id integer not null,")
1348 _T(" access_rights integer not null,")
1349 _T("PRIMARY KEY(user_id,object_id))")));
1350
1351 CHK_EXEC(SetSchemaVersion(451));
1352 return TRUE;
1353}
1354
1355/**
4ca9d9c0
VK
1356 * Upgrade from V449 to V450
1357 */
1358static BOOL H_UpgradeFromV449(int currVersion, int newVersion)
1359{
1360 static const TCHAR *batch =
1361 _T("ALTER TABLE dct_thresholds ADD sample_count integer\n")
1362 _T("UPDATE dct_thresholds SET sample_count=1\n")
1363 _T("<END>");
1364 CHK_EXEC(SQLBatch(batch));
797a2b25 1365 DBSetNotNullConstraint(g_hCoreDB, _T("dct_thresholds"), _T("sample_count"));
4ca9d9c0
VK
1366
1367 CHK_EXEC(CreateTable(
1368 _T("CREATE TABLE dct_threshold_instances (")
1369 _T(" threshold_id integer not null,")
8aaa2784 1370 _T(" instance varchar(255) not null,")
4ca9d9c0
VK
1371 _T(" match_count integer not null,")
1372 _T(" is_active char(1) not null,")
1373 _T("PRIMARY KEY(threshold_id,instance))")));
1374
1375 CHK_EXEC(SetSchemaVersion(450));
1376 return TRUE;
1377}
1378
1379/**
0d2c73ec
VK
1380 * Upgrade from V448 to V449
1381 */
1382static BOOL H_UpgradeFromV448(int currVersion, int newVersion)
1383{
1384 CHK_EXEC(CreateConfigParam(_T("SMTPPort"), _T("25"), _T("Port used by SMTP server"), 'I', true, false, false, false));
1385 CHK_EXEC(SetSchemaVersion(449));
1386 return TRUE;
1387}
1388
1389/**
b723bbb3
VK
1390 * Upgrade from V447 to V448
1391 */
1392static BOOL H_UpgradeFromV447(int currVersion, int newVersion)
1393{
1394 CHK_EXEC(SQLQuery(_T("ALTER TABLE nodes ADD lldp_id varchar(63)")));
1395 CHK_EXEC(SetSchemaVersion(448));
1396 return TRUE;
1397}
1398
1399/**
fa9c1a51
VK
1400 * Upgrade from V446 to V447
1401 */
1402static BOOL H_UpgradeFromV446(int currVersion, int newVersion)
1403{
1404 CHK_EXEC(CreateTable(
1405 _T("CREATE TABLE port_layouts (")
1406 _T(" device_oid varchar(255) not null,")
1407 _T(" numbering_scheme char(1) not null,")
1408 _T(" row_count char(1) not null,")
1409 _T(" layout_data varchar(4000) null,")
1410 _T("PRIMARY KEY(device_oid))")));
1411
1412 CHK_EXEC(SetSchemaVersion(447));
1413 return TRUE;
1414}
1415
1416/**
3e883888
EJ
1417 * Upgrade from V445 to V446
1418 */
1419static BOOL H_UpgradeFromV445(int currVersion, int newVersion)
1420{
1421 CHK_EXEC(CreateTable(
1422 _T("CREATE TABLE network_map_seed_nodes (")
1423 _T(" map_id integer not null,")
1424 _T(" seed_node_id integer not null,")
1425 _T("PRIMARY KEY(map_id,seed_node_id))")));
1426
1427 DB_RESULT hResult = DBSelect(g_hCoreDB, _T("SELECT id,seed FROM network_maps"));
1428 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("INSERT INTO network_map_seed_nodes (map_id,seed_node_id) VALUES (?,?)"));
1429 if (hResult != NULL)
1430 {
1431 if (hStmt != NULL)
1432 {
1433 int nRows = DBGetNumRows(hResult);
1434 for(int i = 0; i < nRows; i++)
1435 {
1436 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 0));
1437 DBBind(hStmt, 2, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 1));
1438
1439 if (!SQLExecute(hStmt))
1440 {
1441 if (!g_bIgnoreErrors)
1442 {
1443 DBFreeStatement(hStmt);
1444 DBFreeResult(hResult);
1445 return FALSE;
1446 }
1447 }
1448 }
1449
16684f16 1450 CHK_EXEC(DBDropColumn(g_hCoreDB, _T("network_maps"), _T("seed")));
3e883888
EJ
1451 DBFreeStatement(hStmt);
1452 }
1453 DBFreeResult(hResult);
1454 }
1455
3e883888
EJ
1456 CHK_EXEC(SetSchemaVersion(446));
1457 return TRUE;
1458}
1459
1460/**
c48843a5
VK
1461 * Upgrade from V444 to V445
1462 */
1463static BOOL H_UpgradeFromV444(int currVersion, int newVersion)
1464{
1465 CHK_EXEC(SQLQuery(_T("ALTER TABLE nodes ADD tunnel_id varchar(36) null")));
1466 CHK_EXEC(SetSchemaVersion(445));
1467 return TRUE;
1468}
1469
1470/**
80d9447b 1471 * Upgrade from V443 to V444
1472 */
1473static BOOL H_UpgradeFromV443(int currVersion, int newVersion)
1474{
d888bc1c 1475 CHK_EXEC(CreateConfigParam(_T("GraceLoginCount"), _T("5"), _T("User's grace login count"), 'I', true, false, false, false));
80d9447b 1476 CHK_EXEC(SetSchemaVersion(444));
1477 return TRUE;
1478}
1479
1480/**
e9c75749
EJ
1481 * Upgrade from V442 to V443
1482 */
1483static BOOL H_UpgradeFromV442(int currVersion, int newVersion)
1484{
1485 static const TCHAR *batch =
1486 _T("ALTER TABLE dc_tables ADD instance varchar(255) null\n")
1487 _T("ALTER TABLE dc_tables ADD instd_method integer null\n")
1488 _T("UPDATE dc_tables SET instd_method=0\n")
1489 _T("ALTER TABLE dc_tables ADD instd_data varchar(255) null\n")
1490 _T("ALTER TABLE dc_tables ADD instd_filter $SQL:TEXT null\n")
1491 _T("<END>");
1492 CHK_EXEC(SQLBatch(batch));
797a2b25 1493 DBSetNotNullConstraint(g_hCoreDB, _T("dc_tables"), _T("instd_method"));
e9c75749
EJ
1494 CHK_EXEC(SetSchemaVersion(443));
1495 return TRUE;
1496}
1497
de1be1b5 1498/**
d1c4701c
VK
1499 * Upgrade from V441 to V442
1500 */
1501static BOOL H_UpgradeFromV441(int currVersion, int newVersion)
1502{
1503 CHK_EXEC(CreateTable(
1504 _T("CREATE TABLE object_urls (")
1505 _T(" object_id integer not null,")
1506 _T(" url_id integer not null,")
1507 _T(" url varchar(2000) null,")
1508 _T(" description varchar(2000) null,")
1509 _T(" PRIMARY KEY(object_id,url_id))")));
1510 CHK_EXEC(SetSchemaVersion(442));
1511 return TRUE;
1512}
1513
1514/**
c8ad9b5b
VK
1515 * Upgrade from V440 to V441
1516 */
1517static BOOL H_UpgradeFromV440(int currVersion, int newVersion)
1518{
1519 CHK_EXEC(CreateConfigParam(_T("TopologyPollingInterval"), _T("1800"), _T("Interval in seconds between topology polls"), 'I', true, true, false, false));
1520 CHK_EXEC(SetSchemaVersion(441));
1521 return TRUE;
1522}
1523
1524/**
c29cf4bf
VK
1525 * Upgrade from V439 to V440
1526 */
1527static BOOL H_UpgradeFromV439(int currVersion, int newVersion)
1528{
1529 static const TCHAR *batch =
1530 _T("UPDATE config SET description='Enable/disable automatic deletion of subnet objects without any nodes within.' WHERE var_name='DeleteEmptySubnets'\n")
1531 _T("UPDATE config SET description='Instance polling interval (in seconds).' WHERE var_name='InstancePollingInterval'\n")
1532 _T("<END>");
1533 CHK_EXEC(SQLBatch(batch));
1534 CHK_EXEC(SetSchemaVersion(440));
1535 return TRUE;
1536}
1537
1538/**
776d2ca4
EJ
1539 * Upgrade from V438 to V439
1540 */
1541static BOOL H_UpgradeFromV438(int currVersion, int newVersion)
1542{
1543 static const TCHAR *batch =
1544 _T("UPDATE config SET data_type='S' WHERE var_name='LdapUserUniqueId'\n")
c29cf4bf 1545 _T("UPDATE config SET data_type='S' WHERE var_name='LdapGroupUniqueId'\n")
776d2ca4
EJ
1546 _T("<END>");
1547 CHK_EXEC(SQLBatch(batch));
1548 CHK_EXEC(SetSchemaVersion(439));
1549 return TRUE;
1550}
1551
1552/**
0207b7dd
EJ
1553 * Upgrade from V437 to V438
1554 */
1555static BOOL H_UpgradeFromV437(int currVersion, int newVersion)
1556{
1557 static const TCHAR *batch =
1558 _T("ALTER TABLE snmp_trap_cfg ADD guid varchar(36)\n")
1559 _T("UPDATE snmp_trap_cfg SET guid='5d01e7e5-edbb-46ce-b53c-f7f64d1bf8ff' WHERE trap_id=1\n")
1560 _T("UPDATE snmp_trap_cfg SET guid='c5464919-fd76-4624-9c21-b6ab73d9df80' WHERE trap_id=2\n")
1561 _T("UPDATE snmp_trap_cfg SET guid='44d3b32e-33c5-4a39-b2ad-990a1120155d' WHERE trap_id=3\n")
1562 _T("UPDATE snmp_trap_cfg SET guid='c9660f48-a4b3-41c8-b3f9-e9a6a8129db5' WHERE trap_id=4\n")
1563 _T("UPDATE snmp_trap_cfg SET guid='4b422ba6-4b45-4881-931a-ed38dc798f9f' WHERE trap_id=5\n")
1564 _T("UPDATE snmp_trap_cfg SET guid='bd8b6971-a3e4-4cad-9c70-3a33e61e0913' WHERE trap_id=6\n")
1565 _T("ALTER TABLE script_library ADD guid varchar(36)\n")
1566 _T("UPDATE script_library SET guid='3b7bddce-3505-42ff-ac60-6a48a64bd0ae' WHERE script_id=1\n")
1567 _T("UPDATE script_library SET guid='2fb9212b-97e6-40e7-b434-2df4f7e8f6aa' WHERE script_id=2\n")
1568 _T("UPDATE script_library SET guid='38696a00-c519-438c-8cbd-4b3a0cba4af1' WHERE script_id=3\n")
1569 _T("UPDATE script_library SET guid='efe50915-47b2-43d8-b4f4-2c09a44970c3' WHERE script_id=4\n")
1570 _T("UPDATE script_library SET guid='7837580c-4054-40f2-981f-7185797fe7d7' WHERE script_id=11\n")
1571 _T("UPDATE script_library SET guid='f7d1bc7e-4046-4ee4-adb2-718f7361984d' WHERE script_id=12\n")
1572 _T("UPDATE script_library SET guid='048fcf32-765b-4702-9c70-f012f62d5a90' WHERE script_id=13\n")
1573 _T("UPDATE script_library SET guid='d515c10f-a5c9-4f41-afcd-9ddc8845f288' WHERE script_id=14\n")
1574 _T("UPDATE script_library SET guid='7cd1c471-2f14-4fae-8743-8899fed64d18' WHERE script_id=15\n")
1575 _T("UPDATE script_library SET guid='befdb083-ac68-481d-a7b7-127e11c3fae0' WHERE script_id=16\n")
1576 _T("<END>");
1577 CHK_EXEC(SQLBatch(batch));
1578
0207b7dd 1579 DB_RESULT hResult = DBSelect(g_hCoreDB, _T("SELECT trap_id FROM snmp_trap_cfg WHERE guid IS NULL"));
0207b7dd
EJ
1580 if (hResult != NULL)
1581 {
49b0df1a 1582 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("UPDATE snmp_trap_cfg SET guid=? WHERE trap_id=?"));
0207b7dd
EJ
1583 if (hStmt != NULL)
1584 {
48f34e00 1585 int numRows = DBGetNumRows(hResult);
0207b7dd
EJ
1586 for(int i = 0; i < numRows; i++)
1587 {
49b0df1a 1588 uuid guid = uuid::generate();
0207b7dd
EJ
1589 DBBind(hStmt, 1, DB_SQLTYPE_VARCHAR, guid);
1590 DBBind(hStmt, 2, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 0));
1591
1592 if (!SQLExecute(hStmt))
1593 {
1594 if (!g_bIgnoreErrors)
1595 {
1596 DBFreeStatement(hStmt);
1597 DBFreeResult(hResult);
1598 return FALSE;
1599 }
1600 }
1601 }
1602 DBFreeStatement(hStmt);
1603 }
1604 DBFreeResult(hResult);
1605 }
1606
1607 hResult = DBSelect(g_hCoreDB, _T("SELECT guid,script_id FROM script_library WHERE guid IS NULL"));
0207b7dd
EJ
1608 if (hResult != NULL)
1609 {
49b0df1a 1610 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("UPDATE script_library SET guid=? WHERE script_id=?"));
0207b7dd
EJ
1611 if (hStmt != NULL)
1612 {
48f34e00 1613 int numRows = DBGetNumRows(hResult);
0207b7dd
EJ
1614 for(int i = 0; i < numRows; i++)
1615 {
49b0df1a 1616 uuid guid = uuid::generate();
0207b7dd
EJ
1617 DBBind(hStmt, 1, DB_SQLTYPE_VARCHAR, guid);
1618 DBBind(hStmt, 2, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 1));
1619 if (!SQLExecute(hStmt))
1620 {
1621 if (!g_bIgnoreErrors)
1622 {
1623 DBFreeStatement(hStmt);
1624 DBFreeResult(hResult);
1625 return FALSE;
1626 }
1627 }
1628 }
1629 DBFreeStatement(hStmt);
1630 }
1631 DBFreeResult(hResult);
1632 }
1633
797a2b25
VK
1634 CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("snmp_trap_cfg"), _T("guid")));
1635 CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("script_library"), _T("guid")));
0207b7dd
EJ
1636 CHK_EXEC(SetSchemaVersion(438));
1637 return TRUE;
1638}
1639
1640/**
f4b2ebd3
VK
1641 * Upgrade from V436 to V437
1642 */
1643static BOOL H_UpgradeFromV436(int currVersion, int newVersion)
1644{
1645 CHK_EXEC(
1646 CreateEventTemplate(EVENT_ROUTING_LOOP_DETECTED, _T("SYS_ROUTING_LOOP_DETECTED"),
1647 SEVERITY_MAJOR, EF_LOG, _T("98276f42-dc85-41a5-b449-6ba83d1a71b7"),
1648 _T("Routing loop detected for destination %3 (selected route %6/%7 via %9)"),
1649 _T("Generated when server detects routing loop during network path trace.\r\n")
1650 _T("Source of the event is node which routes packet back to already passed hop.\r\n")
1651 _T("Parameters:\r\n")
1652 _T(" 1) Protocol (IPv4 or IPv6)\r\n")
1653 _T(" 2) Path trace destination node ID\r\n")
1654 _T(" 3) Path trace destination address\r\n")
1655 _T(" 4) Path trace source node ID\r\n")
1656 _T(" 5) Path trace source node address\r\n")
1657 _T(" 6) Routing prefix (subnet address)\r\n")
1658 _T(" 7) Routing prefix length (subnet mask length)\r\n")
1659 _T(" 8) Next hop node ID\r\n")
1660 _T(" 9) Next hop address"))
1661 );
1662 CHK_EXEC(SetSchemaVersion(437));
1663 return TRUE;
1664}
1665
1666/**
55d99dce
VK
1667 * Upgrade from V435 to V436
1668 */
1669static BOOL H_UpgradeFromV435(int currVersion, int newVersion)
1670{
1671 static const TCHAR *batch =
1672 _T("ALTER TABLE nodes ADD agent_comp_mode char(1)\n")
1673 _T("UPDATE nodes SET agent_comp_mode='0'\n")
1674 _T("<END>");
1675 CHK_EXEC(SQLBatch(batch));
797a2b25 1676 CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("nodes"), _T("agent_comp_mode")));
55d99dce
VK
1677 CHK_EXEC(SetSchemaVersion(436));
1678 return TRUE;
1679}
1680
1681/**
9674aefa
VK
1682 * Upgrade from V434 to V435
1683 */
1684static BOOL H_UpgradeFromV434(int currVersion, int newVersion)
1685{
1686 CHK_EXEC(CreateConfigParam(_T("DefaultAgentProtocolCompressionMode"), _T("1"), _T("Default agent protocol compression mode"), 'C', true, false, false, false));
1687 static const TCHAR *batch =
1688 _T("UPDATE config SET data_type='C',description='Default agent cache mode' WHERE var_name='DefaultAgentCacheMode'\n")
1689 _T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultAgentCacheMode','1','On')\n")
1690 _T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultAgentCacheMode','2','Off')\n")
1691 _T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultAgentProtocolCompressionMode','1','Enabled')\n")
1692 _T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultAgentProtocolCompressionMode','2','Disabled')\n")
1693 _T("<END>");
1694 CHK_EXEC(SQLBatch(batch));
1695 CHK_EXEC(SetSchemaVersion(435));
1696 return TRUE;
1697}
1698
1699/**
de1be1b5
VK
1700 * Upgrade from V433 to V434
1701 */
1702static BOOL H_UpgradeFromV433(int currVersion, int newVersion)
1703{
1704 CHK_EXEC(
1705 CreateEventTemplate(EVENT_IF_EXPECTED_STATE_UP, _T("SYS_IF_EXPECTED_STATE_UP"),
1706 SEVERITY_NORMAL, EF_LOG, _T("4997c3f5-b332-4077-8e99-983142f0e193"),
1707 _T("Expected state for interface \"%2\" set to UP"),
1708 _T("Generated when interface expected state set to UP.\r\n")
1709 _T("Please note that source of event is node, not an interface itself.\r\n")
1710 _T("Parameters:\r\n")
f4b2ebd3
VK
1711 _T(" 1) Interface index\r\n")
1712 _T(" 2) Interface name"))
de1be1b5
VK
1713 );
1714
1715 CHK_EXEC(
1716 CreateEventTemplate(EVENT_IF_EXPECTED_STATE_DOWN, _T("SYS_IF_EXPECTED_STATE_DOWN"),
1717 SEVERITY_NORMAL, EF_LOG, _T("75de536c-4861-4f19-ba56-c43d814431d7"),
1718 _T("Expected state for interface \"%2\" set to DOWN"),
1719 _T("Generated when interface expected state set to DOWN.\r\n")
1720 _T("Please note that source of event is node, not an interface itself.\r\n")
1721 _T("Parameters:\r\n")
f4b2ebd3
VK
1722 _T(" 1) Interface index\r\n")
1723 _T(" 2) Interface name"))
de1be1b5
VK
1724 );
1725
1726 CHK_EXEC(
1727 CreateEventTemplate(EVENT_IF_EXPECTED_STATE_IGNORE, _T("SYS_IF_EXPECTED_STATE_IGNORE"),
1728 SEVERITY_NORMAL, EF_LOG, _T("0e488c0e-3340-4e02-ad96-b999b8392e55"),
1729 _T("Expected state for interface \"%2\" set to IGNORE"),
1730 _T("Generated when interface expected state set to IGNORE.\r\n")
1731 _T("Please note that source of event is node, not an interface itself.\r\n")
1732 _T("Parameters:\r\n")
f4b2ebd3
VK
1733 _T(" 1) Interface index\r\n")
1734 _T(" 2) Interface name"))
de1be1b5
VK
1735 );
1736
1737 CHK_EXEC(AddEventToEPPRule(_T("6f46d451-ee66-4563-8747-d129877df24d"), EVENT_IF_EXPECTED_STATE_DOWN));
1738 CHK_EXEC(AddEventToEPPRule(_T("6f46d451-ee66-4563-8747-d129877df24d"), EVENT_IF_EXPECTED_STATE_IGNORE));
1739 CHK_EXEC(AddEventToEPPRule(_T("ecc3fb57-672d-489d-a0ef-4214ea896e0f"), EVENT_IF_EXPECTED_STATE_UP));
1740 CHK_EXEC(AddEventToEPPRule(_T("ecc3fb57-672d-489d-a0ef-4214ea896e0f"), EVENT_IF_EXPECTED_STATE_IGNORE));
1741
1742 CHK_EXEC(SetSchemaVersion(434));
1743 return TRUE;
1744}
1745
1746/**
727b90ff
VK
1747 * Upgrade from V432 to V433
1748 */
1749static BOOL H_UpgradeFromV432(int currVersion, int newVersion)
1750{
1751 CHK_EXEC(CreateConfigParam(_T("UseSyslogForDiscovery"), _T("0"), _T("Use syslog messages for new node discovery."), 'B', true, false, false, false));
1752 CHK_EXEC(SetSchemaVersion(433));
1753 return TRUE;
1754}
1755
de1be1b5 1756/**
3c76ed34
VK
1757 * Upgrade from V431 to V432
1758 */
1759static BOOL H_UpgradeFromV431(int currVersion, int newVersion)
95111e00 1760{
3c76ed34
VK
1761 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_syslog_source ON syslog(source_object_id)")));
1762 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_snmp_trap_log_oid ON snmp_trap_log(object_id)")));
1763 CHK_EXEC(SetSchemaVersion(432));
1764 return TRUE;
1765}
1766
de1be1b5 1767/**
3c4dc19b
EJ
1768 * Upgrade from V430 to V431
1769 */
1770static BOOL H_UpgradeFromV430(int currVersion, int newVersion)
95111e00 1771{
3c76ed34
VK
1772 CHK_EXEC(SQLQuery(_T("DELETE FROM config_values WHERE var_name='SNMPPorts'")));
1773 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'")));
1774 CHK_EXEC(SetSchemaVersion(431));
3c4dc19b
EJ
1775 return TRUE;
1776}
00420032 1777
de1be1b5
VK
1778/**
1779 * Upgrade from V429 to V430
00420032 1780 */
1781static BOOL H_UpgradeFromV429(int currVersion, int newVersion)
1782{
1783 CHK_EXEC(CreateTable(
1784 _T("CREATE TABLE policy_pstorage_actions (")
1785 _T("rule_id integer not null,")
1786 _T("ps_key varchar(255) not null,")
1787 _T("value varchar(2000) null,")
1788 _T("action integer not null,")
1789 _T("PRIMARY KEY(rule_id,ps_key,action))")));
1790
1791 CHK_EXEC(CreateTable(
1792 _T("CREATE TABLE persistent_storage (")
03f3c823 1793 _T("entry_key varchar(255) not null,")
00420032 1794 _T("value varchar(2000) null,")
1795 _T("PRIMARY KEY(entry_key))")));
1796
00420032 1797 //Move previous attrs form situations to pstorage
1798 DB_RESULT hResult = SQLSelect(_T("SELECT event_policy.rule_id,situations.name,event_policy.situation_instance,")
1799 _T("policy_situation_attr_list.attr_name,policy_situation_attr_list.attr_value ")
1800 _T("FROM event_policy,situations,policy_situation_attr_list ")
1801 _T("WHERE event_policy.rule_id=policy_situation_attr_list.rule_id ")
1802 _T("AND situations.id=policy_situation_attr_list.situation_id"));
1803 if (hResult != NULL)
1804 {
1805 int count = DBGetNumRows(hResult);
1806 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("INSERT INTO policy_pstorage_actions (rule_id,ps_key,value,action) VALUES (?,?,?,1)"));
1807 if (hStmt != NULL)
1808 {
76d77587 1809 String key;
00420032 1810 for(int i = 0; i < count; i++)
1811 {
00420032 1812 TCHAR tmp[256];
1813 DBGetField(hResult, i, 1, tmp, 256);
2bf8ce90 1814 key.append(tmp);
00420032 1815 DBGetField(hResult, i, 2, tmp, 256);
2bf8ce90 1816 key.append(_T("."));
1817 key.append(tmp);
00420032 1818 DBGetField(hResult, i, 3, tmp, 256);
2bf8ce90 1819 key.append(_T("."));
1820 key.append(tmp);
00420032 1821 DBGetField(hResult, i, 4, tmp, 256);
1822
1823 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, DBGetFieldLong(hResult, i, 0));
2bf8ce90 1824 DBBind(hStmt, 2, DB_SQLTYPE_TEXT, key, DB_BIND_STATIC, 512);
00420032 1825 DBBind(hStmt, 3, DB_SQLTYPE_TEXT, tmp, DB_BIND_STATIC);
1826 if (!SQLExecute(hStmt))
1827 {
1828 if (!g_bIgnoreErrors)
1829 {
1830 DBFreeStatement(hStmt);
1831 DBFreeResult(hResult);
1832 return FALSE;
1833 }
1834 }
76d77587 1835 key.clear();
00420032 1836 }
1837 DBFreeStatement(hStmt);
1838 }
1839 else if (!g_bIgnoreErrors)
1840 {
1841 DBFreeStatement(hStmt);
1842 DBFreeResult(hResult);
1843 return FALSE;
1844 }
1845 DBFreeResult(hResult);
1846 }
1847 else
1848 {
1849 if (!g_bIgnoreErrors)
1850 return false;
1851 }
1852
1853 CHK_EXEC(SQLQuery(_T("DROP TABLE situations")));
1854 CHK_EXEC(SQLQuery(_T("DROP TABLE policy_situation_attr_list")));
16684f16
VK
1855 CHK_EXEC(DBDropColumn(g_hCoreDB, _T("event_policy"), _T("situation_id")));
1856 CHK_EXEC(DBDropColumn(g_hCoreDB, _T("event_policy"), _T("situation_instance")));
00420032 1857 CHK_EXEC(SetSchemaVersion(430));
1858 return TRUE;
1859}
1860
e4926628 1861/**
e11eade2
EJ
1862 * Upgrade from V428 to V429
1863 */
1864static BOOL H_UpgradeFromV428(int currVersion, int newVersion)
1865{
74724c20 1866 CHK_EXEC(DBResizeColumn(g_hCoreDB, _T("config"), _T("description"), 450, true));
e11eade2
EJ
1867 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Interval in seconds between active network discovery polls.' WHERE var_name='ActiveDiscoveryInterval'")));
1868 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'")));
1869 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'")));
1870 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'")));
1871 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'")));
1872 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'")));
1873 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'")));
1874 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'")));
1875 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'")));
1876 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'")));
1877 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'")));
1878 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='AllowTrapVarbindsConversion'")));
1879 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='AnonymousFileAccess'")));
1880 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'")));
1881 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'")));
1882 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'")));
1883 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Interval in milliseconds between beacon hosts polls.' WHERE var_name='BeaconPollingInterval'")));
1884 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Timeout in milliseconds to consider beacon host unreachable.' WHERE var_name='BeaconTimeout'")));
1885 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='BlockInactiveUserAccounts'")));
1886 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='CapabilityExpirationTime'")));
1887 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable case insensitive login names' WHERE var_name='CaseInsensitiveLoginNames'")));
1888 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable trusted nodes check' WHERE var_name='CheckTrustedNodes'")));
1889 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'")));
1890 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable container auto binding for clusters.' WHERE var_name='ClusterContainerAutoBind'")));
1891 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable template auto apply for clusters.' WHERE var_name='ClusterTemplateAutoApply'")));
1892 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'")));
1893 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Interval in seconds between configuration polls.' WHERE var_name='ConfigurationPollingInterval'")));
1894 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable data interpolation in dashboard data export.' WHERE var_name='DashboardDataExportEnableInterpolation'")));
1895 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'")));
1896 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='DBConnectionPoolCooldownTime'")));
1897 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='DBConnectionPoolMaxLifetime'")));
1898 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='A maximum number of connections in the connection pool.' WHERE var_name='DBConnectionPoolMaxSize'")));
1899 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='' WHERE var_name='DBLockInfo'")));
1900 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='DBLockPID'")));
1901 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='' WHERE var_name='DBLockStatus'")));
1902 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='DefaultAgentCacheMode'")));
f42d62e0
VK
1903 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Default date display format for GUI.' WHERE var_name='DefaultConsoleDateFormat'")));
1904 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Default short time display format for GUI.' WHERE var_name='DefaultConsoleShortTimeFormat'")));
1905 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Default long time display format for GUI.' WHERE var_name='DefaultConsoleTimeFormat'")));
e11eade2
EJ
1906 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Default polling interval for newly created DCI (in seconds).' WHERE var_name='DefaultDCIPollingInterval'")));
1907 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Default retention time for newly created DCI (in days).' WHERE var_name='DefaultDCIRetentionTime'")));
1908 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='C',description='Set the default encryption policy for communications with agents.' WHERE var_name='DefaultEncryptionPolicy'")));
1909 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='C',description='Default expected state for new interface objects.' WHERE var_name='DefaultInterfaceExpectedState'")));
1910 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='H',description='Default background color for new network map objects.' WHERE var_name='DefaultMapBackgroundColor'")));
1911 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Default mask for synthetic IPv4 subnets.' WHERE var_name='DefaultSubnetMaskIPv4'")));
1912 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Default mask for synthetic IPv6 subnets.' WHERE var_name='DefaultSubnetMaskIPv6'")));
1913 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'")));
1914 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'")));
1915 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'")));
1916 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'")));
1917 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='' WHERE var_name='DiscoveryFilter'")));
1918 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='DiscoveryFilterFlags'")));
1919 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Interval in seconds between passive network discovery polls.' WHERE var_name='DiscoveryPollingInterval'")));
1920 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='EnableAdminInterface'")));
1921 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable agent self-registration' WHERE var_name='EnableAgentRegistration'")));
1922 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable audit log.' WHERE var_name='EnableAuditLog'")));
1923 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='EnableCheckPointSNMP'")));
1924 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='EnableReportingServer'")));
1925 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='EnableEventStormDetection'")));
1926 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable Inter-Server Communications Listener.' WHERE var_name='EnableISCListener'")));
1927 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.'")));
1928 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='EnableObjectTransactions'")));
1929 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable SNMP trap processing.' WHERE var_name='EnableSNMPTraps'")));
1930 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable alarm summary e-mails.' WHERE var_name='EnableAlarmSummaryEmails'")));
1931 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable receiving of syslog messages.' WHERE var_name='EnableSyslogReceiver'")));
1932 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='EnableTimedAlarmAck'")));
1933 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'")));
1934 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable zoning support' WHERE var_name='EnableZoning'")));
1935 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='EscapeLocalCommands'")));
1936 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='The retention time of event logs' WHERE var_name='EventLogRetentionTime'")));
1937 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='EventStormDuration'")));
1938 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Event storm events per second' WHERE var_name='EventStormEventsPerSecond'")));
1939 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable extended access control in log queries.' WHERE var_name='ExtendedLogQueryAccessControl'")));
1940 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'")));
1941 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'")));
1942 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'")));
1943 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'")));
1944 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'")));
1945 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='FirstFreeObjectId'")));
1946 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='FixedStatusValue'")));
1947 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='' WHERE var_name='HelpDeskLink'")));
1948 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'")));
1949 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'")));
1950 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'")));
1951 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Import configuration from local files on server startup.' WHERE var_name='ImportConfigurationOnStartup'")));
1952 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Instance polling interval (in milliseconds).' WHERE var_name='InstancePollingInterval'")));
1953 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Enable/disable internal certificate authority.' WHERE var_name='InternalCA'")));
1954 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='IntruderLockoutThreshold'")));
1955 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='IntruderLockoutTime'")));
1956 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='' WHERE var_name='JiraIssueType'")));
1957 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Jira login name.' WHERE var_name='JiraLogin'")));
1958 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Jira password' WHERE var_name='JiraPassword'")));
1959 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Jira project code' WHERE var_name='JiraProjectCode'")));
1960 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='' WHERE var_name='JiraProjectComponent'")));
1961 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='The URL of the Jira server' WHERE var_name='JiraServerURL'")));
1962 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='JobHistoryRetentionTime'")));
1963 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Maximum mumber of job execution retrys.' WHERE var_name='JobRetryCount'")));
1964 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'")));
1965 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'")));
1966 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='LdapGroupUniqueId'")));
1967 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'")));
1968 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'")));
1969 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'")));
1970 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'")));
1971 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'")));
1972 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'")));
1973 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'")));
1974 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'")));
1975 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='User login for LDAP synchronization.' WHERE var_name='LdapSyncUser'")));
1976 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='User password for LDAP synchronization.' WHERE var_name='LdapSyncUserPassword'")));
1977 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'")));
1978 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'")));
1979 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='LdapUserUniqueId'")));
1980 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='LockTimeout'")));
1981 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Log all SNMP traps.' WHERE var_name='LogAllSNMPTraps'")));
1982 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Encoding for e-mails generated by NetXMS server.' WHERE var_name='MailEncoding'")));
1983 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'")));
1984 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'")));
1985 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='MinViewRefreshInterval'")));
1986 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='MobileDeviceListenerPort'")));
1987 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='The number of threads used for data collection.' WHERE var_name='NumberOfDataCollectors'")));
1988 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'")));
1989 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'")));
1990 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Set of flags to enforce password complexity.' WHERE var_name='PasswordComplexity'")));
1991 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'")));
1992 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'")));
1993 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'")));
1994 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='The base thread pool size.' WHERE var_name='PollerThreadPoolBaseSize'")));
1995 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Maximum thread pool size.' WHERE var_name='PollerThreadPoolMaxSize'")));
1996 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'")));
1997 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='The number of retries for RADIUS authentication.' WHERE var_name='RADIUSNumRetries'")));
1998 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Port number used for connection to primary RADIUS server.' WHERE var_name='RADIUSPort'")));
1999 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Port number used for connection to secondary RADIUS server.' WHERE var_name='RADIUSSecondaryPort'")));
2000 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Shared secret used for communication with secondary RADIUS server.' WHERE var_name='RADIUSSecondarySecret'")));
2001 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Host name or IP address of secondary RADIUS server.' WHERE var_name='RADIUSSecondaryServer'")));
2002 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Shared secret used for communication with primary RADIUS server.' WHERE var_name='RADIUSSecret'")));
2003 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Host name or IP address of primary RADIUS server.' WHERE var_name='RADIUSServer'")));
2004 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Timeout in seconds for requests to RADIUS server.' WHERE var_name='RADIUSTimeout'")));
2005 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'")));
2006 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='The hostname of the reporting server.' WHERE var_name='ReportingServerHostname'")));
2007 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='The port of the reporting server.' WHERE var_name='ReportingServerPort'")));
2008 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='Resolve DNS to IP on status poll.' WHERE var_name='ResolveDNSToIPOnStatusPoll'")));
2009 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='B',description='' WHERE var_name='ResolveNodeNames'")));
2010 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Interval in seconds between reading routing table from node.' WHERE var_name='RoutingTableUpdateInterval'")));
2011 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'")));
2012 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='H',description='Identification color for this server' WHERE var_name='ServerColor'")));
2013 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='ServerCommandOutputTimeout'")));
2014 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Name of this server' WHERE var_name='ServerName'")));
2015 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='Mobile phone driver to be used for sending SMS.' WHERE var_name='SMSDriver'")));
2016 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'")));
2017 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='The address used for sending mail from.' WHERE var_name='SMTPFromAddr'")));
2018 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='The name used as the sender.' WHERE var_name='SMTPFromName'")));
2019 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Number of retries for sending mail.' WHERE var_name='SMTPRetryCount'")));
2020 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='TCP port for SMTP server.' WHERE var_name='SNMPPorts'")));
2021 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='An SMTP server used for sending mail.' WHERE var_name='SMTPServer'")));
2022 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'")));
2023 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='The time how long SNMP trap logs are retained.' WHERE var_name='SNMPTrapLogRetentionTime'")));
2024 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Port used for SNMP traps.' WHERE var_name='SNMPTrapPort'")));
2025 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='StatusCalculationAlgorithm'")));
2026 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='Interval in seconds between status polls.' WHERE var_name='StatusPollingInterval'")));
2027 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'")));
2028 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='StatusShift'")));
2029 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='StatusSingleThreshold'")));
2030 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='' WHERE var_name='StatusThresholds'")));
2031 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='' WHERE var_name='StatusTranslation'")));
2032 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'")));
2033 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'")));
2034 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'")));
2035 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'")));
2036 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='UDP port used by built-in syslog server.' WHERE var_name='SyslogListenPort'")));
2037 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='C',description='Node matching policy for built-in syslog daemon.' WHERE var_name='SyslogNodeMatchingPolicy'")));
2038 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'")));
2039 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'")));
2040 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='The URL for the Tile server.' WHERE var_name='TileServerURL'")));
2041 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='TopologyDiscoveryRadius'")));
2042 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='' WHERE var_name='TopologyExpirationTime'")));
2043 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'")));
2044 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'")));
2045 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'")));
2046 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'")));
2047 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='C',description='Control usage of interface aliases (or descriptions).' WHERE var_name='UseInterfaceAliases'")));
727b90ff 2048 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
2049 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'")));
2050 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'")));
2051 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='I',description='XMPP connection port.' WHERE var_name='XMPPPort'")));
2052 CHK_EXEC(SQLQuery(_T("UPDATE config SET data_type='S',description='XMPP connection server.' WHERE var_name='XMPPServer'")));
2053
2054 CHK_EXEC(CreateTable(
2055 _T("CREATE TABLE config_values (")
2056 _T("var_name varchar(63) not null,")
76d77587 2057 _T("var_value varchar(15) not null,")
2058 _T("var_description varchar(255) null,")
2059 _T("PRIMARY KEY(var_name,var_value))")));
e11eade2
EJ
2060
2061 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('ClientListenerPort','65535')")));
2062 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('ExternalAuditPort','65535')")));
2063 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('MobileDeviceListenerPort','65535')")));
2064 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('RADIUSPort','65535')")));
2065 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('RADIUSSecondaryPort','65535')")));
2066 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('ReportingServerPort','65535')")));
2067 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('SNMPPorts','65535')")));
2068 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('SNMPTrapPort','65535')")));
2069 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('SyslogListenPort','65535')")));
2070 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('XMPPPort','65535')")));
2071 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value) VALUES ('AllowedCiphers','63')")));
2072 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultInterfaceExpectedState','0','UP')")));
2073 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultInterfaceExpectedState','1','DOWN')")));
2074 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultInterfaceExpectedState','2','IGNORE')")));
2075 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultEncryptionPolicy','0','Disabled')")));
2076 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultEncryptionPolicy','1','Allowed')")));
2077 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultEncryptionPolicy','2','Preferred')")));
2078 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('DefaultEncryptionPolicy','3','Required')")));
2079 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('StatusPropagationAlgorithm','0','Default')")));
2080 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('StatusPropagationAlgorithm','1','Unchanged')")));
2081 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('StatusPropagationAlgorithm','2','Fixed')")));
2082 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('StatusPropagationAlgorithm','3','Relative')")));
2083 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('StatusPropagationAlgorithm','4','Translated')")));
2084 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('UseInterfaceAliases','0','Don`t use aliases')")));
2085 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('UseInterfaceAliases','1','Use aliases when possible')")));
2086 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('UseInterfaceAliases','2','Concatenate alias and name')")));
2087 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('UseInterfaceAliases','3','Concatenate name and alias')")));
2088 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('SyslogNodeMatchingPolicy','0','IP, then hostname')")));
2089 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('SyslogNodeMatchingPolicy','1','Hostname, then IP')")));
2090 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('LdapUserDeleteAction','0','Delete user')")));
2091 CHK_EXEC(SQLQuery(_T("INSERT INTO config_values (var_name,var_value,var_description) VALUES ('LdapUserDeleteAction','1','Disable user')")));
2092
e11eade2
EJ
2093 CHK_EXEC(SetSchemaVersion(429));
2094 return TRUE;
2095}
2096
2097/**
de1be1b5 2098 * Upgrade from V427 to V428
221826d9
VK
2099 */
2100static BOOL H_UpgradeFromV427(int currVersion, int newVersion)
2101{
2102 CHK_EXEC(CreateConfigParam(_T("ClusterContainerAutoBind"), _T("0"), _T("Enable/disable container auto binding for clusters"), 'B', true, false, false, false));
2103 CHK_EXEC(CreateConfigParam(_T("ClusterTemplateAutoApply"), _T("0"), _T("Enable/disable template auto apply for clusters"), 'B', true, false, false, false));
2104 CHK_EXEC(SetSchemaVersion(428));
2105 return TRUE;
2106}
2107
2108/**
de1be1b5 2109 * Upgrade from V426 to V427
f14e669f 2110 */
61854771 2111static BOOL H_UpgradeFromV426(int currVersion, int newVersion)
f14e669f 2112{
5f18cc16
VK
2113 CHK_EXEC(SQLQuery(_T("ALTER TABLE nodes ADD port_rows integer")));
2114 CHK_EXEC(SQLQuery(_T("ALTER TABLE nodes ADD port_numbering_scheme integer")));
61854771 2115 CHK_EXEC(SetSchemaVersion(427));
f14e669f
EJ
2116 return TRUE;
2117}
2118
2119/**
de1be1b5 2120 * Upgrade from V425 to V426
b52e8ddd 2121 */
291644e3
EJ
2122static BOOL H_UpgradeFromV425(int currVersion, int newVersion)
2123{
5f18cc16
VK
2124 CHK_EXEC(CreateConfigParam(_T("EnableAlarmSummaryEmails"), _T(""), _T("Enable alarm summary e-mails"), 'I', true, false, false, false));
2125 CHK_EXEC(CreateConfigParam(_T("AlarmSummaryEmailSchedule"), _T(""), _T("Schedule for sending alarm summary e-mails in cron format"), 'S', true, false, false, false));
2126 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
2127 CHK_EXEC(SetSchemaVersion(426));
2128 return TRUE;
2129}
2130
2131/**
de1be1b5 2132 * Upgrade from V424 to V425
291644e3 2133 */
b52e8ddd
EJ
2134static BOOL H_UpgradeFromV424(int currVersion, int newVersion)
2135{
2136 CHK_EXEC(SQLQuery(_T("ALTER TABLE scheduled_tasks ADD comments varchar(255)")));
2137 CHK_EXEC(SetSchemaVersion(425));
2138 return TRUE;
2139}
2140
2141/**
de1be1b5 2142 * Upgrade from V423 to V424
8b75662b
EJ
2143 */
2144static BOOL H_UpgradeFromV423(int currVersion, int newVersion)
2145{
2146 CHK_EXEC(CreateConfigParam(_T("MessageOfTheDay"), _T(""), _T("Message to be shown when a user logs into the console"), 'S', true, false, false, false));
2147 CHK_EXEC(SetSchemaVersion(424));
2148 return TRUE;
2149}
2150
2151/**
de1be1b5 2152 * Upgrade from V422 to V423
b2ecde3b
VK
2153 */
2154static BOOL H_UpgradeFromV422(int currVersion, int newVersion)
2155{
2156 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));
2157 CHK_EXEC(SetSchemaVersion(423));
2158 return TRUE;
2159}
2160
2161/**
2162 * Upgrade from V421 to V422
2163 */
88072662
VK
2164static BOOL H_UpgradeFromV421(int currVersion, int newVersion)
2165{
2166 CHK_EXEC(CreateConfigParam(_T("ServerColor"), _T(""), _T("Identification color for this server"), 'S', true, false, false, false));
2167 CHK_EXEC(CreateConfigParam(_T("ServerName"), _T(""), _T("Name of this server"), 'S', true, false, false, false));
2168 CHK_EXEC(SetSchemaVersion(422));
2169 return TRUE;
2170}
2171
2172/**
de1be1b5 2173 * Upgrade from V420 to V421
b2ecde3b 2174 */
d38a36c6 2175static BOOL H_UpgradeFromV420(int currVersion, int newVersion)
b97ddf57
EJ
2176{
2177 DB_RESULT hResult = SQLSelect(_T("SELECT access_rights,user_id,object_id FROM acl"));
b97ddf57
EJ
2178 if (hResult != NULL)
2179 {
2180 UINT32 rights;
4c34f2c2
EJ
2181 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("UPDATE acl SET access_rights=? WHERE user_id=? AND object_id=?"));
2182 if (hStmt != NULL)
b97ddf57 2183 {
4c34f2c2 2184 for(int i = 0; i < DBGetNumRows(hResult); i++)
b97ddf57 2185 {
4c34f2c2
EJ
2186 rights = DBGetFieldULong(hResult, i, 0);
2187 if ((rights & 0x2) == 0x2)
b97ddf57 2188 {
4c34f2c2 2189 rights = rights | 0x8000; // Add Manage maintenance access right to all users which have Modify object access right
b97ddf57
EJ
2190 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, rights);
2191 DBBind(hStmt, 2, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 1));
2192 DBBind(hStmt, 3, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 2));
2193 SQLExecute(hStmt);
b97ddf57
EJ
2194 }
2195 }
a6baa9d2
VK
2196 DBFreeStatement(hStmt);
2197 }
2198 else
2199 {
2200 if (!g_bIgnoreErrors)
2201 {
2202 DBFreeResult(hResult);
2203 return FALSE;
2204 }
b97ddf57 2205 }
b97ddf57
EJ
2206 DBFreeResult(hResult);
2207 }
2208 else
a6baa9d2
VK
2209 {
2210 if (!g_bIgnoreErrors)
2211 return FALSE;
2212 }
b97ddf57 2213
d38a36c6
EJ
2214 CHK_EXEC(SetSchemaVersion(421));
2215 return TRUE;
2216}
2217
de1be1b5 2218/**
d38a36c6
EJ
2219 * Upgrade from V419 to V420
2220 */
2221static BOOL H_UpgradeFromV419(int currVersion, int newVersion)
2222{
2223 CHK_EXEC(CreateConfigParam(_T("EnableReportingServer"), _T("0"), 1, 1));
2224 CHK_EXEC(CreateConfigParam(_T("ReportingServerHostname"), _T("localhost"), 1, 1));
2225 CHK_EXEC(CreateConfigParam(_T("ReportingServerPort"), _T("4710"), 1, 1));
b97ddf57
EJ
2226 CHK_EXEC(SetSchemaVersion(420));
2227 return TRUE;
2228}
2229
2230/**
b2ecde3b
VK
2231 * Upgrade from V418 to V419
2232 */
288a0046
VK
2233static BOOL H_UpgradeFromV418(int currVersion, int newVersion)
2234{
2235 CHK_EXEC(SQLQuery(_T("ALTER TABLE items ADD npe_name varchar(15)")));
2236 CHK_EXEC(SetSchemaVersion(419));
2237 return TRUE;
2238}
2239
2240/**
de1be1b5 2241 * Upgrade from V417 to V418
b2ecde3b 2242 */
7ac735ef 2243static BOOL H_UpgradeFromV417(int currVersion, int newVersion)
2244{
288a0046
VK
2245 // Update in object tools objectToolFilter objectMenuFilter
2246 // move object tool flags to filter structure
7ac735ef 2247 DB_RESULT hResult = SQLSelect(_T("SELECT tool_id,flags,tool_filter FROM object_tools"));
2248 if (hResult != NULL)
2249 {
2250 int count = DBGetNumRows(hResult);
2251 for(int i = 0; i < count; i++)
2252 {
2253 int filteringFlag = 0;
2254 int objectToolFlag = DBGetFieldLong(hResult, i, 1);
7ac735ef 2255
a13cb1ac
VK
2256 // Separate and reorder flags for filter and for object tools
2257 for(int j = 1; j < 5; j = j << 1) //REQUIRES_SNMP 0x01, REQUIRES_AGENT 0x02, REQUIRES_OID_MATCH 0x04
7ac735ef 2258 {
a13cb1ac 2259 if ((objectToolFlag & j) != 0)
7ac735ef 2260 {
2261 objectToolFlag = objectToolFlag & ~j;
2262 filteringFlag = filteringFlag | j;
2263 }
2264 }
a13cb1ac
VK
2265
2266 if ((objectToolFlag & 0x08) != 0) //ASK_CONFIRMATION
7ac735ef 2267 {
2268 objectToolFlag = objectToolFlag & ~0x08;
2269 objectToolFlag = objectToolFlag | 0x01;
2270 }
a13cb1ac
VK
2271
2272 if ((objectToolFlag & 0x10) != 0) //GENERATES_OUTPUT
7ac735ef 2273 {
2274 objectToolFlag = objectToolFlag & ~0x10;
2275 objectToolFlag = objectToolFlag | 0x02;
2276 }
a13cb1ac
VK
2277
2278 if ((objectToolFlag & 0x20) != 0) //DISABLED
7ac735ef 2279 {
2280 objectToolFlag = objectToolFlag & ~0x20;
2281 objectToolFlag = objectToolFlag | 0x04;
2282 }
a13cb1ac
VK
2283
2284 if ((objectToolFlag & 0x40) != 0) //SHOW_IN_COMMANDS
7ac735ef 2285 {
2286 objectToolFlag = objectToolFlag & ~0x40;
2287 objectToolFlag = objectToolFlag | 0x08;
2288 }
a13cb1ac
VK
2289
2290 if ((objectToolFlag & 0x80) != 0) //REQUIRES_NODE_OS_MATCH
7ac735ef 2291 {
2292 objectToolFlag = objectToolFlag & ~0x80;
2293 filteringFlag = filteringFlag | 0x08;
2294 }
a13cb1ac
VK
2295
2296 if ((objectToolFlag & 0x100) != 0) //REQUIRES_TEMPLATE_MATCH
7ac735ef 2297 {
2298 objectToolFlag = objectToolFlag & ~0x100;
2299 filteringFlag = filteringFlag | 0x10;
2300 }
a13cb1ac
VK
2301
2302 if ((objectToolFlag & 0x10000) != 0) //SNMP_INDEXED_BY_VALUE
7ac735ef 2303 {
2304 objectToolFlag = objectToolFlag & ~0x10000;
2305 objectToolFlag = objectToolFlag | 0x10;
2306 }
a13cb1ac
VK
2307
2308 if ((objectToolFlag & 0x20000) != 0) //REQUIRES_WORKSTATION_OS_MATCH
7ac735ef 2309 {
2310 objectToolFlag = objectToolFlag & ~0x20000;
2311 filteringFlag = filteringFlag | 0x20;
2312 }
2313
a13cb1ac
VK
2314 // Add filter flags to XML
2315 TCHAR *xml = DBGetField(hResult, i, 2, NULL, 0);
367caea6 2316 size_t len = (xml != NULL) ? _tcslen(xml) + 1024 : 1024;
a13cb1ac 2317 TCHAR *tmp = (TCHAR *)malloc(len * sizeof(TCHAR));
367caea6 2318 TCHAR *ptr = (xml != NULL) ? _tcsrchr(xml, '<') : NULL;
a13cb1ac 2319 if (ptr != NULL)
7ac735ef 2320 {
2321 *ptr = 0;
a13cb1ac 2322 _sntprintf(tmp, len, _T("%s<flags>%d</flags></objectMenuFilter>"), xml, filteringFlag);
7ac735ef 2323 _tcsncpy(tmp, _T("<objectMenuFilter"), 17); //Change main tag name
2324 }
2325 else
2326 {
a13cb1ac 2327 _sntprintf(tmp, len, _T("<objectMenuFilter><flags>%d</flags></objectMenuFilter>"), filteringFlag);
7ac735ef 2328 }
2329
2330 DB_STATEMENT hStmt = DBPrepare(g_hCoreDB, _T("UPDATE object_tools SET flags=?,tool_filter=? WHERE tool_id=?"));
2331 if (hStmt != NULL)
2332 {
2333 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, objectToolFlag);
a13cb1ac 2334 DBBind(hStmt, 2, DB_SQLTYPE_TEXT, tmp, DB_BIND_DYNAMIC);
7ac735ef 2335 DBBind(hStmt, 3, DB_SQLTYPE_INTEGER, DBGetFieldULong(hResult, i, 0));
2336 if (!SQLExecute(hStmt))
2337 {
2338 if (!g_bIgnoreErrors)
2339 {
a13cb1ac 2340 free(xml);
7ac735ef 2341 DBFreeStatement(hStmt);
2342 DBFreeResult(hResult);
2343 return FALSE;
2344 }
2345 }
2346 }
a13cb1ac 2347 else
7ac735ef 2348 {
a13cb1ac
VK
2349 free(tmp);
2350 if (!g_bIgnoreErrors)
2351 {
2352 free(xml);
2353 DBFreeResult(hResult);
2354 return FALSE;
2355 }
7ac735ef 2356 }
a13cb1ac 2357 free(xml);
7ac735ef 2358 }
2359 DBFreeResult(hResult);
2360 }
2361 else
2362 {
2363 if (!g_bIgnoreErrors)
2364 return false;
2365 }
2366
2367 CHK_EXEC(SetSchemaVersion(418));
2368 return TRUE;
2369}
2370
2371/**
b2ecde3b
VK
2372 * Upgrade from V416 to V417
2373 */
c299358f
EJ
2374static BOOL H_UpgradeFromV416(int currVersion, int newVersion)
2375{
2376 CHK_EXEC(CreateConfigParam(_T("JiraIssueType"), _T("Task"), true, false));
2377 CHK_EXEC(CreateConfigParam(_T("JiraLogin"), _T("netxms"), true, true));
2378 CHK_EXEC(CreateConfigParam(_T("JiraPassword"), _T(""), true, true));
2379 CHK_EXEC(CreateConfigParam(_T("JiraProjectCode"), _T("NETXMS"), true, false));
2380 CHK_EXEC(CreateConfigParam(_T("JiraProjectComponent"), _T(""), true, false));
2381 CHK_EXEC(CreateConfigParam(_T("JiraServerURL"), _T("http://localhost"), true, true));
2382
2383 CHK_EXEC(SetSchemaVersion(417));
2384 return TRUE;
2385}
2386
2387/**
b2ecde3b
VK
2388 * Upgrade from V415 to V416
2389 */
6a6b96c0
EJ
2390static BOOL H_UpgradeFromV415(int currVersion, int newVersion)
2391{
2392 CHK_EXEC(CreateTable(
2393 _T("CREATE TABLE alarm_categories (")
2394 _T("id integer not null,")
2395 _T("name varchar(63) null,")
2396 _T("descr varchar(255) null,")
2397 _T("PRIMARY KEY(id))")));
2398 CHK_EXEC(CreateTable(
2399 _T("CREATE TABLE alarm_category_acl (")
2400 _T("category_id integer not null,")
2401 _T("user_id integer not null,")
2402 _T("PRIMARY KEY(category_id,user_id))")));
2403 CHK_EXEC(CreateTable(
2404 _T("CREATE TABLE alarm_category_map (")
2405 _T("alarm_id integer not null,")
2406 _T("category_id integer not null,")
2407 _T("PRIMARY KEY(alarm_id,category_id))")));
2408
2409 CHK_EXEC(SQLQuery(
2410 _T("ALTER TABLE alarms ADD alarm_category_ids varchar(255)")));
2411
2412 // Add view all alarms system access to user group - Everyone
2413 DB_RESULT hResult = SQLSelect(_T("SELECT system_access FROM user_groups WHERE name='Everyone'"));
2414 if (hResult != NULL)
2415 {
2416 UINT64 sysAccess = DBGetFieldUInt64(hResult, 0, 0);
2417 sysAccess = sysAccess | SYSTEM_ACCESS_VIEW_ALL_ALARMS;
2418
2419 TCHAR query[MAX_DB_STRING];
2420 _sntprintf(query, MAX_DB_STRING, _T("UPDATE user_groups SET system_access=%ld WHERE name='Everyone'"), sysAccess);
2421 CHK_EXEC(SQLQuery(query));
2422
2423 DBFreeResult(hResult);
2424 }
2425 else
2426 {
2427 if (!g_bIgnoreErrors)
2428 return false;
2429 }
2430
2431 CHK_EXEC(SetSchemaVersion(416));
2432 return TRUE;
2433}
2434
2435/**
73bbcd77
VK
2436 * Upgrade from V414 to V415
2437 */
2438static BOOL H_UpgradeFromV414(int currVersion, int newVersion)
2439{
797a2b25 2440 CHK_EXEC(DBRemoveNotNullConstraint(g_hCoreDB, _T("dci_summary_tables"), _T("menu_path")));
73bbcd77
VK
2441 CHK_EXEC(SetSchemaVersion(415));
2442 return TRUE;
2443}
2444
2445/**
685508a7
VK
2446 * Upgrade from V413 to V414
2447 */
2448static BOOL H_UpgradeFromV413(int currVersion, int newVersion)
2449{
2450 CHK_EXEC(SQLQuery(_T("UPDATE config SET var_name='EnableSyslogReceiver' WHERE var_name='EnableSyslogDaemon'")));
2451 CHK_EXEC(SetSchemaVersion(414));
2452 return TRUE;
2453}
2454
2455/**
be737a59
VK
2456 * Upgrade from V412 to V413
2457 */
2458static BOOL H_UpgradeFromV412(int currVersion, int newVersion)
2459{
2460 CHK_EXEC(SQLQuery(_T("UPDATE users SET name='system',description='Built-in system account',full_name='',flags=12 WHERE id=0")));
2461
2462 TCHAR password[128];
2463 DB_RESULT hResult = SQLSelect(_T("SELECT password FROM users WHERE id=0"));
2464 if (hResult != NULL)
2465 {
2466 if (DBGetNumRows(hResult) > 0)
2467 DBGetField(hResult, 0, 0, password, 128);
2468 else
2469 _tcscpy(password, _T("3A445C0072CD69D9030CC6644020E5C4576051B1")); // Use default password "netxms"
2470 DBFreeResult(hResult);
2471 }
2472 else
2473 {
2474 if (!g_bIgnoreErrors)
2475 return false;
2476 }
2477
2478 UINT32 userId = 1;
2479 hResult = SQLSelect(_T("SELECT max(id) FROM users"));
2480 if (hResult != NULL)
2481 {
2482 if (DBGetNumRows(hResult) > 0)
2483 userId = DBGetFieldULong(hResult, 0, 0) + 1;
2484 DBFreeResult(hResult);
2485 }
2486 else
2487 {
2488 if (!g_bIgnoreErrors)
2489 return false;
2490 }
2491
2492 uuid guid = uuid::generate();
2493 TCHAR query[1024];
2494 _sntprintf(query, 1024,
2495 _T("INSERT INTO users (id,name,password,system_access,flags,full_name,")
2496 _T(" description,grace_logins,auth_method,guid,")
2497 _T(" cert_mapping_method,cert_mapping_data,")
2498 _T(" auth_failures,last_passwd_change,min_passwd_length,")
2499 _T(" disabled_until,last_login) VALUES (%d,'admin','%s',274877906943,0,")
2500 _T(" '','Default administrator account',5,0,'%s',0,'',0,0,0,0,0)"),
2501 userId, password, (const TCHAR *)guid.toString());
2502 CHK_EXEC(SQLQuery(query));
2503
2504 for(int i = 1; i < 10; i++)
2505 {
2506 _sntprintf(query, 256, _T("INSERT INTO acl (object_id,user_id,access_rights) VALUES (%d,%d,32767)"), i, userId);
2507 CHK_EXEC(SQLQuery(query));
2508 }
2509
74cd0a62 2510 //Add adming to Admin group if exists
2511 UINT32 groupId = 0;
2512 hResult = SQLSelect(_T("SELECT id FROM user_groups WHERE name='Admins'"));
2513 if (hResult != NULL)
2514 {
2515 if (DBGetNumRows(hResult) > 0)
2516 groupId = DBGetFieldULong(hResult, 0, 0);
2517 DBFreeResult(hResult);
2518 }
2519 else
2520 {
2521 if (!g_bIgnoreErrors)
2522 return false;
2523 }
2524 if(groupId != 0)
2525 {
2526 _sntprintf(query, 256, _T("INSERT INTO user_group_members (group_id,user_id) VALUES (%d,%d)"), groupId, userId);
2527 CHK_EXEC(SQLQuery(query));
2528 }
2529
2530 //Update non object ACL
95111e00 2531 _sntprintf(query, 256, _T("UPDATE object_tools_acl SET user_id=%d WHERE user_id=0"), userId);
74cd0a62 2532 CHK_EXEC(SQLQuery(query));
2533
2534 _sntprintf(query, 256, _T("UPDATE graph_acl SET user_id=%d WHERE user_id=0"), userId);
2535 CHK_EXEC(SQLQuery(query));
2536
2537 _sntprintf(query, 256, _T("UPDATE graphs SET owner_id=%d WHERE owner_id=0"), userId);
2538 CHK_EXEC(SQLQuery(query));
2539
2540
be737a59
VK
2541 CHK_EXEC(SetSchemaVersion(413));
2542 return TRUE;
2543}
2544
2545/**
43b62436
VK
2546 * Upgrade from V411 to V412
2547 */
2548static BOOL H_UpgradeFromV411(int currVersion, int newVersion)
2549{
2550 DB_RESULT hResult = SQLSelect(_T("SELECT id,zone_guid,agent_proxy,snmp_proxy,icmp_proxy,ssh_proxy FROM zones"));
2551 if (hResult != NULL)
2552 {
2553 CHK_EXEC(SQLQuery(_T("DROP TABLE zones")));
2554 CHK_EXEC(CreateTable(
2555 _T("CREATE TABLE zones (")
2556 _T("id integer not null,")
2557 _T("zone_guid integer not null,")
2558 _T("proxy_node integer not null,")
2559 _T("PRIMARY KEY(id))")));
2560 int count = DBGetNumRows(hResult);
2561 if (count > 0)
2562 {
2563 TCHAR query[256];
2564 for(int i = 0; i < count; i++)
2565 {
2566 UINT32 proxy = 0;
2567 for(int j = 2; (j < 6) && (proxy == 0); j++)
2568 proxy = DBGetFieldULong(hResult, i, j);
49e749f3 2569 _sntprintf(query, 256, _T("INSERT INTO zones (id,zone_guid,proxy_node) VALUES (%d,%d,%d)"),
43b62436
VK
2570 DBGetFieldLong(hResult, i, 0), DBGetFieldLong(hResult, i, 1), (int)proxy);
2571 CHK_EXEC(SQLQuery(query));
2572 }
2573 }
2574 DBFreeResult(hResult);
2575 }
2576 else
2577 {
be737a59 2578 if (!g_bIgnoreErrors)
43b62436
VK
2579 return false;
2580 }
2581 CHK_EXEC(SetSchemaVersion(412));
2582 return TRUE;
2583}
2584
2585/**
63604cda
VK
2586 * Upgrade from V410 to V411
2587 */
2588static BOOL H_UpgradeFromV410(int currVersion, int newVersion)
2589{
29e18f5a 2590 //check if tdata upgrade was already done, then just delete "TdataTableUpdated" metadata parameter
03e5e230 2591 if (!MetaDataReadInt(_T("TdataTableUpdated"), 0))
63604cda 2592 {
29e18f5a 2593 StringMap savedMetadata;
2594 DB_RESULT hResult = SQLSelect(_T("SELECT var_name,var_value FROM metadata WHERE var_name LIKE 'TDataTableCreationCommand_%' OR var_name LIKE 'TDataIndexCreationCommand_%'"));
2595 if (hResult != NULL)
63604cda 2596 {
29e18f5a 2597 int count = DBGetNumRows(hResult);
2598 for(int i = 0; i < count; i++)
63604cda 2599 {
29e18f5a 2600 savedMetadata.setPreallocated(DBGetField(hResult, i, 0, NULL, 0), DBGetField(hResult, i, 1, NULL, 0));
63604cda 2601 }
29e18f5a 2602 DBFreeResult(hResult);
2603 }
2604 else if (!g_bIgnoreErrors)
2605 {
63604cda
VK
2606 return false;
2607 }
63604cda 2608
29e18f5a 2609 static const TCHAR *batch =
2610 _T("DELETE FROM metadata WHERE var_name LIKE 'TDataTableCreationCommand_%' OR var_name LIKE 'TDataIndexCreationCommand_%'\n")
2611 _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")
2612 _T("<END>");
2613 CHK_EXEC(SQLBatch(batch));
2614
2615 if (g_dbSyntax == DB_SYNTAX_MSSQL)
2616 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)')")));
2617 else
2618 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)')")));
2619
2620 // table conversion will require multiple commits
2621 DBCommit(g_hCoreDB);
2622 if (!ConvertTDataTables())
2623 {
2624 if (!g_bIgnoreErrors)
2625 {
2626 // Restore metadata
2627 SQLQuery(_T("DELETE FROM metadata WHERE var_name LIKE 'TDataTableCreationCommand_%' OR var_name LIKE 'TDataIndexCreationCommand_%'"));
2628 StringList *keys = savedMetadata.keys();
2629 for(int i = 0; i < keys->size(); i++)
2630 {
2631 TCHAR query[4096];
2632 _sntprintf(query, 4096, _T("INSERT INTO metadata (var_name,var_value) VALUES (%s,%s)"),
2633 (const TCHAR *)DBPrepareString(g_hCoreDB, keys->get(i)),
2634 (const TCHAR *)DBPrepareString(g_hCoreDB, savedMetadata.get(keys->get(i))));
2635 SQLQuery(query);
2636 }
2637 return false;
2638 }
2639 }
2640
2641 DBBegin(g_hCoreDB);
2642 }
2643 else
2644 {
2645 CHK_EXEC(SQLQuery(_T("DELETE FROM metadata WHERE var_name='TdataTableUpdated'")));
2646 }
63604cda
VK
2647 CHK_EXEC(SetSchemaVersion(411));
2648 return TRUE;
2649}
2650
2651/**
241541f4
VK
2652 * Upgrade from V409 to V410
2653 */
2654static BOOL H_UpgradeFromV409(int currVersion, int newVersion)
2655{
2656 static const TCHAR *batch =
2657 _T("ALTER TABLE zones ADD ssh_proxy integer\n")
2658 _T("UPDATE zones SET ssh_proxy=0\n")
2659 _T("ALTER TABLE nodes ADD ssh_login varchar(63)\n")
2660 _T("ALTER TABLE nodes ADD ssh_password varchar(63)\n")
2661 _T("ALTER TABLE nodes ADD ssh_proxy integer\n")
2662 _T("UPDATE nodes SET ssh_proxy=0\n")
2663 _T("<END>");
2664 CHK_EXEC(SQLBatch(batch));
2665
797a2b25
VK
2666 CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("nodes"), _T("ssh_proxy")));
2667 CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("zones"), _T("ssh_proxy")));
241541f4
VK
2668
2669 CHK_EXEC(SetSchemaVersion(410));
2670 return TRUE;
2671}
2672
2673/**
e980db40
VK
2674 * Upgrade from V408 to V409
2675 */
2676static BOOL H_UpgradeFromV408(int currVersion, int newVersion)
2677{
2678 static const TCHAR *batch =
2679 _T("ALTER TABLE nodes ADD node_type integer\n")
2680 _T("ALTER TABLE nodes ADD node_subtype varchar(127)\n")
2681 _T("UPDATE nodes SET node_type=0\n")
2682 _T("<END>");
2683 CHK_EXEC(SQLBatch(batch));
2684
797a2b25 2685 CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("nodes"), _T("node_type")));
241541f4 2686
e980db40
VK
2687 CHK_EXEC(SetSchemaVersion(409));
2688 return TRUE;
2689}
2690
2691/**
e4926628
VK
2692 * Upgrade from V407 to V408
2693 */
2694static BOOL H_UpgradeFromV407(int currVersion, int newVersion)
2695{
2696 CHK_EXEC(CreateTable(
2697 _T("CREATE TABLE chassis (")
2698 _T(" id integer not null,")
32a400d9 2699 _T(" flags integer not null,")
e4926628
VK
2700 _T(" controller_id integer not null,")
2701 _T(" rack_id integer not null,")
2702 _T(" rack_image varchar(36) null,")
2703 _T(" rack_position integer not null,")
2704 _T(" rack_height integer not null,")
2705 _T(" PRIMARY KEY(id))")
2706 ));
2707
2708 static const TCHAR *batch =
2709 _T("ALTER TABLE nodes ADD chassis_id integer\n")
2710 _T("UPDATE nodes SET chassis_id=0\n")
2711 _T("<END>");
2712 CHK_EXEC(SQLBatch(batch));
2713
797a2b25 2714 CHK_EXEC(DBSetNotNullConstraint(g_hCoreDB, _T("nodes"), _T("chassis_id")));
241541f4 2715
e4926628
VK
2716 CHK_EXEC(SetSchemaVersion(408));
2717 return TRUE;
2718}
2719
2720/**
8498228c 2721 * Upgrade from V406 to V407
2722 */
2723static BOOL H_UpgradeFromV406(int currVersion, int newVersion)
2724{
74724c20 2725 DBResizeColumn(g_hCoreDB, _T("user_groups"), _T("ldap_unique_id"), 64, true);
e4926628 2726 CHK_EXEC(SetSchemaVersion(407));
8498228c 2727 return TRUE;
2728}
2729
2730/**
ba756b1a
VK
2731 * Upgrade from V405 to V406
2732 */
2733static BOOL H_UpgradeFromV405(int currVersion, int newVersion)
2734{
2735 static const TCHAR *batch =
2736 _T("ALTER TABLE nodes ADD syslog_msg_count $SQL:INT64\n")
2737 _T("ALTER TABLE nodes ADD snmp_trap_count $SQL:INT64\n")
2738 _T("UPDATE nodes SET syslog_msg_count=0,snmp_trap_count=0\n")
2739 _T("<END>");
2740 CHK_EXEC(SQLBatch(batch));
e4926628 2741 CHK_EXEC(SetSchemaVersion(406));
ba756b1a
VK
2742 return TRUE;
2743}
2744
2745/**
b123ecb3 2746 * Upgrade from V404 to V405
2747 */
2748static BOOL H_UpgradeFromV404(int currVersion, int newVersion)
2749{
7b30e5ae 2750 CHK_EXEC(CreateEventTemplate(EVENT_AGENT_LOG_PROBLEM, _T("SYS_AGENT_LOG_PROBLEM"),
b123ecb3 2751 SEVERITY_MAJOR, EF_LOG, _T("262057ca-357a-4a4d-9b78-42ae96e490a1"),
2752 _T("Problem with agent log: %2"),
7b30e5ae 2753 _T("Generated on status poll if agent reports problem with log file.\r\n")
b123ecb3 2754 _T("Parameters:\r\n")
7b30e5ae 2755 _T(" 1) Status code\r\n")
b123ecb3 2756 _T(" 2) Description")));
7b30e5ae 2757 CHK_EXEC(CreateEventTemplate(EVENT_AGENT_LOCAL_DATABASE_PROBLEM, _T("SYS_AGENT_LOCAL_DATABASE_PROBLEM"),
b123ecb3 2758 SEVERITY_MAJOR, EF_LOG, _T("d02b63f1-1151-429e-adb9-1dfbb3a31b32"),
2759 _T("Problem with agent local database: %2"),
7b30e5ae 2760 _T("Generated on status poll if agent reports local database problem.\r\n")
b123ecb3 2761 _T("Parameters:\r\n")
7b30e5ae 2762 _T(" 1) Status code\r\n")
b123ecb3 2763 _T(" 2) Description")));
2764
2765 int ruleId = NextFreeEPPruleID();
2766 TCHAR query[1024];
2767 _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 2768 _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 2769 ruleId, EVENT_ALARM_TIMEOUT);
2770 CHK_EXEC(SQLQuery(query));
7b30e5ae 2771 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_AGENT_LOG_PROBLEM);
b123ecb3 2772 CHK_EXEC(SQLQuery(query));
7b30e5ae
VK
2773
2774 ruleId = NextFreeEPPruleID();
b123ecb3 2775 _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 2776 _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 2777 ruleId, EVENT_ALARM_TIMEOUT);
2778 CHK_EXEC(SQLQuery(query));
7b30e5ae 2779 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_AGENT_LOCAL_DATABASE_PROBLEM);
b123ecb3 2780 CHK_EXEC(SQLQuery(query));
2781
e4926628 2782 CHK_EXEC(SetSchemaVersion(405));
b123ecb3 2783 return TRUE;
2784}
2785
2786/**
b8c8a8a7
VK
2787 * Upgrade from V403 to V404
2788 */
2789static BOOL H_UpgradeFromV403(int currVersion, int newVersion)
2790{
2791 CHK_EXEC(CreateConfigParam(_T("SyslogIgnoreMessageTimestamp"), _T("0"),
2792 _T("Ignore timestamp received in syslog messages and always use server time"),
2793 'B', true, false, false, false));
e4926628 2794 CHK_EXEC(SetSchemaVersion(404));
b8c8a8a7
VK
2795 return TRUE;
2796}
2797
2798/**
a18687b9
VK
2799 * Upgrade from V402 to V403
2800 */
2801static BOOL H_UpgradeFromV402(int currVersion, int newVersion)
2802{
2803 CHK_EXEC(SQLQuery(_T("DROP TABLE policy_time_range_list")));
2804 CHK_EXEC(SQLQuery(_T("DROP TABLE time_ranges")));
e4926628 2805 CHK_EXEC(SetSchemaVersion(403));
a18687b9
VK
2806 return TRUE;
2807}
2808
2809/**
ed0a9e41
VK
2810 * Upgrade from V401 to V402
2811 */
2812static BOOL H_UpgradeFromV401(int currVersion, int newVersion)
2813{
2814 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_event_log_source ON event_log(event_source)")));
e4926628 2815 CHK_EXEC(SetSchemaVersion(402));
ed0a9e41
VK
2816 return TRUE;
2817}
2818
2819/**
bad2c02e 2820 * Upgrade from V400 to V401
2821 */
2822static BOOL H_UpgradeFromV400(int currVersion, int newVersion)
2823{
3da098f7
VK
2824 CHK_EXEC(CreateEventTemplate(EVENT_LDAP_SYNC_ERROR, _T("SYS_LDAP_SYNC_ERROR"),
2825 SEVERITY_MAJOR, EF_LOG, _T("f7e8508d-1503-4736-854b-1e5b8b0ad1f2"),
2826 _T("LDAP sync error: %5"),
bad2c02e 2827 _T("Generated when LDAP synchronization error occurs.\r\n")
2828 _T("Parameters:\r\n")
2829 _T(" 1) User ID\r\n")
2830 _T(" 2) User GUID\r\n")
2831 _T(" 3) User LDAP DN\r\n")
2832 _T(" 4) User name\r\n")
2833 _T(" 5) Problem description")));
355aa002 2834
3da098f7 2835 int ruleId = NextFreeEPPruleID();
bad2c02e 2836 TCHAR query[1024];
3da098f7 2837 _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 2838 CHK_EXEC(SQLQuery(query));
50e319a2 2839 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_LDAP_SYNC_ERROR);
bad2c02e 2840 CHK_EXEC(SQLQuery(query));
2841
2842 CHK_EXEC(SQLQuery(_T("ALTER TABLE users ADD ldap_unique_id varchar(64)")));
2843 CHK_EXEC(SQLQuery(_T("ALTER TABLE user_groups ADD ldap_unique_id varchar(64)")));
2844 CHK_EXEC(CreateConfigParam(_T("LdapUserUniqueId"), _T(""), true, false, false));
2845 CHK_EXEC(CreateConfigParam(_T("LdapGroupUniqueId"), _T(""), true, false, false));
2846
e4926628 2847 CHK_EXEC(SetSchemaVersion(401));
bad2c02e 2848 return TRUE;
2849}
355aa002 2850
c908b63b 2851/**
355aa002
TD
2852 * Upgrade from V399 to V400
2853 */
2854static BOOL H_UpgradeFromV399(int currVersion, int newVersion)
2855{
2856 CHK_EXEC(CreateConfigParam(_T("JobRetryCount"), _T("5"), _T("Maximum mumber of job execution retrys"), 'I', true, false, false, false));
e4926628 2857 CHK_EXEC(SetSchemaVersion(400));
355aa002
TD
2858 return TRUE;
2859}
2860
2861/**
2862 * Upgrade from V398 to V399
0de31ec3 2863 */
8e6e8ef1
VK
2864static BOOL H_UpgradeFromV398(int currVersion, int newVersion)
2865{
2866 CHK_EXEC(CreateTable(
2867 _T("CREATE TABLE config_repositories (")
2868 _T(" id integer not null,")
2869 _T(" url varchar(1023) not null,")
2870 _T(" auth_token varchar(63) null,")
2871 _T(" description varchar(1023) null,")
2872 _T(" PRIMARY KEY(id))")
2873 ));
2874
e4926628 2875 CHK_EXEC(SetSchemaVersion(399));
8e6e8ef1
VK
2876 return TRUE;
2877}
2878
2879/**
2880 * Upgrade from V397 to V398
2881 */
0de31ec3
VK
2882static BOOL H_UpgradeFromV397(int currVersion, int newVersion)
2883{
2884 CHK_EXEC(CreateTable(
2885 _T("CREATE TABLE currency_codes (")
2886 _T(" numeric_code char(3) not null,")
2887 _T(" alpha_code char(3) not null,")
a27a303e 2888 _T(" description varchar(127) not null,")
0de31ec3
VK
2889 _T(" exponent integer not null,")
2890 _T(" PRIMARY KEY(numeric_code))")
2891 ));
2892
2893 CHK_EXEC(CreateTable(
2894 _T("CREATE TABLE country_codes (")
2895 _T(" numeric_code char(3) not null,")
2896 _T(" alpha_code char(2) not null,")
2897 _T(" alpha3_code char(3) not null,")
a27a303e 2898 _T(" name varchar(127) not null,")
0de31ec3
VK
2899 _T(" PRIMARY KEY(numeric_code))")
2900 ));
2901
dc4472a5 2902 static const TCHAR *batch1 =
0de31ec3
VK
2903 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('008', 'ALL', 'Lek', 2)\n")
2904 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('012', 'DZD', 'Algerian Dinar', 2)\n")
2905 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('031', 'AZM', 'Azerbaijanian Manat', 0)\n")
2906 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('032', 'ARS', 'Argentine Peso', 2)\n")
2907 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('036', 'AUD', 'Australian Dollar', 2)\n")
2908 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('044', 'BSD', 'Bahamian Dollar', 2)\n")
2909 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('048', 'BHD', 'Bahraini Dinar', 3)\n")
2910 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('050', 'BDT', 'Taka', 2)\n")
2911 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('051', 'AMD', 'Armenian Dram', 2)\n")
2912 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('052', 'BBD', 'Barbados Dollar', 2)\n")
2913 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('060', 'BMD', 'Bermudian Dollar', 2)\n")
2914 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('064', 'BTN', 'Ngultrum', 2)\n")
2915 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('068', 'BOB', 'Boliviano', 2)\n")
2916 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('072', 'BWP', 'Pula', 2)\n")
2917 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('084', 'BZD', 'Belize Dollar', 2)\n")
2918 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('090', 'SBD', 'Solomon Islands Dollar', 2)\n")
2919 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('096', 'BND', 'Brunei Dollar', 2)\n")
2920 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('100', 'BGL', 'Lev', 0)\n")
2921 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('104', 'MMK', 'Kyat', 2)\n")
2922 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('108', 'BIF', 'Burundi Franc', 0)\n")
2923 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('116', 'KHR', 'Riel', 2)\n")
2924 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('124', 'CAD', 'Canadian Dollar', 2)\n")
2925 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('132', 'CVE', 'Cape Verde Escudo', 2)\n")
2926 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('136', 'KYD', 'Cayman Islands Dollar', 2)\n")
2927 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('144', 'LKR', 'Sri Lanka Rupee', 2)\n")
2928 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('152', 'CLP', 'Chilean Peso', 0)\n")
2929 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('156', 'CNY', 'Yuan Renminbi', 2)\n")
2930 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('170', 'COP', 'Colombian Peso', 2)\n")
2931 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('174', 'KMF', 'Comoro Franc', 0)\n")
2932 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('188', 'CRC', 'Costa Rican Colon', 2)\n")
2933 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('191', 'HRK', 'Croatian Kuna', 2)\n")
2934 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('192', 'CUP', 'Cuban Peso', 2)\n")
2935 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('196', 'CYP', 'Cyprus Pound', 0)\n")
2936 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('203', 'CZK', 'Czech Koruna', 2)\n")
2937 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('208', 'DKK', 'Danish Krone', 2)\n")
2938 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('214', 'DOP', 'Dominican Peso', 2)\n")
2939 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('222', 'SVC', 'El Salvador Colon', 2)\n")
2940 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('230', 'ETB', 'Ethiopian Birr', 2)\n")
2941 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('232', 'ERN', 'Nakfa', 2)\n")
2942 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('233', 'EEK', 'Estonian Kroon', 0)\n")
2943 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('238', 'FKP', 'Falkland Islands Pound', 2)\n")
2944 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('242', 'FJD', 'Fiji Dollar', 2)\n")
2945 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('262', 'DJF', 'Djibouti Franc', 0)\n")
2946 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('270', 'GMD', 'Dalasi', 2)\n")
2947 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('288', 'GHC', 'Cedi', 0)\n")
2948 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('292', 'GIP', 'Gibraltar Pound', 2)\n")
2949 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('320', 'GTQ', 'Quetzal', 2)\n")
2950 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('324', 'GNF', 'Guinea Franc', 0)\n")
2951 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('328', 'GYD', 'Guyana Dollar', 2)\n")
2952 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('332', 'HTG', 'Gourde', 2)\n")
2953 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('340', 'HNL', 'Lempira', 2)\n")
2954 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('344', 'HKD', 'Hong Kong Dollar', 2)\n")
2955 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('348', 'HUF', 'Forint', 2)\n")
2956 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('352', 'ISK', 'Iceland Krona', 0)\n")
2957 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('356', 'INR', 'Indian Rupee', 2)\n")
2958 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('360', 'IDR', 'Rupiah', 2)\n")
2959 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('364', 'IRR', 'Iranian Rial', 2)\n")
2960 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('368', 'IQD', 'Iraqi Dinar', 3)\n")
2961 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('376', 'ILS', 'New Israeli Sheqel', 2)\n")
2962 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('388', 'JMD', 'Jamaican Dollar', 2)\n")
2963 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('392', 'JPY', 'Yen', 0)\n")
2964 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('398', 'KZT', 'Tenge', 2)\n")
2965 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('400', 'JOD', 'Jordanian Dinar', 3)\n")
2966 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('404', 'KES', 'Kenyan Shilling', 2)\n")
2967 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('408', 'KPW', 'North Korean Won', 2)\n")
2968 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('410', 'KRW', 'Won', 0)\n")
2969 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('414', 'KWD', 'Kuwaiti Dinar', 3)\n")
2970 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('417', 'KGS', 'Som', 2)\n")
2971 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('418', 'LAK', 'Kip', 2)\n")
2972 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('422', 'LBP', 'Lebanese Pound', 2)\n")
2973 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('426', 'LSL', 'Lesotho Loti', 2)\n")
2974 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('428', 'LVL', 'Latvian Lats', 2)\n")
2975 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('430', 'LRD', 'Liberian Dollar', 2)\n")
2976 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('434', 'LYD', 'Lybian Dinar', 3)\n")
2977 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('440', 'LTL', 'Lithuanian Litas', 2)\n")
2978 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('446', 'MOP', 'Pataca', 2)\n")
2979 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('450', 'MGF', 'Malagasy Franc', 0)\n")
2980 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('454', 'MWK', 'Kwacha', 2)\n")
2981 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('458', 'MYR', 'Malaysian Ringgit', 2)\n")
2982 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('462', 'MVR', 'Rufiyaa', 2)\n")
2983 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('470', 'MTL', 'Maltese Lira', 0)\n")
2984 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('478', 'MRO', 'Ouguiya', 2)\n")
2985 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('480', 'MUR', 'Mauritius Rupee', 2)\n")
2986 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('484', 'MXN', 'Mexican Peso', 2)\n")
2987 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('496', 'MNT', 'Tugrik', 2)\n")
2988 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('498', 'MDL', 'Moldovan Leu', 2)\n")
2989 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('504', 'MAD', 'Moroccan Dirham', 2)\n")
2990 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('508', 'MZM', 'Metical', 0)\n")
2991 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('512', 'OMR', 'Rial Omani', 3)\n")
2992 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('516', 'NAD', 'Namibia Dollar', 2)\n")
2993 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('524', 'NPR', 'Nepalese Rupee', 2)\n")
2994 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('532', 'ANG', 'Netherlands Antillan Guilder', 2)\n")
2995 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('533', 'AWG', 'Aruban Guilder', 2)\n")
2996 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('548', 'VUV', 'Vatu', 0)\n")
2997 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('554', 'NZD', 'New Zealand Dollar', 2)\n")
2998 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('558', 'NIO', 'Cordoba Oro', 2)\n")
2999 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('566', 'NGN', 'Naira', 2)\n")
3000 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('578', 'NOK', 'Norvegian Krone', 2)\n")
3001 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('586', 'PKR', 'Pakistan Rupee', 2)\n")
3002 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('590', 'PAB', 'Balboa', 2)\n")
3003 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('598', 'PGK', 'Kina', 2)\n")
3004 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('600', 'PYG', 'Guarani', 0)\n")
3005 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('604', 'PEN', 'Nuevo Sol', 2)\n")
3006 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('608', 'PHP', 'Philippine Peso', 2)\n")
3007 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('624', 'GWP', 'Guinea-Bissau Peso', 0)\n")
3008 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('634', 'QAR', 'Qatari Rial', 2)\n")
3009 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('642', 'ROL', 'Leu', 0)\n")
3010 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('643', 'RUB', 'Russian Ruble', 2)\n")
3011 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('646', 'RWF', 'Rwanda Franc', 0)\n")
3012 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('654', 'SHP', 'Saint Helena Pound', 2)\n")
3013 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('678', 'STD', 'Dobra', 2)\n")
3014 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('682', 'SAR', 'Saudi Riyal', 2)\n")
3015 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('690', 'SCR', 'Seychelles Rupee', 2)\n")
3016 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('694', 'SLL', 'Leone', 2)\n")
3017 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('702', 'SGD', 'Singapore Dollar', 2)\n")
3018 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('703', 'SKK', 'Slovak Koruna', 0)\n")
3019 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('704', 'VND', 'Dong', 0)\n")
3020 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('706', 'SOS', 'Somali Shilling', 2)\n")
3021 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('710', 'ZAR', 'Rand', 2)\n")
3022 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('716', 'ZWD', 'Zimbabwe Dollar', 0)\n")
3023 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('728', 'SSP', 'South Sudanese pound', 2)\n")
3024 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('740', 'SRG', 'Suriname Guilder', 0)\n")
3025 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('748', 'SZL', 'Lilangeni', 2)\n")
3026 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('752', 'SEK', 'Swedish Krona', 2)\n")
3027 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('756', 'CHF', 'Swiss Franc', 2)\n")
3028 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('760', 'SYP', 'Syrian Pound', 2)\n")
3029 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('764', 'THB', 'Baht', 2)\n")
3030 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('776', 'TOP', 'Paanga', 2)\n")
3031 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('780', 'TTD', 'Trinidad and Tobago Dollar', 2)\n")
3032 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('784', 'AED', 'UAE Dirham', 2)\n")
3033 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('788', 'TND', 'Tunisian Dinar', 3)\n")
3034 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('795', 'TMM', 'Manat', 0)\n")
3035 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('800', 'UGX', 'Uganda Shilling', 2)\n")
3036 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('807', 'MKD', 'Denar', 2)\n")
3037 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('810', 'RUR', 'Russian Ruble', 0)\n")
3038 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('818', 'EGP', 'Egyptian Pound', 2)\n")
3039 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('826', 'GBP', 'Pound Sterling', 2)\n")
3040 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('834', 'TZS', 'Tanzanian Shilling', 2)\n")
3041 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('840', 'USD', 'US Dollar', 2)\n")
3042 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('858', 'UYU', 'Peso Uruguayo', 2)\n")
3043 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('860', 'UZS', 'Uzbekistan Sum', 2)\n")
3044 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('862', 'VEB', 'Bolivar', 0)\n")
3045 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('882', 'WST', 'Tala', 2)\n")
3046 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('886', 'YER', 'Yemeni Rial', 2)\n")
3047 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('891', 'CSD', 'Serbian Dinar', 0)\n")
3048 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('894', 'ZMK', 'Kwacha', 2)\n")
3049 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('901', 'TWD', 'New Taiwan Dollar', 2)\n")
3050 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('933', 'BYN', 'Belarussian New Ruble', 2)\n")
3051 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('934', 'TMT', 'Turkmenistani Manat', 2)\n")
3052 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('937', 'VEF', 'Venezuelan Bolivar', 2)\n")
3053 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('938', 'SDG', 'Sudanese Pound', 2)\n")
3054 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('941', 'RSD', 'Serbian Dinar', 2)\n")
3055 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('943', 'MZN', 'Mozambican Metical', 2)\n")
3056 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('944', 'AZN', 'Azerbaijani Manat', 2)\n")
3057 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('946', 'RON', 'New Romanian Leu', 2)\n")
3058 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('949', 'TRY', 'New Turkish Lira', 2)\n")
3059 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('950', 'XAF', 'CFA Franc BEAC', 0)\n")
3060 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('951', 'XCD', 'East Carribbean Dollar', 2)\n")
3061 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('952', 'XOF', 'CFA Franc BCEAO', 0)\n")
3062 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('953', 'XPF', 'CFP Franc', 0)\n")
3063 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('967', 'ZMW', 'Zambian Kwacha', 2)\n")
3064 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('968', 'SRD', 'Surinamese Dollar', 2)\n")
3065 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('969', 'MGA', 'Malagasy Ariary', 2)\n")
3066 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('971', 'AFN', 'Afghani', 2)\n")
3067 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('972', 'TJS', 'Somoni', 2)\n")
3068 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('973', 'AOA', 'Kwanza', 2)\n")
3069 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('974', 'BYR', 'Belarussian Ruble', 0)\n")
3070 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('975', 'BGN', 'Bulgarian Lev', 2)\n")
3071 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('976', 'CDF', 'Franc Congolais', 2)\n")
3072 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('977', 'BAM', 'Convertible Marks', 2)\n")
3073 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('978', 'EUR', 'Euro', 2)\n")
3074 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('979', 'MXV', 'Mexican Unidad de Inversion (UDI)', 2)\n")
3075 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('980', 'UAH', 'Hryvnia', 2)\n")
3076 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('981', 'GEL', 'Lari', 2)\n")
3077 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('984', 'BOV', 'Mvdol', 2)\n")
3078 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('985', 'PLN', 'Zloty', 2)\n")
3079 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('986', 'BRL', 'Brazilian Real', 2)\n")
3080 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('990', 'CLF', 'Unidades de Fomento', 0)\n")
3081 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('997', 'USN', 'US dollar (next day funds code)', 2)\n")
3082 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('998', 'USS', 'US dollar (same day funds code)', 2)\n")
3083 _T("INSERT INTO currency_codes (numeric_code, alpha_code, description, exponent) VALUES ('999', 'XXX', 'No currency', 0)\n")
dc4472a5
VK
3084 _T("<END>");
3085 static const TCHAR *batch2 =
0de31ec3
VK
3086 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AD','AND','020','Andorra')\n")
3087 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AE','ARE','784','United Arab Emirates')\n")
3088 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AF','AFG','004','Afghanistan')\n")
3089 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AG','ATG','028','Antigua and Barbuda')\n")
3090 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AI','AIA','660','Anguilla')\n")
3091 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AL','ALB','008','Albania')\n")
3092 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AM','ARM','051','Armenia')\n")
3093 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AN','ANT','530','Netherlands Antilles')\n")
3094 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AO','AGO','024','Angola')\n")
3095 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AQ','ATA','010','Antarctica')\n")
3096 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AR','ARG','032','Argentina')\n")
3097 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AS','ASM','016','American Samoa')\n")
3098 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AT','AUT','040','Austria')\n")
3099 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AU','AUS','036','Australia')\n")
3100 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AW','ABW','533','Aruba')\n")
3101 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AX','ALA','248','Aland Islands')\n")
3102 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('AZ','AZE','031','Azerbaijan')\n")
3103 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BA','BIH','070','Bosnia and Herzegovina')\n")
3104 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BB','BRB','052','Barbados')\n")
3105 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BD','BGD','050','Bangladesh')\n")
3106 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BE','BEL','056','Belgium')\n")
3107 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BF','BFA','854','Burkina Faso')\n")
3108 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BG','BGR','100','Bulgaria')\n")
3109 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BH','BHR','048','Bahrain')\n")
3110 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BI','BDI','108','Burundi')\n")
3111 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BJ','BEN','204','Benin')\n")
3112 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BL','BLM','652','Saint-Barthelemy')\n")
3113 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BM','BMU','060','Bermuda')\n")
3114 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BN','BRN','096','Brunei Darussalam')\n")
3115 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BO','BOL','068','Bolivia')\n")
3116 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BQ','BES','535','Bonaire, Sint Eustatius and Saba')\n")
3117 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BR','BRA','076','Brazil')\n")
3118 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BS','BHS','044','Bahamas')\n")
3119 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BT','BTN','064','Bhutan')\n")
3120 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BV','BVT','074','Bouvet Island')\n")
3121 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BW','BWA','072','Botswana')\n")
3122 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BY','BLR','112','Belarus')\n")
3123 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('BZ','BLZ','084','Belize')\n")
3124 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CA','CAN','124','Canada')\n")
3125 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CC','CCK','166','Cocos (Keeling) Islands')\n")
3126 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CD','COD','180','Congo, Democratic Republic of the')\n")
3127 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CF','CAF','140','Central African Republic')\n")
3128 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CG','COG','178','Congo (Brazzaville)')\n")
3129 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CH','CHE','756','Switzerland')\n")
3130 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CI','CIV','384','Cote d''Ivoire')\n")
3131 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CK','COK','184','Cook Islands')\n")
3132 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CL','CHL','152','Chile')\n")
3133 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CM','CMR','120','Cameroon')\n")
3134 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CN','CHN','156','China')\n")
3135 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CO','COL','170','Colombia')\n")
3136 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CR','CRI','188','Costa Rica')\n")
3137 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CU','CUB','192','Cuba')\n")
3138 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CV','CPV','132','Cape Verde')\n")
3139 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CW','CUW','531','Curacao')\n")
3140 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CX','CXR','162','Christmas Island')\n")
3141 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CY','CYP','196','Cyprus')\n")
3142 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('CZ','CZE','203','Czech Republic')\n")
3143 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('DE','DEU','276','Germany')\n")
3144 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('DJ','DJI','262','Djibouti')\n")
3145 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('DK','DNK','208','Denmark')\n")
3146 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('DM','DMA','212','Dominica')\n")
3147 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('DO','DOM','214','Dominican Republic')\n")
3148 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('DZ','DZA','012','Algeria')\n")
3149 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('EC','ECU','218','Ecuador')\n")
3150 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('EE','EST','233','Estonia')\n")
3151 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('EG','EGY','818','Egypt')\n")
3152 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('EH','ESH','732','Western Sahara')\n")
3153 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('ER','ERI','232','Eritrea')\n")
3154 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('ES','ESP','724','Spain')\n")
3155 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('ET','ETH','231','Ethiopia')\n")
3156 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('FI','FIN','246','Finland')\n")
3157 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('FJ','FJI','242','Fiji')\n")
3158 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('FK','FLK','238','Falkland Islands (Malvinas)')\n")
3159 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('FM','FSM','583','Micronesia, Federated States of')\n")
3160 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('FO','FRO','234','Faroe Islands')\n")
3161 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('FR','FRA','250','France')\n")
3162 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GA','GAB','266','Gabon')\n")
3163 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GB','GBR','826','United Kingdom')\n")
3164 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GD','GRD','308','Grenada')\n")
3165 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GE','GEO','268','Georgia')\n")
3166 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GF','GUF','254','French Guiana')\n")
3167 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GG','GGY','831','Guernsey')\n")
3168 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GH','GHA','288','Ghana')\n")
3169 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GI','GIB','292','Gibraltar')\n")
3170 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GL','GRL','304','Greenland')\n")
3171 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GM','GMB','270','Gambia')\n")
3172 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GN','GIN','324','Guinea')\n")
3173 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GP','GLP','312','Guadeloupe')\n")
3174 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GQ','GNQ','226','Equatorial Guinea')\n")
3175 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GR','GRC','300','Greece')\n")
3176 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GS','SGS','239','South Georgia and the South Sandwich Islands')\n")
3177 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GT','GTM','320','Guatemala')\n")
3178 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GU','GUM','316','Guam')\n")
3179 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GW','GNB','624','Guinea-Bissau')\n")
3180 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('GY','GUY','328','Guyana')\n")
3181 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('HK','HKG','344','Hong Kong, Special Administrative Region of China')\n")
3182 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('HM','HMD','334','Heard Island and Mcdonald Islands')\n")
3183 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('HN','HND','340','Honduras')\n")
3184 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('HR','HRV','191','Croatia')\n")
3185 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('HT','HTI','332','Haiti')\n")
3186 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('HU','HUN','348','Hungary')\n")
3187 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('ID','IDN','360','Indonesia')\n")
3188 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('IE','IRL','372','Ireland')\n")
3189 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('IL','ISR','376','Israel')\n")
3190 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('IM','IMN','833','Isle of Man')\n")
3191 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('IN','IND','356','India')\n")
3192 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('IO','IOT','086','British Indian Ocean Territory')\n")
3193 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('IQ','IRQ','368','Iraq')\n")
3194 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('IR','IRN','364','Iran, Islamic Republic of')\n")
3195 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('IS','ISL','352','Iceland')\n")
3196 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('IT','ITA','380','Italy')\n")
3197 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('JE','JEY','832','Jersey')\n")
3198 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('JM','JAM','388','Jamaica')\n")
3199 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('JO','JOR','400','Jordan')\n")
3200 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('JP','JPN','392','Japan')\n")
3201 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KE','KEN','404','Kenya')\n")
3202 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KG','KGZ','417','Kyrgyzstan')\n")
3203 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KH','KHM','116','Cambodia')\n")
3204 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KI','KIR','296','Kiribati')\n")
3205 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KM','COM','174','Comoros')\n")
3206 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KN','KNA','659','Saint Kitts and Nevis')\n")
3207 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KP','PRK','408','Korea, Democratic People''s Republic of')\n")
3208 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KR','KOR','410','Korea, Republic of')\n")
3209 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KW','KWT','414','Kuwait')\n")
3210 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KY','CYM','136','Cayman Islands')\n")
3211 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('KZ','KAZ','398','Kazakhstan')\n")
3212 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LA','LAO','418','Lao PDR')\n")
3213 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LB','LBN','422','Lebanon')\n")
3214 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LC','LCA','662','Saint Lucia')\n")
3215 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LI','LIE','438','Liechtenstein')\n")
3216 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LK','LKA','144','Sri Lanka')\n")
3217 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LR','LBR','430','Liberia')\n")
3218 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LS','LSO','426','Lesotho')\n")
3219 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LT','LTU','440','Lithuania')\n")
3220 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LU','LUX','442','Luxembourg')\n")
3221 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LV','LVA','428','Latvia')\n")
3222 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('LY','LBY','434','Libya')\n")
3223 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MA','MAR','504','Morocco')\n")
3224 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MC','MCO','492','Monaco')\n")
3225 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MD','MDA','498','Moldova')\n")
3226 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('ME','MNE','499','Montenegro')\n")
3227 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MF','MAF','663','Saint-Martin (French part)')\n")
3228 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MG','MDG','450','Madagascar')\n")
3229 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MH','MHL','584','Marshall Islands')\n")
3230 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MK','MKD','807','Macedonia, Republic of')\n")
3231 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('ML','MLI','466','Mali')\n")
3232 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MM','MMR','104','Myanmar')\n")
3233 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MN','MNG','496','Mongolia')\n")
3234 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MO','MAC','446','Macao, Special Administrative Region of China')\n")
3235 _T("INSERT INTO country_codes (alpha_code,alpha3_code,numeric_code,name) VALUES ('MP','MNP','580','Northern Mariana Islands')\n")