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