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