cosmetic change
[public/netxms.git] / src / server / tools / nxdbmgr / upgrade.cpp
CommitLineData
5039dede
AK
1/*
2** nxdbmgr - NetXMS database manager
480e036b 3** Copyright (C) 2004-2013 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"
24
4f50e45c
VK
25/**
26 * Externals
27 */
7a41a06e
VK
28BOOL MigrateMaps();
29
4f50e45c
VK
30/**
31 * Create table
32 */
5039dede
AK
33static BOOL CreateTable(const TCHAR *pszQuery)
34{
5039dede 35 BOOL bResult;
7618e362 36 String query(pszQuery);
5039dede 37
6bcafa2d
VK
38 query.replace(_T("$SQL:TEXT"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT]);
39 query.replace(_T("$SQL:TXT4K"), g_pszSqlType[g_iSyntax][SQL_TYPE_TEXT4K]);
40 query.replace(_T("$SQL:INT64"), g_pszSqlType[g_iSyntax][SQL_TYPE_INT64]);
5039dede 41 if (g_iSyntax == DB_SYNTAX_MYSQL)
7618e362
VK
42 query += g_pszTableSuffix;
43 bResult = SQLQuery(query);
5039dede
AK
44 return bResult;
45}
46
4f50e45c
VK
47/**
48 * Create configuration parameter if it doesn't exist (unless bForceUpdate set to true)
49 */
a43a5e7d
VK
50BOOL CreateConfigParam(const TCHAR *pszName, const TCHAR *pszValue,
51 int iVisible, int iNeedRestart, BOOL bForceUpdate)
5039dede 52{
42475f3e 53 TCHAR szQuery[1024];
5039dede
AK
54 DB_RESULT hResult;
55 BOOL bVarExist = FALSE, bResult = TRUE;
56
57 // Check for variable existence
08b214c6 58 _sntprintf(szQuery, 1024, _T("SELECT var_value FROM config WHERE var_name='%s'"), pszName);
5039dede
AK
59 hResult = DBSelect(g_hCoreDB, szQuery);
60 if (hResult != 0)
61 {
62 if (DBGetNumRows(hResult) > 0)
63 bVarExist = TRUE;
64 DBFreeResult(hResult);
65 }
66
67 if (!bVarExist)
68 {
08b214c6 69 _sntprintf(szQuery, 1024, _T("INSERT INTO config (var_name,var_value,is_visible,")
42475f3e
VK
70 _T("need_server_restart) VALUES (%s,%s,%d,%d)"),
71 (const TCHAR *)DBPrepareString(g_hCoreDB, pszName, 63),
72 (const TCHAR *)DBPrepareString(g_hCoreDB, pszValue, 255), iVisible, iNeedRestart);
5039dede
AK
73 bResult = SQLQuery(szQuery);
74 }
75 else if (bForceUpdate)
76 {
42475f3e
VK
77 _sntprintf(szQuery, 1024, _T("UPDATE config SET var_value=%s WHERE var_name=%s"),
78 (const TCHAR *)DBPrepareString(g_hCoreDB, pszValue, 255), (const TCHAR *)DBPrepareString(g_hCoreDB, pszName, 63));
5039dede
AK
79 bResult = SQLQuery(szQuery);
80 }
81 return bResult;
82}
83
4f50e45c
VK
84/**
85 * Set primary key constraint
86 */
5039dede
AK
87static BOOL SetPrimaryKey(const TCHAR *table, const TCHAR *key)
88{
89 TCHAR query[4096];
90
91 if (g_iSyntax == DB_SYNTAX_SQLITE)
92 return TRUE; // SQLite does not support adding constraints
93
94 _sntprintf(query, 4096, _T("ALTER TABLE %s ADD PRIMARY KEY (%s)"), table, key);
95 return SQLQuery(query);
96}
97
4f50e45c
VK
98/**
99 * Drop primary key from table
100 */
9bfc9a6b
VK
101static BOOL DropPrimaryKey(const TCHAR *table)
102{
103 TCHAR query[1024];
104 DB_RESULT hResult;
105 BOOL success;
106
107 switch(g_iSyntax)
108 {
109 case DB_SYNTAX_ORACLE:
110 case DB_SYNTAX_MYSQL:
111 _sntprintf(query, 1024, _T("ALTER TABLE %s DROP PRIMARY KEY"), table);
112 success = SQLQuery(query);
113 break;
114 case DB_SYNTAX_PGSQL:
115 _sntprintf(query, 1024, _T("ALTER TABLE %s DROP CONSTRAINT %s_pkey"), table, table);
116 success = SQLQuery(query);
117 break;
118 case DB_SYNTAX_MSSQL:
119 success = FALSE;
120 _sntprintf(query, 1024, _T("SELECT name FROM sysobjects WHERE xtype='PK' AND parent_obj=OBJECT_ID('%s')"), table);
121 hResult = SQLSelect(query);
122 if (hResult != NULL)
123 {
124 if (DBGetNumRows(hResult) > 0)
125 {
126 TCHAR objName[512];
127
128 DBGetField(hResult, 0, 0, objName, 512);
129 _sntprintf(query, 1024, _T("ALTER TABLE %s DROP CONSTRAINT %s"), table, objName);
130 success = SQLQuery(query);
131 }
132 DBFreeResult(hResult);
133 }
134 break;
135 default: // Unsupported DB engine
136 success = FALSE;
137 break;
138 }
139 return success;
140}
141
4f50e45c
VK
142/**
143 * Convert strings from # encoded form to normal form
144 */
d6bf58f9 145static BOOL ConvertStrings(const TCHAR *table, const TCHAR *idColumn, const TCHAR *idColumn2, const TCHAR *column, bool isStringId)
643c9dcb
VK
146{
147 DB_RESULT hResult;
148 TCHAR *query;
149 int queryLen = 512;
150 BOOL success = FALSE;
151
c29fb885 152 query = (TCHAR *)malloc(queryLen * sizeof(TCHAR));
fe12a1ea 153
a4743a0f
VK
154 switch(g_iSyntax)
155 {
156 case DB_SYNTAX_MSSQL:
9f6712bc 157 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE CAST(%s AS nvarchar(4000))=N'#00'"), table, column, column);
a4743a0f
VK
158 break;
159 case DB_SYNTAX_ORACLE:
160 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE to_char(%s)='#00'"), table, column, column);
161 break;
162 default:
163 _sntprintf(query, queryLen, _T("UPDATE %s SET %s='' WHERE %s='#00'"), table, column, column);
164 break;
165 }
fe12a1ea
VK
166 if (!SQLQuery(query))
167 {
168 free(query);
169 return FALSE;
170 }
171
98cd01bb
VK
172 _sntprintf(query, queryLen, _T("SELECT %s,%s%s%s FROM %s WHERE %s LIKE '%%#%%'"),
173 idColumn, column, (idColumn2 != NULL) ? _T(",") : _T(""), (idColumn2 != NULL) ? idColumn2 : _T(""), table, column);
643c9dcb
VK
174 hResult = SQLSelect(query);
175 if (hResult == NULL)
176 {
177 free(query);
178 return FALSE;
179 }
180
181 int count = DBGetNumRows(hResult);
182 for(int i = 0; i < count; i++)
183 {
643c9dcb 184 TCHAR *value = DBGetField(hResult, i, 1, NULL, 0);
035a4d73 185 if (_tcschr(value, _T('#')) != NULL)
643c9dcb 186 {
035a4d73
VK
187 DecodeSQLString(value);
188 String newValue = DBPrepareString(g_hCoreDB, value);
189 if ((int)newValue.getSize() + 256 > queryLen)
190 {
191 queryLen = newValue.getSize() + 256;
c29fb885 192 query = (TCHAR *)realloc(query, queryLen * sizeof(TCHAR));
035a4d73 193 }
d6bf58f9 194 if (isStringId)
98cd01bb 195 {
d6bf58f9
VK
196 TCHAR *id = DBGetField(hResult, i, 0, NULL, 0);
197 if (idColumn2 != NULL)
198 {
199 TCHAR *id2 = DBGetField(hResult, i, 2, NULL, 0);
200 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=%s AND %s=%s"),
201 table, column, (const TCHAR *)newValue,
202 idColumn, (const TCHAR *)DBPrepareString(g_hCoreDB, id),
203 idColumn2, (const TCHAR *)DBPrepareString(g_hCoreDB, id2));
204 }
205 else
206 {
207 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=%s"), table, column,
208 (const TCHAR *)newValue, idColumn, (const TCHAR *)DBPrepareString(g_hCoreDB, id));
209 }
210 free(id);
98cd01bb
VK
211 }
212 else
213 {
d6bf58f9
VK
214 INT64 id = DBGetFieldInt64(hResult, i, 0);
215 if (idColumn2 != NULL)
216 {
217 INT64 id2 = DBGetFieldInt64(hResult, i, 2);
218 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=") INT64_FMT _T(" AND %s=") INT64_FMT,
219 table, column, (const TCHAR *)newValue, idColumn, id, idColumn2, id2);
220 }
221 else
222 {
223 _sntprintf(query, queryLen, _T("UPDATE %s SET %s=%s WHERE %s=") INT64_FMT, table, column,
224 (const TCHAR *)newValue, idColumn, id);
225 }
98cd01bb 226 }
035a4d73
VK
227 if (!SQLQuery(query))
228 goto cleanup;
643c9dcb 229 }
643c9dcb
VK
230 }
231 success = TRUE;
232
233cleanup:
234 DBFreeResult(hResult);
a4743a0f 235 free(query);
643c9dcb
VK
236 return success;
237}
238
98cd01bb
VK
239static BOOL ConvertStrings(const TCHAR *table, const TCHAR *idColumn, const TCHAR *column)
240{
d6bf58f9 241 return ConvertStrings(table, idColumn, NULL, column, false);
98cd01bb
VK
242}
243
4f50e45c 244/**
70ffb771 245 * Set column nullable (currently only Oracle and PostgreSQL)
4f50e45c 246 */
480e036b 247static BOOL SetColumnNullable(const TCHAR *table, const TCHAR *column)
1024e962
VK
248{
249 TCHAR query[1024] = _T("");
250
251 switch(g_iSyntax)
252 {
253 case DB_SYNTAX_ORACLE:
254 _sntprintf(query, 1024, _T("DECLARE already_null EXCEPTION; ")
255 _T("PRAGMA EXCEPTION_INIT(already_null, -1451); ")
f57209fd
VK
256 _T("BEGIN EXECUTE IMMEDIATE 'ALTER TABLE %s MODIFY %s null'; ")
257 _T("EXCEPTION WHEN already_null THEN null; END;"), table, column);
1024e962 258 break;
480e036b
VK
259 case DB_SYNTAX_PGSQL:
260 _sntprintf(query, 1024, _T("ALTER TABLE %s ALTER COLUMN %s DROP NOT NULL"), table, column);
261 break;
1024e962
VK
262 default:
263 break;
264 }
265
266 return (query[0] != 0) ? SQLQuery(query) : TRUE;
267}
268
480e036b
VK
269/**
270 * Resize varchar column
271 */
272static BOOL ResizeColumn(const TCHAR *table, const TCHAR *column, int newSize)
273{
274 TCHAR query[1024];
275
276 switch(g_iSyntax)
277 {
278 case DB_SYNTAX_DB2:
279 _sntprintf(query, 1024, _T("ALTER TABLE %s ALTER COLUMN %s SET DATA TYPE varchar(%d)"), table, column, newSize);
280 break;
281 case DB_SYNTAX_MSSQL:
282 _sntprintf(query, 1024, _T("ALTER TABLE %s ALTER COLUMN %s varchar(%d)"), table, column, newSize);
283 break;
284 case DB_SYNTAX_PGSQL:
285 _sntprintf(query, 1024, _T("ALTER TABLE %s ALTER COLUMN %s TYPE varchar(%d)"), table, column, newSize);
286 break;
287 case DB_SYNTAX_SQLITE:
288 /* TODO: add SQLite support */
289 query[0] = 0;
290 break;
291 default:
292 _sntprintf(query, 1024, _T("ALTER TABLE %s MODIFY %s varchar(%d)"), table, column, newSize);
293 break;
294 }
295
296 return (query[0] != 0) ? SQLQuery(query) : TRUE;
297}
298
4f50e45c
VK
299/**
300 * Create new event template
301 */
aa16f82b
VK
302static BOOL CreateEventTemplate(int code, const TCHAR *name, int severity, int flags, const TCHAR *message, const TCHAR *description)
303{
480e036b 304 TCHAR query[4096];
aa16f82b 305
480e036b
VK
306 _sntprintf(query, 4096, _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES (%d,'%s',%d,%d,%s,%s)"),
307 code, name, severity, flags, (const TCHAR *)DBPrepareString(g_hCoreDB, message),
308 (const TCHAR *)DBPrepareString(g_hCoreDB, description));
aa16f82b
VK
309 return SQLQuery(query);
310}
311
22aaa779
VK
312/**
313 * Re-create TDATA tables
314 */
1d4f7890 315static BOOL RecreateTData(const TCHAR *className, bool multipleTables)
22aaa779 316{
1d4f7890 317 TCHAR query[1024];
22aaa779
VK
318 _sntprintf(query, 256, _T("SELECT id FROM %s"), className);
319 DB_RESULT hResult = SQLSelect(query);
320 if (hResult != NULL)
321 {
322 int count = DBGetNumRows(hResult);
323 for(int i = 0; i < count; i++)
324 {
325 DWORD id = DBGetFieldULong(hResult, i, 0);
326
1d4f7890
VK
327 if (multipleTables)
328 {
329 _sntprintf(query, 1024, _T("DROP TABLE tdata_rows_%d\nDROP TABLE tdata_records_%d\nDROP TABLE tdata_%d\n<END>"), id, id, id);
330 }
331 else
332 {
333 _sntprintf(query, 256, _T("DROP TABLE tdata_%d\n<END>"), id);
334 }
335 if (!SQLBatch(query))
22aaa779
VK
336 {
337 if (!g_bIgnoreErrors)
338 {
339 DBFreeResult(hResult);
340 return FALSE;
341 }
342 }
343
344 if (!CreateTDataTables(id))
345 {
346 if (!g_bIgnoreErrors)
347 {
348 DBFreeResult(hResult);
349 return FALSE;
350 }
351 }
352 }
353 DBFreeResult(hResult);
354 }
355 else
356 {
357 if (!g_bIgnoreErrors)
358 return FALSE;
359 }
360 return TRUE;
361}
362
27088c41
AK
363/**
364 * Upgrade from V301 to V302
365 */
366static BOOL H_UpgradeFromV301(int currVersion, int newVersion)
367{
368 static TCHAR batch[] =
369 _T("DELETE FROM config WHERE var_name='DisableVacuum'\n")
370 _T("<END>");
371 CHK_EXEC(SQLBatch(batch));
372
373 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='302' WHERE var_name='SchemaVersion'")));
374 return TRUE;
375}
376
1d34c533
VK
377/**
378 * Upgrade from V300 to V301
379 */
380static BOOL H_UpgradeFromV300(int currVersion, int newVersion)
381{
382 static TCHAR batch[] =
383 _T("ALTER TABLE thresholds ADD script $SQL:TEXT\n")
384 _T("ALTER TABLE thresholds ADD sample_count integer\n")
385 _T("UPDATE thresholds SET sample_count=parameter_1\n")
386 _T("ALTER TABLE thresholds DROP COLUMN parameter_1\n")
387 _T("ALTER TABLE thresholds DROP COLUMN parameter_2\n")
388 _T("<END>");
389 CHK_EXEC(SQLBatch(batch));
390
391 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='301' WHERE var_name='SchemaVersion'")));
392 return TRUE;
393}
394
244c65ef
VK
395/**
396 * Upgrade from V299 to V300
397 */
398static BOOL H_UpgradeFromV299(int currVersion, int newVersion)
399{
400 CHK_EXEC(CreateConfigParam(_T("EnableXMPPConnector"), _T("0"), 1, 1));
401 CHK_EXEC(CreateConfigParam(_T("XMPPLogin"), _T("netxms@localhost"), 1, 1));
402 CHK_EXEC(CreateConfigParam(_T("XMPPPassword"), _T("netxms"), 1, 1));
403 CHK_EXEC(CreateConfigParam(_T("XMPPServer"), _T("localhost"), 1, 1));
404 CHK_EXEC(CreateConfigParam(_T("XMPPPort"), _T("5222"), 1, 1));
405
406 SetColumnNullable(_T("users"), _T("full_name"));
407 SetColumnNullable(_T("users"), _T("description"));
408 SetColumnNullable(_T("users"), _T("cert_mapping_data"));
409 SetColumnNullable(_T("user_groups"), _T("description"));
410 SetColumnNullable(_T("userdb_custom_attributes"), _T("attr_value"));
411
412 ConvertStrings(_T("users"), _T("id"), _T("full_name"));
413 ConvertStrings(_T("users"), _T("id"), _T("description"));
414 ConvertStrings(_T("users"), _T("id"), _T("cert_mapping_data"));
415 ConvertStrings(_T("user_groups"), _T("id"), _T("description"));
416 ConvertStrings(_T("userdb_custom_attributes"), _T("object_id"), _T("attr_name"), _T("attr_name"), true);
417 ConvertStrings(_T("userdb_custom_attributes"), _T("object_id"), _T("attr_name"), _T("attr_value"), true);
418
419 CHK_EXEC(SQLQuery(_T("ALTER TABLE users ADD xmpp_id varchar(127)")));
420
421 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='300' WHERE var_name='SchemaVersion'")));
422 return TRUE;
423}
424
ce47611c
VK
425/**
426 * Upgrade from V298 to V299
427 */
428static BOOL H_UpgradeFromV298(int currVersion, int newVersion)
429{
430 CHK_EXEC(SQLQuery(_T("UPDATE event_cfg SET message='Subnet %2 added',description='")
431 _T("Generated when subnet object added to the database.\r\n")
432 _T("Parameters:\r\n")
433 _T(" 1) Subnet object ID\r\n")
434 _T(" 2) Subnet name\r\n")
435 _T(" 3) IP address\r\n")
436 _T(" 4) Network mask")
437 _T("' WHERE event_code=2")));
438 CHK_EXEC(SQLQuery(_T("UPDATE event_cfg SET message='Subnet %2 deleted',description='")
439 _T("Generated when subnet object deleted from the database.\r\n")
440 _T("Parameters:\r\n")
441 _T(" 1) Subnet object ID\r\n")
442 _T(" 2) Subnet name\r\n")
443 _T(" 3) IP address\r\n")
444 _T(" 4) Network mask")
445 _T("' WHERE event_code=19")));
446 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='299' WHERE var_name='SchemaVersion'")));
447 return TRUE;
448}
449
af21affe
VK
450/**
451 * Upgrade from V297 to V298
452 */
453static BOOL H_UpgradeFromV297(int currVersion, int newVersion)
454{
455 CHK_EXEC(CreateConfigParam(_T("AgentDefaultSharedSecret"), _T("netxms"), 1, 0));
456 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='298' WHERE var_name='SchemaVersion'")));
457 return TRUE;
458}
459
e02953a4
VK
460/**
461 * Upgrade from V296 to V297
462 */
463static BOOL H_UpgradeFromV296(int currVersion, int newVersion)
464{
465 CHK_EXEC(CreateConfigParam(_T("UseSNMPTrapsForDiscovery"), _T("0"), 1, 1));
466 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='297' WHERE var_name='SchemaVersion'")));
467 return TRUE;
468}
469
71e4ed3a
VK
470/**
471 * Upgrade from V295 to V296
472 */
473static BOOL H_UpgradeFromV295(int currVersion, int newVersion)
474{
475 static TCHAR batch[] =
476 _T("ALTER TABLE nodes ADD boot_time integer\n")
477 _T("UPDATE nodes SET boot_time=0\n")
478 _T("<END>");
479 CHK_EXEC(SQLBatch(batch));
480
481 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='296' WHERE var_name='SchemaVersion'")));
482 return TRUE;
483}
484
c59466d2
VK
485/**
486 * Upgrade from V294 to V295
487 */
488static BOOL H_UpgradeFromV294(int currVersion, int newVersion)
489{
490 CHK_EXEC(CreateConfigParam(_T("IcmpPingTimeout"), _T("1500"), 1, 1));
491 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='295' WHERE var_name='SchemaVersion'")));
492 return TRUE;
493}
494
1d4f7890
VK
495/**
496 * Upgrade from V293 to V294
497 */
498static BOOL H_UpgradeFromV293(int currVersion, int newVersion)
499{
500 static TCHAR batch[] =
501 _T("DELETE FROM metadata WHERE var_name LIKE 'TDataTableCreationCommand_%'\n")
502 _T("INSERT INTO metadata (var_name,var_value)")
503 _T(" VALUES ('TDataTableCreationCommand_0','CREATE TABLE tdata_%d (item_id integer not null,tdata_timestamp integer not null,record_id $SQL:INT64 not null,UNIQUE(record_id))')\n")
504 _T("INSERT INTO metadata (var_name,var_value)")
505 _T(" VALUES ('TDataTableCreationCommand_1','CREATE TABLE tdata_records_%d (record_id $SQL:INT64 not null,row_id $SQL:INT64 not null,instance varchar(255) null,PRIMARY KEY(row_id),FOREIGN KEY (record_id) REFERENCES tdata_%d(record_id) ON DELETE CASCADE)')\n")
506 _T("INSERT INTO metadata (var_name,var_value)")
507 _T(" VALUES ('TDataTableCreationCommand_2','CREATE TABLE tdata_rows_%d (row_id $SQL:INT64 not null,column_id integer not null,value varchar(255) null,PRIMARY KEY(row_id,column_id),FOREIGN KEY (row_id) REFERENCES tdata_records_%d(row_id) ON DELETE CASCADE)')\n")
508 _T("<END>");
509 CHK_EXEC(SQLBatch(batch));
510
511 RecreateTData(_T("nodes"), true);
512 RecreateTData(_T("clusters"), true);
513 RecreateTData(_T("mobile_devices"), true);
514
515 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='294' WHERE var_name='SchemaVersion'")));
516 return TRUE;
517}
518
bc969eaf
VK
519/**
520 * Upgrade from V292 to V293
521 */
522static BOOL H_UpgradeFromV292(int currVersion, int newVersion)
523{
524 CHK_EXEC(CreateConfigParam(_T("DefaultConsoleShortTimeFormat"), _T("HH:mm"), 1, 0));
525 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='293' WHERE var_name='SchemaVersion'")));
526 return TRUE;
527}
528
badf9a95
VK
529/**
530 * Upgrade from V291 to V292
531 */
532static BOOL H_UpgradeFromV291(int currVersion, int newVersion)
533{
534 CHK_EXEC(SQLQuery(_T("ALTER TABLE event_policy ADD rule_guid varchar(36)")));
535
536 // Generate GUIDs for all objects
537 DB_RESULT hResult = SQLSelect(_T("SELECT rule_id FROM event_policy"));
538 if (hResult != NULL)
539 {
540 int count = DBGetNumRows(hResult);
541 for(int i = 0; i < count; i++)
542 {
543 uuid_t guid;
544 TCHAR query[256], buffer[64];
545
546 uuid_generate(guid);
547 _sntprintf(query, 256, _T("UPDATE event_policy SET rule_guid='%s' WHERE rule_id=%d"),
548 uuid_to_string(guid, buffer), DBGetFieldULong(hResult, i, 0));
549 CHK_EXEC(SQLQuery(query));
550 }
551 DBFreeResult(hResult);
552 }
553
554 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='292' WHERE var_name='SchemaVersion'")));
555 return TRUE;
556}
557
48d50116
VK
558/**
559 * Upgrade from V290 to V291
560 */
561static BOOL H_UpgradeFromV290(int currVersion, int newVersion)
562{
563 CHK_EXEC(SQLQuery(_T("UPDATE network_services SET service_type=7 WHERE service_type=6")));
564 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='291' WHERE var_name='SchemaVersion'")));
565 return TRUE;
566}
567
701726bc
VK
568/**
569 * Upgrade from V289 to V290
570 */
571static BOOL H_UpgradeFromV289(int currVersion, int newVersion)
572{
573 CHK_EXEC(SQLQuery(_T("ALTER TABLE network_maps ADD filter $SQL:TEXT")));
574 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='290' WHERE var_name='SchemaVersion'")));
575 return TRUE;
576}
577
90297892
VK
578/**
579 * Upgrade from V288 to V289
580 */
581static BOOL H_UpgradeFromV288(int currVersion, int newVersion)
582{
583 CHK_EXEC(SQLQuery(_T("ALTER TABLE dct_thresholds DROP COLUMN current_state")));
584 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='289' WHERE var_name='SchemaVersion'")));
585 return TRUE;
586}
587
a0dc14f9
VK
588/**
589 * Upgrade from V287 to V288
590 */
591static BOOL H_UpgradeFromV287(int currVersion, int newVersion)
592{
593 CHK_EXEC(CreateEventTemplate(EVENT_TABLE_THRESHOLD_ACTIVATED, _T("SYS_TABLE_THRESHOLD_ACTIVATED"), EVENT_SEVERITY_MINOR, EF_LOG,
594 _T("Threshold activated on table \"%2\" row %4 (%5)"),
595 _T("Generated when table threshold is activated.\r\n")
596 _T("Parameters:\r\n")
597 _T(" 1) Table DCI name\r\n")
598 _T(" 2) Table DCI description\r\n")
599 _T(" 3) Table DCI ID\r\n")
600 _T(" 4) Table row\r\n")
601 _T(" 5) Instance")));
602
603 CHK_EXEC(CreateEventTemplate(EVENT_TABLE_THRESHOLD_DEACTIVATED, _T("SYS_TABLE_THRESHOLD_DEACTIVATED"), EVENT_SEVERITY_NORMAL, EF_LOG,
604 _T("Threshold deactivated on table \"%2\" row %4 (%5)"),
605 _T("Generated when table threshold is deactivated.\r\n")
606 _T("Parameters:\r\n")
607 _T(" 1) Table DCI name\r\n")
608 _T(" 2) Table DCI description\r\n")
609 _T(" 3) Table DCI ID\r\n")
610 _T(" 4) Table row\r\n")
611 _T(" 5) Instance")));
612
613 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='288' WHERE var_name='SchemaVersion'")));
614 return TRUE;
615}
616
9387bc59
VK
617/**
618 * Upgrade from V286 to V287
619 */
620static BOOL H_UpgradeFromV286(int currVersion, int newVersion)
621{
622 static TCHAR batch[] =
623 _T("ALTER TABLE dc_table_columns ADD sequence_number integer\n")
624 _T("UPDATE dc_table_columns SET sequence_number=0\n")
625 _T("<END>");
626 CHK_EXEC(SQLBatch(batch));
627
628 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='287' WHERE var_name='SchemaVersion'")));
629 return TRUE;
630}
631
9098ad59
VK
632/**
633 * Upgrade from V285 to V286
634 */
635static BOOL H_UpgradeFromV285(int currVersion, int newVersion)
636{
637 CHK_EXEC(CreateTable(
638 _T("CREATE TABLE dct_thresholds (")
639 _T("id integer not null,")
640 _T("table_id integer not null,")
641 _T("sequence_number integer not null,")
642 _T("current_state char(1) not null,")
643 _T("activation_event integer not null,")
644 _T("deactivation_event integer not null,")
645 _T("PRIMARY KEY(id))")));
646
647 CHK_EXEC(CreateTable(
648 _T("CREATE TABLE dct_threshold_conditions (")
649 _T("threshold_id integer not null,")
650 _T("group_id integer not null,")
651 _T("sequence_number integer not null,")
652 _T("column_name varchar(63) null,")
653 _T("check_operation integer not null,")
654 _T("check_value varchar(255) null,")
655 _T("PRIMARY KEY(threshold_id,group_id,sequence_number))")));
656
657 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='286' WHERE var_name='SchemaVersion'")));
658 return TRUE;
659}
660
17017844
VK
661/**
662 * Upgrade from V284 to V285
663 */
664static BOOL H_UpgradeFromV284(int currVersion, int newVersion)
665{
666 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_items_node_id ON items(node_id)")));
667 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_dc_tables_node_id ON dc_tables(node_id)")));
668
669 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='285' WHERE var_name='SchemaVersion'")));
670 return TRUE;
671}
672
eb4822b6
VK
673/**
674 * Upgrade from V283 to V284
675 */
676static BOOL H_UpgradeFromV283(int currVersion, int newVersion)
677{
678 CHK_EXEC(CreateConfigParam(_T("SNMPTrapPort"), _T("162"), 1, 1));
679
680 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='284' WHERE var_name='SchemaVersion'")));
681 return TRUE;
682}
683
0b77b73e
VK
684/**
685 * Upgrade from V282 to V283
686 */
687static BOOL H_UpgradeFromV282(int currVersion, int newVersion)
688{
689 static TCHAR batch[] =
690 _T("ALTER TABLE dc_table_columns ADD display_name varchar(255)\n")
691 _T("UPDATE dc_table_columns SET display_name=column_name\n")
692 _T("<END>");
693 CHK_EXEC(SQLBatch(batch));
694
695 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='283' WHERE var_name='SchemaVersion'")));
696 return TRUE;
697}
698
549f48b3
VK
699/**
700 * Upgrade from V281 to V282
701 */
702static BOOL H_UpgradeFromV281(int currVersion, int newVersion)
703{
704 CHK_EXEC(SQLQuery(_T("DELETE FROM config WHERE var_name='WindowsConsoleUpgradeURL'")));
705 CHK_EXEC(CreateConfigParam(_T("EnableObjectTransactions"), _T("0"), 1, 1));
706
707 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='282' WHERE var_name='SchemaVersion'")));
708 return TRUE;
709}
710
22aaa779
VK
711/**
712 * Upgrade from V280 to V281
713 */
714static BOOL H_UpgradeFromV280(int currVersion, int newVersion)
715{
716 static TCHAR batch[] =
717 _T("DELETE FROM metadata WHERE var_name='TDataTableCreationCommand'\n")
718 _T("INSERT INTO metadata (var_name,var_value)")
719 _T(" VALUES ('TDataTableCreationCommand_0','CREATE TABLE tdata_%d (item_id integer not null,tdata_timestamp integer not null,record_id $SQL:INT64 not null)')\n")
720 _T("INSERT INTO metadata (var_name,var_value)")
721 _T(" VALUES ('TDataTableCreationCommand_1','CREATE TABLE tdata_records_%d (record_id $SQL:INT64 not null,row_id $SQL:INT64 not null,instance varchar(255) null,PRIMARY KEY(record_id,row_id))')\n")
722 _T("INSERT INTO metadata (var_name,var_value)")
723 _T(" VALUES ('TDataTableCreationCommand_2','CREATE TABLE tdata_rows_%d (row_id $SQL:INT64 not null,column_id integer not null,value varchar(255) null,PRIMARY KEY(row_id,column_id))')\n")
724 _T("INSERT INTO metadata (var_name,var_value)")
725 _T(" VALUES ('TDataIndexCreationCommand_1','CREATE INDEX idx_tdata_rec_%d_instance ON tdata_records_%d(instance)')\n")
726 _T("<END>");
727 CHK_EXEC(SQLBatch(batch));
728
1d4f7890
VK
729 RecreateTData(_T("nodes"), false);
730 RecreateTData(_T("clusters"), false);
731 RecreateTData(_T("mobile_devices"), false);
22aaa779
VK
732
733 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='281' WHERE var_name='SchemaVersion'")));
734 return TRUE;
735}
736
737/**
738 * Upgrade from V279 to V280
739 */
740static BOOL H_UpgradeFromV279(int currVersion, int newVersion)
741{
742 static TCHAR batch[] =
743 _T("ALTER TABLE dc_table_columns ADD flags integer\n")
744 _T("UPDATE dc_table_columns SET flags=data_type\n")
745 _T("ALTER TABLE dc_table_columns DROP COLUMN data_type\n")
746 _T("<END>");
747 CHK_EXEC(SQLBatch(batch));
748
749 DB_RESULT hResult = SQLSelect(_T("SELECT item_id,instance_column FROM dc_tables"));
750 if (hResult != NULL)
751 {
752 int count = DBGetNumRows(hResult);
753 for(int i = 0; i < count; i++)
754 {
755 TCHAR columnName[MAX_COLUMN_NAME] = _T("");
756 DBGetField(hResult, i, 1, columnName, MAX_COLUMN_NAME);
757 if (columnName[0] != 0)
758 {
759 TCHAR query[256];
760 _sntprintf(query, 256, _T("UPDATE dc_table_columns SET flags=flags+256 WHERE table_id=%d AND column_name=%s"),
761 DBGetFieldLong(hResult, i, 0), (const TCHAR *)DBPrepareString(g_hCoreDB, columnName));
762 CHK_EXEC(SQLQuery(query));
763 }
764 }
765 DBFreeResult(hResult);
766 }
767 else
768 {
769 if (!g_bIgnoreErrors)
770 return FALSE;
771 }
772
773 CHK_EXEC(SQLQuery(_T("ALTER TABLE dc_tables DROP COLUMN instance_column")));
774
775 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='280' WHERE var_name='SchemaVersion'")));
776 return TRUE;
777}
778
22ee6d97
VK
779/**
780 * Upgrade from V278 to V279
781 */
782static BOOL H_UpgradeFromV278(int currVersion, int newVersion)
783{
784 CHK_EXEC(CreateConfigParam(_T("DeleteEventsOfDeletedObject"), _T("1"), 1, 0));
785 CHK_EXEC(CreateConfigParam(_T("DeleteAlarmsOfDeletedObject"), _T("1"), 1, 0));
786
787 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='279' WHERE var_name='SchemaVersion'")));
788 return TRUE;
789}
790
85ae39bc
VK
791/**
792 * Upgrade from V277 to V278
793 */
794static BOOL H_UpgradeFromV277(int currVersion, int newVersion)
795{
796 DB_RESULT hResult = SQLSelect(_T("SELECT id FROM clusters"));
797 if (hResult != NULL)
798 {
799 int count = DBGetNumRows(hResult);
800 for(int i = 0; i < count; i++)
801 {
802 DWORD id = DBGetFieldULong(hResult, i, 0);
803 if (!CreateIDataTable(id))
804 {
805 if (!g_bIgnoreErrors)
806 {
807 DBFreeResult(hResult);
808 return FALSE;
809 }
810 }
22aaa779 811 if (!CreateTDataTable_preV281(id))
85ae39bc
VK
812 {
813 if (!g_bIgnoreErrors)
814 {
815 DBFreeResult(hResult);
816 return FALSE;
817 }
818 }
819 }
820 DBFreeResult(hResult);
821 }
822 else
823 {
824 if (!g_bIgnoreErrors)
825 return FALSE;
826 }
827
828 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='278' WHERE var_name='SchemaVersion'")));
829 return TRUE;
830}
831
62f41164
VK
832/**
833 * Upgrade from V276 to V277
834 */
835static BOOL H_UpgradeFromV276(int currVersion, int newVersion)
836{
b4c2a628
VK
837 CHK_EXEC(CreateTable(_T("CREATE TABLE dci_summary_tables (")
838 _T("id integer not null,")
839 _T("menu_path varchar(255) not null,")
840 _T("title varchar(127) null,")
841 _T("node_filter $SQL:TEXT null,")
842 _T("flags integer not null,")
843 _T("columns $SQL:TEXT null,")
844 _T("PRIMARY KEY(id))")));
845
62f41164
VK
846 CHK_EXEC(CreateConfigParam(_T("DefaultMapBackgroundColor"), _T("0xffffff"), 1, 0));
847
848 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='277' WHERE var_name='SchemaVersion'")));
849 return TRUE;
850}
851
55bdca5a
VK
852/**
853 * Upgrade from V275 to V276
854 */
855static BOOL H_UpgradeFromV275(int currVersion, int newVersion)
856{
857 static TCHAR batch[] =
858 _T("ALTER TABLE dc_table_columns DROP COLUMN transformation_script\n")
859 _T("ALTER TABLE dc_tables ADD transformation_script $SQL:TEXT\n")
860 _T("<END>");
861 CHK_EXEC(SQLBatch(batch));
862
863 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='276' WHERE var_name='SchemaVersion'")));
864 return TRUE;
865}
866
8715a84c
VK
867/**
868 * Upgrade from V274 to V275
869 */
870static BOOL H_UpgradeFromV274(int currVersion, int newVersion)
871{
872 static TCHAR batch[] =
873 _T("ALTER TABLE nodes ADD rack_image varchar(36)\n")
874 _T("ALTER TABLE nodes ADD rack_position integer\n")
875 _T("ALTER TABLE nodes ADD rack_id integer\n")
876 _T("UPDATE nodes SET rack_image='00000000-0000-0000-0000-000000000000',rack_position=0,rack_id=0\n")
877 _T("<END>");
878 CHK_EXEC(SQLBatch(batch));
879
880 CHK_EXEC(CreateTable(_T("CREATE TABLE access_points (")
881 _T("id integer not null,")
882 _T("node_id integer not null,")
f1989a3a 883 _T("mac_address varchar(12) null,")
8715a84c
VK
884 _T("vendor varchar(64) null,")
885 _T("model varchar(128) null,")
886 _T("serial_number varchar(64) null,")
887 _T("PRIMARY KEY(id))")));
888
889 CHK_EXEC(CreateTable(_T("CREATE TABLE racks (")
890 _T("id integer not null,")
891 _T("height integer not null,")
892 _T("PRIMARY KEY(id))")));
893
894 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='275' WHERE var_name='SchemaVersion'")));
895 return TRUE;
896}
897
d02f6b92
VK
898/**
899 * Upgrade from V273 to V274
900 */
901static BOOL H_UpgradeFromV273(int currVersion, int newVersion)
902{
903 static TCHAR batch[] =
904 _T("ALTER TABLE items ADD samples integer\n")
905 _T("UPDATE items SET samples=0\n")
906 _T("<END>");
907 CHK_EXEC(SQLBatch(batch));
908
909 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='274' WHERE var_name='SchemaVersion'")));
910 return TRUE;
911}
912
f05a8a45
VK
913/**
914 * Upgrade from V272 to V273
915 */
916static BOOL H_UpgradeFromV272(int currVersion, int newVersion)
917{
918 CHK_EXEC(CreateConfigParam(_T("DefaultDCIRetentionTime"), _T("30"), 1, 0));
919 CHK_EXEC(CreateConfigParam(_T("DefaultDCIPollingInterval"), _T("60"), 1, 0));
920 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='273' WHERE var_name='SchemaVersion'")));
921 return TRUE;
922}
923
0f75f8fc
VK
924/**
925 * Upgrade from V271 to V272
926 */
927static BOOL H_UpgradeFromV271(int currVersion, int newVersion)
928{
929 CHK_EXEC(CreateConfigParam(_T("SNMPTrapLogRetentionTime"), _T("90"), 1, 0));
28e1575f 930 CHK_EXEC(SQLQuery(_T("ALTER TABLE nodes ADD driver_name varchar(32)\n")));
0f75f8fc
VK
931 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='272' WHERE var_name='SchemaVersion'")));
932 return TRUE;
933}
934
86634c2c
VK
935/**
936 * Upgrade from V270 to V271
937 */
938static BOOL H_UpgradeFromV270(int currVersion, int newVersion)
939{
940 static TCHAR batch[] =
941 _T("ALTER TABLE object_properties ADD location_accuracy integer\n")
f2d5b2c4
VK
942 _T("ALTER TABLE object_properties ADD location_timestamp integer\n")
943 _T("UPDATE object_properties SET location_accuracy=0,location_timestamp=0\n")
86634c2c
VK
944 _T("<END>");
945 CHK_EXEC(SQLBatch(batch));
946
947 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='271' WHERE var_name='SchemaVersion'")));
948 return TRUE;
949}
950
afbe5388
VK
951/**
952 * Upgrade from V269 to V270
953 */
954static BOOL H_UpgradeFromV269(int currVersion, int newVersion)
955{
956 static TCHAR batch[] =
957 _T("ALTER TABLE items ADD instd_method integer\n")
958 _T("ALTER TABLE items ADD instd_data varchar(255)\n")
959 _T("ALTER TABLE items ADD instd_filter $SQL:TEXT\n")
960 _T("UPDATE items SET instd_method=0\n")
961 _T("<END>");
962 CHK_EXEC(SQLBatch(batch));
963
964 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='270' WHERE var_name='SchemaVersion'")));
965 return TRUE;
966}
967
480e036b
VK
968/**
969 * Upgrade from V268 to V269
970 */
971static BOOL H_UpgradeFromV268(int currVersion, int newVersion)
972{
973 CHK_EXEC(ResizeColumn(_T("alarms"), _T("message"), 2000));
974 CHK_EXEC(ResizeColumn(_T("alarm_events"), _T("message"), 2000));
975 CHK_EXEC(ResizeColumn(_T("event_log"), _T("event_message"), 2000));
976 CHK_EXEC(ResizeColumn(_T("event_cfg"), _T("message"), 2000));
977 CHK_EXEC(ResizeColumn(_T("event_policy"), _T("alarm_message"), 2000));
978 CHK_EXEC(ResizeColumn(_T("items"), _T("name"), 1024));
979 CHK_EXEC(ResizeColumn(_T("dc_tables"), _T("name"), 1024));
980
981 CHK_EXEC(SetColumnNullable(_T("event_policy"), _T("alarm_key")));
982 CHK_EXEC(SetColumnNullable(_T("event_policy"), _T("alarm_message")));
983 CHK_EXEC(SetColumnNullable(_T("event_policy"), _T("comments")));
984 CHK_EXEC(SetColumnNullable(_T("event_policy"), _T("situation_instance")));
985 CHK_EXEC(SetColumnNullable(_T("event_policy"), _T("script")));
986 CHK_EXEC(ConvertStrings(_T("event_policy"), _T("rule_id"), _T("alarm_key")));
987 CHK_EXEC(ConvertStrings(_T("event_policy"), _T("rule_id"), _T("alarm_message")));
988 CHK_EXEC(ConvertStrings(_T("event_policy"), _T("rule_id"), _T("comments")));
989 CHK_EXEC(ConvertStrings(_T("event_policy"), _T("rule_id"), _T("situation_instance")));
990 CHK_EXEC(ConvertStrings(_T("event_policy"), _T("rule_id"), _T("script")));
991
992 CHK_EXEC(SetColumnNullable(_T("policy_situation_attr_list"), _T("attr_value")));
993 // convert strings in policy_situation_attr_list
994 DB_RESULT hResult = SQLSelect(_T("SELECT rule_id,situation_id,attr_name,attr_value FROM policy_situation_attr_list"));
995 if (hResult != NULL)
996 {
997 if (SQLQuery(_T("DELETE FROM policy_situation_attr_list")))
998 {
999 TCHAR name[MAX_DB_STRING], value[MAX_DB_STRING], query[1024];
1000 int count = DBGetNumRows(hResult);
1001 for(int i = 0; i < count; i++)
1002 {
1003 LONG ruleId = DBGetFieldLong(hResult, i, 0);
1004 LONG situationId = DBGetFieldLong(hResult, i, 1);
1005 DBGetField(hResult, i, 2, name, MAX_DB_STRING);
1006 DBGetField(hResult, i, 3, value, MAX_DB_STRING);
1007
1008 DecodeSQLString(name);
1009 DecodeSQLString(value);
1010
1011 if (name[0] == 0)
1012 _tcscpy(name, _T("noname"));
1013
1014 _sntprintf(query, 1024, _T("INSERT INTO policy_situation_attr_list (rule_id,situation_id,attr_name,attr_value) VALUES (%d,%d,%s,%s)"),
1015 ruleId, situationId, (const TCHAR *)DBPrepareString(g_hCoreDB, name), (const TCHAR *)DBPrepareString(g_hCoreDB, value));
1016 if (!SQLQuery(query))
1017 {
1018 if (!g_bIgnoreErrors)
1019 {
1020 DBFreeResult(hResult);
1021 return FALSE;
1022 }
1023 }
1024 }
1025 }
1026 else
1027 {
1028 if (!g_bIgnoreErrors)
1029 {
1030 DBFreeResult(hResult);
1031 return FALSE;
1032 }
1033 }
1034 DBFreeResult(hResult);
1035 }
1036 else
1037 {
1038 if (!g_bIgnoreErrors)
1039 return FALSE;
1040 }
1041
1042 CHK_EXEC(SetColumnNullable(_T("event_cfg"), _T("description")));
1043 CHK_EXEC(SetColumnNullable(_T("event_cfg"), _T("message")));
1044 CHK_EXEC(ConvertStrings(_T("event_cfg"), _T("event_code"), _T("description")));
1045 CHK_EXEC(ConvertStrings(_T("event_cfg"), _T("event_code"), _T("message")));
1046
1047 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='269' WHERE var_name='SchemaVersion'")));
1048 return TRUE;
1049}
1050
d6bf58f9
VK
1051/**
1052 * Upgrade from V267 to V268
1053 */
1054static BOOL H_UpgradeFromV267(int currVersion, int newVersion)
1055{
480e036b
VK
1056 CHK_EXEC(SetColumnNullable(_T("network_services"), _T("check_request")));
1057 CHK_EXEC(SetColumnNullable(_T("network_services"), _T("check_responce")));
d6bf58f9
VK
1058 CHK_EXEC(ConvertStrings(_T("network_services"), _T("id"), _T("check_request")));
1059 CHK_EXEC(ConvertStrings(_T("network_services"), _T("id"), _T("check_responce")));
1060
480e036b 1061 CHK_EXEC(SetColumnNullable(_T("config"), _T("var_value")));
d6bf58f9
VK
1062 CHK_EXEC(ConvertStrings(_T("config"), _T("var_name"), NULL, _T("var_value"), true));
1063
480e036b 1064 CHK_EXEC(SetColumnNullable(_T("config"), _T("var_value")));
d6bf58f9
VK
1065 CHK_EXEC(ConvertStrings(_T("config"), _T("var_name"), NULL, _T("var_value"), true));
1066
480e036b 1067 CHK_EXEC(SetColumnNullable(_T("dci_schedules"), _T("schedule")));
d6bf58f9
VK
1068 CHK_EXEC(ConvertStrings(_T("dci_schedules"), _T("schedule_id"), _T("item_id"), _T("schedule"), false));
1069
1070 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='268' WHERE var_name='SchemaVersion'")));
1071 return TRUE;
1072}
1073
c1482463
VK
1074/**
1075 * Upgrade from V266 to V267
1076 */
1077static BOOL H_UpgradeFromV266(int currVersion, int newVersion)
1078{
1079 CHK_EXEC(CreateEventTemplate(EVENT_NODE_UNREACHABLE, _T("SYS_NODE_UNREACHABLE"), EVENT_SEVERITY_CRITICAL,
1080 EF_LOG, _T("Node unreachable because of network failure"),
1081 _T("Generated when node is unreachable by management server because of network failure.\r\nParameters:\r\n No event-specific parameters")));
1082 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='267' WHERE var_name='SchemaVersion'")));
1083 return TRUE;
1084}
1085
69bb7f47
VK
1086/**
1087 * Upgrade from V265 to V266
1088 */
1089static BOOL H_UpgradeFromV265(int currVersion, int newVersion)
1090{
1091 // create index on root event ID in event log
1092 switch(g_iSyntax)
1093 {
1094 case DB_SYNTAX_MSSQL:
1095 case DB_SYNTAX_PGSQL:
1096 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_event_log_root_id ON event_log(root_event_id) WHERE root_event_id > 0")));
1097 break;
1098 case DB_SYNTAX_ORACLE:
1099 CHK_EXEC(SQLQuery(_T("CREATE OR REPLACE FUNCTION zero_to_null(id NUMBER) ")
1100 _T("RETURN NUMBER ")
1101 _T("DETERMINISTIC ")
1102 _T("AS BEGIN")
1103 _T(" IF id > 0 THEN")
1104 _T(" RETURN id;")
1105 _T(" ELSE")
1106 _T(" RETURN NULL;")
1107 _T(" END IF;")
1108 _T("END;")));
1109 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_event_log_root_id ON event_log(zero_to_null(root_event_id))")));
1110 break;
1111 default:
1112 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_event_log_root_id ON event_log(root_event_id)")));
1113 break;
1114 }
1115
1116 CHK_EXEC(CreateTable(_T("CREATE TABLE mapping_tables (")
1117 _T("id integer not null,")
1118 _T("name varchar(63) not null,")
1119 _T("flags integer not null,")
1120 _T("description $SQL:TXT4K null,")
1121 _T("PRIMARY KEY(id))")));
1122
1123 CHK_EXEC(CreateTable(_T("CREATE TABLE mapping_data (")
1124 _T("table_id integer not null,")
1125 _T("md_key varchar(63) not null,")
1126 _T("md_value varchar(255) null,")
f41af2c4 1127 _T("description $SQL:TXT4K null,")
69bb7f47
VK
1128 _T("PRIMARY KEY(table_id,md_key))")));
1129
1130 CHK_EXEC(SQLQuery(_T("DROP TABLE deleted_objects")));
1131
1132 CHK_EXEC(CreateConfigParam(_T("FirstFreeObjectId"), _T("100"), 0, 1, FALSE));
1133
1134 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='266' WHERE var_name='SchemaVersion'")));
1135 return TRUE;
1136}
1137
b1e9b6b3
VK
1138/**
1139 * Upgrade from V264 to V265
1140 */
1141static BOOL H_UpgradeFromV264(int currVersion, int newVersion)
1142{
1143 CHK_EXEC(CreateTable(_T("CREATE TABLE alarm_events (")
1144 _T("alarm_id integer not null,")
1145 _T("event_id $SQL:INT64 not null,")
1146 _T("event_code integer not null,")
1147 _T("event_name varchar(63) null,")
1148 _T("severity integer not null,")
1149 _T("source_object_id integer not null,")
1150 _T("event_timestamp integer not null,")
1151 _T("message varchar(255) null,")
1152 _T("PRIMARY KEY(alarm_id,event_id))")));
1153 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_alarm_events_alarm_id ON alarm_events(alarm_id)")));
1154 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='265' WHERE var_name='SchemaVersion'")));
1155 return TRUE;
1156}
1157
9aa67910
VK
1158/**
1159 * Upgrade from V263 to V264
1160 */
1161static BOOL H_UpgradeFromV263(int currVersion, int newVersion)
1162{
1163 CHK_EXEC(CreateTable(_T("CREATE TABLE mobile_devices (")
1164 _T("id integer not null,")
1165 _T("device_id varchar(64) not null,")
1166 _T("vendor varchar(64) null,")
1167 _T("model varchar(128) null,")
1168 _T("serial_number varchar(64) null,")
1169 _T("os_name varchar(32) null,")
1170 _T("os_version varchar(64) null,")
1171 _T("user_id varchar(64) null,")
171c2fd6 1172 _T("battery_level integer not null,")
9aa67910 1173 _T("PRIMARY KEY(id))")));
534e1b83 1174 CHK_EXEC(CreateConfigParam(_T("MobileDeviceListenerPort"), _T("4747"), 1, 1));
9aa67910
VK
1175 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='264' WHERE var_name='SchemaVersion'")));
1176 return TRUE;
1177}
1178
84880c89
VK
1179/**
1180 * Upgrade from V262 to V263
1181 */
1182static BOOL H_UpgradeFromV262(int currVersion, int newVersion)
1183{
1184 CHK_EXEC(SQLQuery(_T("ALTER TABLE network_maps ADD radius integer")));
1185 CHK_EXEC(SQLQuery(_T("UPDATE network_maps SET radius=-1")));
1186 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='263' WHERE var_name='SchemaVersion'")));
1187 return TRUE;
1188}
1189
dc4a1aec
AK
1190/**
1191 * Upgrade from V261 to V262
1192 */
1193static BOOL H_UpgradeFromV261(int currVersion, int newVersion)
1194{
534e1b83 1195 CHK_EXEC(CreateConfigParam(_T("ApplyDCIFromTemplateToDisabledDCI"), _T("0"), 1, 1));
dc4a1aec
AK
1196 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='262' WHERE var_name='SchemaVersion'")));
1197 return TRUE;
1198}
1199
4f50e45c
VK
1200/**
1201 * Upgrade from V260 to V261
1202 */
1203static BOOL H_UpgradeFromV260(int currVersion, int newVersion)
1204{
534e1b83 1205 CHK_EXEC(CreateConfigParam(_T("NumberOfBusinessServicePollers"), _T("10"), 1, 1));
4f50e45c
VK
1206 CHK_EXEC(SQLQuery(_T("DELETE FROM config WHERE var_name='NumberOfEventProcessors'")));
1207 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='261' WHERE var_name='SchemaVersion'")));
1208 return TRUE;
1209}
a203ea53 1210
4f50e45c
VK
1211/**
1212 * Upgrade from V259 to V260
1213 */
a203ea53
AK
1214static BOOL H_UpgradeFromV259(int currVersion, int newVersion)
1215{
534e1b83 1216 CHK_EXEC(CreateConfigParam(_T("UseFQDNForNodeNames"), _T("1"), 1, 1));
a203ea53
AK
1217 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='260' WHERE var_name='SchemaVersion'")));
1218 return TRUE;
1219}
1220
4f50e45c
VK
1221/**
1222 * Upgrade from V258 to V259
1223 */
5da6ca46
VK
1224static BOOL H_UpgradeFromV258(int currVersion, int newVersion)
1225{
1226 // have to made these columns nullable again because
1227 // because they was forgotten as NOT NULL in schema.in
1228 // and so some databases can still have them as NOT NULL
480e036b
VK
1229 CHK_EXEC(SetColumnNullable(_T("templates"), _T("apply_filter")));
1230 CHK_EXEC(SetColumnNullable(_T("containers"), _T("auto_bind_filter")));
5da6ca46
VK
1231
1232 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='259' WHERE var_name='SchemaVersion'")));
1233 return TRUE;
1234}
1235
4f50e45c
VK
1236/**
1237 * Upgrade from V257 to V258
1238 */
dd42ad0a
AK
1239static BOOL H_UpgradeFromV257(int currVersion, int newVersion)
1240{
1241 static TCHAR batch[] =
1242 _T("ALTER TABLE nodes ADD down_since integer\n")
1243 _T("UPDATE nodes SET down_since=0\n")
1244 _T("<END>");
1245
1246 CHK_EXEC(SQLBatch(batch));
1247
534e1b83 1248 CHK_EXEC(CreateConfigParam(_T("DeleteUnreachableNodesPeriod"), _T("0"), 1, 1));
dd42ad0a
AK
1249
1250 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='258' WHERE var_name='SchemaVersion'")));
1251 return TRUE;
1252}
aa16f82b 1253
534e1b83
VK
1254/**
1255 * Upgrade from V256 to V257
1256 */
e4acd770
VK
1257static BOOL H_UpgradeFromV256(int currVersion, int newVersion)
1258{
1259 static TCHAR batch[] =
1260 _T("ALTER TABLE network_maps ADD bg_color integer\n")
1261 _T("ALTER TABLE network_maps ADD link_routing integer\n")
1262 _T("UPDATE network_maps SET bg_color=16777215,link_routing=1\n")
1263 _T("ALTER TABLE network_map_links ADD routing integer\n")
1264 _T("ALTER TABLE network_map_links ADD bend_points $SQL:TXT4K\n")
1265 _T("UPDATE network_map_links SET routing=0\n")
1266 _T("<END>");
1267
1268 CHK_EXEC(SQLBatch(batch));
1269
1270 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='257' WHERE var_name='SchemaVersion'")));
1271 return TRUE;
1272}
1273
534e1b83
VK
1274/**
1275 * Upgrade from V255 to V256
1276 */
aabe5b72
VK
1277static BOOL H_UpgradeFromV255(int currVersion, int newVersion)
1278{
534e1b83
VK
1279 CHK_EXEC(CreateConfigParam(_T("DefaultConsoleDateFormat"), _T("dd.MM.yyyy"), 1, 0));
1280 CHK_EXEC(CreateConfigParam(_T("DefaultConsoleTimeFormat"), _T("HH:mm:ss"), 1, 0));
aabe5b72
VK
1281
1282 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='256' WHERE var_name='SchemaVersion'")));
1283 return TRUE;
1284}
1285
480e036b
VK
1286/**
1287 * Upgrade from V254 to V255
1288 */
5f6bc78c
VK
1289static BOOL H_UpgradeFromV254(int currVersion, int newVersion)
1290{
1291 static TCHAR batch[] =
1292 _T("ALTER TABLE alarms ADD resolved_by integer\n")
1293 _T("UPDATE alarms SET resolved_by=0\n")
1294 _T("UPDATE alarms SET alarm_state=3 WHERE alarm_state=2\n")
1295 _T("<END>");
1296
1297 CHK_EXEC(SQLBatch(batch));
1298
3e9e0cc5 1299 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='255' WHERE var_name='SchemaVersion'")));
5f6bc78c
VK
1300 return TRUE;
1301}
40647141 1302
badf9a95
VK
1303/**
1304 * Upgrade from V253 to V254
1305 */
40647141
VK
1306static BOOL H_UpgradeFromV253(int currVersion, int newVersion)
1307{
1308 static TCHAR batch[] =
1309 _T("ALTER TABLE network_maps ADD flags integer\n")
1310 _T("ALTER TABLE network_maps ADD link_color integer\n")
1311 _T("UPDATE network_maps SET flags=1,link_color=-1\n")
1312 _T("ALTER TABLE network_map_links ADD color integer\n")
1313 _T("ALTER TABLE network_map_links ADD status_object integer\n")
1314 _T("UPDATE network_map_links SET color=-1,status_object=0\n")
1315 _T("<END>");
1316
1317 CHK_EXEC(SQLBatch(batch));
1318
1319 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='254' WHERE var_name='SchemaVersion'")));
1320 return TRUE;
1321}
1322
d6bf58f9
VK
1323/**
1324 * Upgrade from V252 to V253
1325 */
feab3324
VK
1326static BOOL H_UpgradeFromV252(int currVersion, int newVersion)
1327{
480e036b 1328 CHK_EXEC(SetColumnNullable(_T("templates"), _T("apply_filter")));
242e9c7f
VK
1329 CHK_EXEC(ConvertStrings(_T("templates"), _T("id"), _T("apply_filter")));
1330
480e036b 1331 CHK_EXEC(SetColumnNullable(_T("containers"), _T("auto_bind_filter")));
242e9c7f
VK
1332 CHK_EXEC(ConvertStrings(_T("containers"), _T("id"), _T("auto_bind_filter")));
1333
feab3324
VK
1334 static TCHAR batch[] =
1335 _T("ALTER TABLE templates ADD flags integer\n")
2984ac95
VK
1336 _T("UPDATE templates SET flags=0 WHERE enable_auto_apply=0\n")
1337 _T("UPDATE templates SET flags=3 WHERE enable_auto_apply<>0\n")
feab3324
VK
1338 _T("ALTER TABLE templates DROP COLUMN enable_auto_apply\n")
1339 _T("ALTER TABLE containers ADD flags integer\n")
2984ac95
VK
1340 _T("UPDATE containers SET flags=0 WHERE enable_auto_bind=0\n")
1341 _T("UPDATE containers SET flags=3 WHERE enable_auto_bind<>0\n")
feab3324
VK
1342 _T("ALTER TABLE containers DROP COLUMN enable_auto_bind\n")
1343 _T("<END>");
feab3324
VK
1344 CHK_EXEC(SQLBatch(batch));
1345
1346 CHK_EXEC(CreateEventTemplate(EVENT_CONTAINER_AUTOBIND, _T("SYS_CONTAINER_AUTOBIND"), EVENT_SEVERITY_NORMAL, 1,
1347 _T("Node %2 automatically bound to container %4"),
1348 _T("Generated when node bound to container object by autobind rule.\r\n")
1349 _T("Parameters:#\r\n")
1350 _T(" 1) Node ID\r\n")
1351 _T(" 2) Node name\r\n")
1352 _T(" 3) Container ID\r\n")
1353 _T(" 4) Container name")
1354 ));
1355
1356 CHK_EXEC(CreateEventTemplate(EVENT_CONTAINER_AUTOUNBIND, _T("SYS_CONTAINER_AUTOUNBIND"), EVENT_SEVERITY_NORMAL, 1,
1357 _T("Node %2 automatically unbound from container %4"),
1358 _T("Generated when node unbound from container object by autobind rule.\r\n")
1359 _T("Parameters:#\r\n")
1360 _T(" 1) Node ID\r\n")
1361 _T(" 2) Node name\r\n")
1362 _T(" 3) Container ID\r\n")
1363 _T(" 4) Container name")
1364 ));
1365
1366 CHK_EXEC(CreateEventTemplate(EVENT_TEMPLATE_AUTOAPPLY, _T("SYS_TEMPLATE_AUTOAPPLY"), EVENT_SEVERITY_NORMAL, 1,
1367 _T("Template %4 automatically applied to node %2"),
1368 _T("Generated when template applied to node by autoapply rule.\r\n")
1369 _T("Parameters:#\r\n")
1370 _T(" 1) Node ID\r\n")
1371 _T(" 2) Node name\r\n")
1372 _T(" 3) Template ID\r\n")
1373 _T(" 4) Template name")
1374 ));
1375
1376 CHK_EXEC(CreateEventTemplate(EVENT_TEMPLATE_AUTOREMOVE, _T("SYS_TEMPLATE_AUTOREMOVE"), EVENT_SEVERITY_NORMAL, 1,
1377 _T("Template %4 automatically removed from node %2"),
1378 _T("Generated when template removed from node by autoapply rule.\r\n")
1379 _T("Parameters:#\r\n")
1380 _T(" 1) Node ID\r\n")
1381 _T(" 2) Node name\r\n")
1382 _T(" 3) Template ID\r\n")
1383 _T(" 4) Template name")
1384 ));
1385
65790062
VK
1386 TCHAR buffer[64];
1387 _sntprintf(buffer, 64, _T("%d"), ConfigReadInt(_T("AllowedCiphers"), 15) + 16);
1388 CreateConfigParam(_T("AllowedCiphers"), buffer, 1, 1, TRUE);
1389
feab3324
VK
1390 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='253' WHERE var_name='SchemaVersion'")));
1391 return TRUE;
1392}
1393
badf9a95
VK
1394/**
1395 * Upgrade from V251 to V252
1396 */
1e6b68a6
VK
1397static BOOL H_UpgradeFromV251(int currVersion, int newVersion)
1398{
1399 static TCHAR batch[] =
1400 _T("ALTER TABLE interfaces ADD admin_state integer\n")
1401 _T("ALTER TABLE interfaces ADD oper_state integer\n")
1402 _T("UPDATE interfaces SET admin_state=0,oper_state=0\n")
1403 _T("<END>");
1404
1405 CHK_EXEC(SQLBatch(batch));
1406
1407 CHK_EXEC(CreateEventTemplate(EVENT_INTERFACE_UNEXPECTED_UP, _T("SYS_IF_UNEXPECTED_UP"), EVENT_SEVERITY_MAJOR, 1,
1408 _T("Interface \"%2\" unexpectedly changed state to UP (IP Addr: %3/%4, IfIndex: %5)"),
1409 _T("Generated when interface goes up but it's expected state set to DOWN.\r\n")
1410 _T("Please note that source of event is node, not an interface itself.\r\n")
1411 _T("Parameters:#\r\n")
1412 _T(" 1) Interface object ID\r\n")
1413 _T(" 2) Interface name\r\n")
1414 _T(" 3) Interface IP address\r\n")
1415 _T(" 4) Interface netmask\r\n")
1416 _T(" 5) Interface index")
1417 ));
1418
1419 CHK_EXEC(CreateEventTemplate(EVENT_INTERFACE_EXPECTED_DOWN, _T("SYS_IF_EXPECTED_DOWN"), EVENT_SEVERITY_NORMAL, 1,
1420 _T("Interface \"%2\" with expected state DOWN changed state to DOWN (IP Addr: %3/%4, IfIndex: %5)"),
1421 _T("Generated when interface goes down and it's expected state is DOWN.\r\n")
1422 _T("Please note that source of event is node, not an interface itself.\r\n")
1423 _T("Parameters:#\r\n")
1424 _T(" 1) Interface object ID\r\n")
1425 _T(" 2) Interface name\r\n")
1426 _T(" 3) Interface IP address\r\n")
1427 _T(" 4) Interface netmask\r\n")
1428 _T(" 5) Interface index")
1429 ));
1430
1431 // Create rule pair in event processing policy
1432 int ruleId = 0;
1433 DB_RESULT hResult = SQLSelect(_T("SELECT max(rule_id) FROM event_policy"));
1434 if (hResult != NULL)
1435 {
1436 ruleId = DBGetFieldLong(hResult, 0, 0) + 1;
1437 DBFreeResult(hResult);
1438 }
1439
1440 TCHAR query[1024];
1441 _sntprintf(query, 1024,
1442 _T("INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,")
1443 _T("script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) VALUES ")
1444 _T("(%d,7944,'Show alarm when interface is unexpectedly up','%%m',5,'IF_UNEXP_UP_%%i_%%1',")
1445 _T("'#00',0,%d,0,'#00')"), ruleId, EVENT_ALARM_TIMEOUT);
1446 CHK_EXEC(SQLQuery(query));
1447 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_INTERFACE_UNEXPECTED_UP);
1448 CHK_EXEC(SQLQuery(query));
1449 ruleId++;
1450
1451 _sntprintf(query, 1024,
1452 _T("INSERT INTO event_policy (rule_id,flags,comments,alarm_message,alarm_severity,alarm_key,")
1453 _T("script,alarm_timeout,alarm_timeout_event,situation_id,situation_instance) VALUES ")
1454 _T("(%d,7944,'Acknowlege interface unexpectedly up alarms when interface goes down','%%m',")
1455 _T("6,'IF_UNEXP_UP_%%i_%%1','#00',0,%d,0,'#00')"), ruleId, EVENT_ALARM_TIMEOUT);
1456 CHK_EXEC(SQLQuery(query));
1457 _sntprintf(query, 1024, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"), ruleId, EVENT_INTERFACE_EXPECTED_DOWN);
1458 CHK_EXEC(SQLQuery(query));
1459
1460 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='252' WHERE var_name='SchemaVersion'")));
1461 return TRUE;
1462}
1463
9aa67910
VK
1464/**
1465 * Upgrade from V250 to V251
1466 */
711e5e9a
VK
1467static BOOL H_UpgradeFromV250(int currVersion, int newVersion)
1468{
1469 static TCHAR batch[] =
1470 _T("ALTER TABLE thresholds ADD current_severity integer\n")
1471 _T("ALTER TABLE thresholds ADD last_event_timestamp integer\n")
1472 _T("UPDATE thresholds SET current_severity=0,last_event_timestamp=0\n")
1473 _T("<END>");
1474
1475 CHK_EXEC(SQLBatch(batch));
1476
480e036b
VK
1477 CHK_EXEC(SetColumnNullable(_T("thresholds"), _T("fire_value")));
1478 CHK_EXEC(SetColumnNullable(_T("thresholds"), _T("rearm_value")));
711e5e9a
VK
1479 CHK_EXEC(ConvertStrings(_T("thresholds"), _T("threshold_id"), _T("fire_value")));
1480 CHK_EXEC(ConvertStrings(_T("thresholds"), _T("threshold_id"), _T("rearm_value")));
1481
1482 CHK_EXEC(CreateConfigParam(_T("EnableNXSLContainerFunctions"), _T("1"), 1, 1));
1483 CHK_EXEC(CreateConfigParam(_T("UseDNSNameForDiscoveredNodes"), _T("0"), 1, 0));
1484 CHK_EXEC(CreateConfigParam(_T("AllowTrapVarbindsConversion"), _T("1"), 1, 1));
1485
1486 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='251' WHERE var_name='SchemaVersion'")));
1487 return TRUE;
1488}
1489
9aa67910
VK
1490/**
1491 * Upgrade from V249 to V250
1492 */
ae2a3458
VK
1493static BOOL H_UpgradeFromV249(int currVersion, int newVersion)
1494{
1495 CHK_EXEC(CreateTable(_T("CREATE TABLE licenses (")
1496 _T("id integer not null,")
1497 _T("content $SQL:TEXT null,")
1498 _T("PRIMARY KEY(id))")));
1499
1500 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='250' WHERE var_name='SchemaVersion'")));
1501 return TRUE;
1502}
1503
9aa67910
VK
1504/**
1505 * Upgrade from V248 to V249
1506 */
d6124fa0
VK
1507#define TDATA_CREATE_QUERY _T("CREATE TABLE tdata_%d (item_id integer not null,tdata_timestamp integer not null,tdata_row integer not null,tdata_column integer not null,tdata_value varchar(255) null)")
1508#define TDATA_INDEX_MSSQL _T("CREATE CLUSTERED INDEX idx_tdata_%d_id_timestamp ON tdata_%d(item_id,tdata_timestamp)")
1509#define TDATA_INDEX_PGSQL _T("CREATE INDEX idx_tdata_%d_timestamp_id ON tdata_%d(tdata_timestamp,item_id)")
1510#define TDATA_INDEX_DEFAULT _T("CREATE INDEX idx_tdata_%d_id_timestamp ON tdata_%d(item_id,tdata_timestamp)")
1511
1512static BOOL CreateTData(DWORD nodeId)
1513{
1514 TCHAR query[256];
1515
1516 _sntprintf(query, 256, TDATA_CREATE_QUERY, (int)nodeId);
1517 CHK_EXEC(SQLQuery(query));
1518
1519 switch(g_iSyntax)
1520 {
1521 case DB_SYNTAX_MSSQL:
1522 _sntprintf(query, 256, TDATA_INDEX_MSSQL, (int)nodeId, (int)nodeId);
1523 break;
1524 case DB_SYNTAX_PGSQL:
1525 _sntprintf(query, 256, TDATA_INDEX_PGSQL, (int)nodeId, (int)nodeId);
1526 break;
1527 default:
1528 _sntprintf(query, 256, TDATA_INDEX_DEFAULT, (int)nodeId, (int)nodeId);
1529 break;
1530 }
1531 CHK_EXEC(SQLQuery(query));
1532
1533 return TRUE;
1534}
1535
1536static BOOL H_UpgradeFromV248(int currVersion, int newVersion)
1537{
1538 CHK_EXEC(SQLQuery(_T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataTableCreationCommand','") TDATA_CREATE_QUERY _T("')")));
1539
1540 switch(g_iSyntax)
1541 {
1542 case DB_SYNTAX_MSSQL:
1543 CHK_EXEC(SQLQuery(_T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataIndexCreationCommand_0','") TDATA_INDEX_MSSQL _T("')")));
1544 break;
1545 case DB_SYNTAX_PGSQL:
1546 CHK_EXEC(SQLQuery(_T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataIndexCreationCommand_0','") TDATA_INDEX_PGSQL _T("')")));
1547 break;
1548 default:
1549 CHK_EXEC(SQLQuery(_T("INSERT INTO metadata (var_name,var_value) VALUES ('TDataIndexCreationCommand_0','") TDATA_INDEX_DEFAULT _T("')")));
1550 break;
1551 }
1552
1553 CHK_EXEC(CreateTable(_T("CREATE TABLE dct_column_names (")
1554 _T("column_id integer not null,")
1555 _T("column_name varchar(63) not null,")
1556 _T("PRIMARY KEY(column_id))")));
1557
1558 DB_RESULT hResult = SQLSelect(_T("SELECT id FROM nodes"));
1559 if (hResult != NULL)
1560 {
1561 int count = DBGetNumRows(hResult);
1562 for(int i = 0 ; i < count; i++)
1563 {
1564 if (!CreateTData(DBGetFieldULong(hResult, i, 0)))
1565 {
1566 if (!g_bIgnoreErrors)
1567 {
1568 DBFreeResult(hResult);
1569 return FALSE;
1570 }
1571 }
1572 }
1573 DBFreeResult(hResult);
1574 }
1575 else
1576 {
1577 if (!g_bIgnoreErrors)
1578 return FALSE;
1579 }
1580
1581 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='249' WHERE var_name='SchemaVersion'")));
1582 return TRUE;
1583}
1584
480e036b
VK
1585/**
1586 * Upgrade from V247 to V248
1587 */
cc8ce218
VK
1588static BOOL H_UpgradeFromV247(int currVersion, int newVersion)
1589{
1590 CHK_EXEC(CreateTable(_T("CREATE TABLE dc_tables (")
1591 _T("item_id integer not null,")
1592 _T("node_id integer not null,")
1593 _T("template_id integer not null,")
1594 _T("template_item_id integer not null,")
1595 _T("name varchar(255) null,")
1596 _T("instance_column varchar(63) null,")
1597 _T("description varchar(255) null,")
1598 _T("flags integer not null,")
1599 _T("source integer not null,")
1600 _T("snmp_port integer not null,")
1601 _T("polling_interval integer not null,")
1602 _T("retention_time integer not null,")
1603 _T("status integer not null,")
1604 _T("system_tag varchar(255) null,")
1605 _T("resource_id integer not null,")
1606 _T("proxy_node integer not null,")
1607 _T("perftab_settings $SQL:TEXT null,")
1608 _T("PRIMARY KEY(item_id))")));
1609
1610 CHK_EXEC(CreateTable(_T("CREATE TABLE dc_table_columns (")
1611 _T("table_id integer not null,")
1612 _T("column_name varchar(63) not null,")
1613 _T("snmp_oid varchar(1023) null,")
1614 _T("data_type integer not null,")
1615 _T("transformation_script $SQL:TEXT null,")
1616 _T("PRIMARY KEY(table_id,column_name))")));
1617
1618 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='248' WHERE var_name='SchemaVersion'")));
1619 return TRUE;
1620}
1621
480e036b
VK
1622/**
1623 * Upgrade from V246 to V247
1624 */
ff392ecf
VK
1625static BOOL H_UpgradeFromV246(int currVersion, int newVersion)
1626{
1627 static TCHAR insertQuery[] = _T("INSERT INTO object_custom_attributes (object_id,attr_name,attr_value) VALUES (?,?,?)");
1628
480e036b 1629 CHK_EXEC(SetColumnNullable(_T("object_custom_attributes"), _T("attr_value")));
ff392ecf
VK
1630
1631 // Convert strings in object_custom_attributes table
1632 DB_RESULT hResult = SQLSelect(_T("SELECT object_id,attr_name,attr_value FROM object_custom_attributes"));
1633 if (hResult != NULL)
1634 {
1635 if (SQLQuery(_T("DELETE FROM object_custom_attributes")))
1636 {
1637 TCHAR errorText[DBDRV_MAX_ERROR_TEXT];
1638 DB_STATEMENT hStmt = DBPrepareEx(g_hCoreDB, insertQuery, errorText);
1639 if (hStmt != NULL)
1640 {
1641 TCHAR name[128], *value;
1642 int count = DBGetNumRows(hResult);
1643 for(int i = 0; i < count; i++)
1644 {
967893bb 1645 UINT32 id = DBGetFieldULong(hResult, i, 0);
ff392ecf
VK
1646 DBGetField(hResult, i, 1, name, 128);
1647 DecodeSQLString(name);
1648 value = DBGetField(hResult, i, 2, NULL, 0);
1649 DecodeSQLString(value);
1650
1651 DBBind(hStmt, 1, DB_SQLTYPE_INTEGER, id);
1652 DBBind(hStmt, 2, DB_SQLTYPE_VARCHAR, name, DB_BIND_STATIC);
1653 DBBind(hStmt, 3, DB_SQLTYPE_VARCHAR, value, DB_BIND_DYNAMIC);
1654 if (g_bTrace)
1655 ShowQuery(insertQuery);
1656 if (!DBExecuteEx(hStmt, errorText))
1657 {
1658 WriteToTerminalEx(_T("SQL query failed (%s):\n\x1b[33;1m%s\x1b[0m\n"), errorText, insertQuery);
1659 if (!g_bIgnoreErrors)
1660 {
1661 DBFreeStatement(hStmt);
1662 DBFreeResult(hResult);
1663 return FALSE;
1664 }
1665 }
1666 }
1667 DBFreeStatement(hStmt);
1668 }
1669 else
1670 {
1671 WriteToTerminalEx(_T("SQL query failed (%s):\n\x1b[33;1m%s\x1b[0m\n"), errorText, insertQuery);
1672 if (!g_bIgnoreErrors)
1673 {
1674 DBFreeResult(hResult);
1675 return FALSE;
1676 }
1677 }
1678 }
1679 else
1680 {
1681 if (!g_bIgnoreErrors)
1682 {
1683 DBFreeResult(hResult);
1684 return FALSE;
1685 }
1686 }
1687
1688 DBFreeResult(hResult);
1689 }
1690 else
1691 {
1692 if (!g_bIgnoreErrors)
1693 return FALSE;
1694 }
1695
1696 CHK_EXEC(SQLQuery(_T("CREATE INDEX idx_ocattr_oid ON object_custom_attributes(object_id)")));
1697 CHK_EXEC(CreateConfigParam(_T("AlarmHistoryRetentionTime"), _T("180"), 1, 0));
1698
1699 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='247' WHERE var_name='SchemaVersion'")));
1700 return TRUE;
1701}
1702
d6bf58f9
VK
1703/**
1704 * Upgrade from V245 to V246
1705 */
98cd01bb
VK
1706static BOOL H_UpgradeFromV245(int currVersion, int newVersion)
1707{
1708 static TCHAR batch[] =
1709 _T("ALTER TABLE snmp_trap_pmap ADD flags integer\n")
1710 _T("UPDATE snmp_trap_pmap SET flags=0\n")
1711 _T("<END>");
1712
1713 CHK_EXEC(SQLBatch(batch));
1714
480e036b 1715 CHK_EXEC(SetColumnNullable(_T("snmp_trap_pmap"), _T("description")));
d6bf58f9 1716 CHK_EXEC(ConvertStrings(_T("snmp_trap_pmap"), _T("trap_id"), _T("parameter"), _T("description"), false));
98cd01bb 1717
480e036b 1718 CHK_EXEC(SetColumnNullable(_T("cluster_resources"), _T("resource_name")));
d6bf58f9 1719 CHK_EXEC(ConvertStrings(_T("cluster_resources"), _T("cluster_id"), _T("resource_id"), _T("resource_name"), false));
98cd01bb
VK
1720
1721 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='246' WHERE var_name='SchemaVersion'")));
1722 return TRUE;
1723}
1724
d6bf58f9
VK
1725/**
1726 * Upgrade from V244 to V245
1727 */
4866d57b
VK
1728static BOOL H_UpgradeFromV244(int currVersion, int newVersion)
1729{
1730 static TCHAR batch[] =
1731 _T("ALTER TABLE nodes ADD runtime_flags integer\n")
1732 _T("UPDATE nodes SET runtime_flags=0\n")
1733 _T("<END>");
1734
1735 CHK_EXEC(SQLBatch(batch));
1736
480e036b
VK
1737 CHK_EXEC(SetColumnNullable(_T("actions"), _T("rcpt_addr")));
1738 CHK_EXEC(SetColumnNullable(_T("actions"), _T("email_subject")));
1739 CHK_EXEC(SetColumnNullable(_T("actions"), _T("action_data")));
4866d57b
VK
1740
1741 CHK_EXEC(ConvertStrings(_T("actions"), _T("action_id"), _T("rcpt_addr")));
1742 CHK_EXEC(ConvertStrings(_T("actions"), _T("action_id"), _T("email_subject")));
1743 CHK_EXEC(ConvertStrings(_T("actions"), _T("action_id"), _T("action_data")));
1744
1745 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='245' WHERE var_name='SchemaVersion'")));
1746 return TRUE;
1747}
1748
1749
aa16f82b
VK
1750//
1751// Upgrade from V243 to V244
1752//
1753
1754static BOOL H_UpgradeFromV243(int currVersion, int newVersion)
1755{
1756 static TCHAR batch[] =
1757 _T("ALTER TABLE interfaces ADD dot1x_pae_state integer\n")
1758 _T("ALTER TABLE interfaces ADD dot1x_backend_state integer\n")
1759 _T("UPDATE interfaces SET dot1x_pae_state=0,dot1x_backend_state=0\n")
1760 _T("<END>");
1761
1762 CHK_EXEC(SQLBatch(batch));
1763
1764 CHK_EXEC(CreateEventTemplate(EVENT_8021X_PAE_STATE_CHANGED, _T("SYS_8021X_PAE_STATE_CHANGED"),
1765 EVENT_SEVERITY_NORMAL, 1, _T("Port %6 PAE state changed from %4 to %2"),
1766 _T("Generated when switch port PAE state changed.\r\nParameters:\r\n")
1767 _T(" 1) New PAE state code\r\n")
1768 _T(" 2) New PAE state as text\r\n")
1769 _T(" 3) Old PAE state code\r\n")
1770 _T(" 4) Old PAE state as text\r\n")
1771 _T(" 5) Interface index\r\n")
1772 _T(" 6) Interface name")));
1773
1774 CHK_EXEC(CreateEventTemplate(EVENT_8021X_BACKEND_STATE_CHANGED, _T("SYS_8021X_BACKEND_STATE_CHANGED"),
1775 EVENT_SEVERITY_NORMAL, 1, _T("Port %6 backend authentication state changed from %4 to %2"),
1776 _T("Generated when switch port backend authentication state changed.\r\nParameters:\r\n")
1777 _T(" 1) New backend state code\r\n")
1778 _T(" 2) New backend state as text\r\n")
1779 _T(" 3) Old backend state code\r\n")
1780 _T(" 4) Old backend state as text\r\n")
1781 _T(" 5) Interface index\r\n")
1782 _T(" 6) Interface name")));
1783
1784 CHK_EXEC(CreateEventTemplate(EVENT_8021X_PAE_FORCE_UNAUTH, _T("SYS_8021X_PAE_FORCE_UNAUTH"),
1785 EVENT_SEVERITY_MAJOR, 1, _T("Port %2 switched to force unauthorize state"),
1786 _T("Generated when switch port PAE state changed to FORCE UNAUTHORIZE.\r\nParameters:\r\n")
1787 _T(" 1) Interface index\r\n")
1788 _T(" 2) Interface name")));
1789
1790 CHK_EXEC(CreateEventTemplate(EVENT_8021X_AUTH_FAILED, _T("SYS_8021X_AUTH_FAILED"),
1791 EVENT_SEVERITY_MAJOR, 1, _T("802.1x authentication failed on port %2"),
1792 _T("Generated when switch port backend authentication state changed to FAIL.\r\nParameters:\r\n")
1793 _T(" 1) Interface index\r\n")
1794 _T(" 2) Interface name")));
1795
1796 CHK_EXEC(CreateEventTemplate(EVENT_8021X_AUTH_TIMEOUT, _T("SYS_8021X_AUTH_TIMEOUT"),
1797 EVENT_SEVERITY_MAJOR, 1, _T("802.1x authentication time out on port %2"),
1798 _T("Generated when switch port backend authentication state changed to TIMEOUT.\r\nParameters:\r\n")
1799 _T(" 1) Interface index\r\n")
1800 _T(" 2) Interface name")));
1801
1802 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='244' WHERE var_name='SchemaVersion'")));
1803 return TRUE;
1804}
1805
1806
e320f8ce
VK
1807//
1808// Upgrade from V242 to V243
1809//
1810
1811static BOOL H_UpgradeFromV242(int currVersion, int newVersion)
1812{
1813 static TCHAR batch[] =
242e9c7f
VK
1814 _T("ALTER TABLE items ADD snmp_raw_value_type integer\n")
1815 _T("UPDATE items SET snmp_raw_value_type=0\n")
e320f8ce
VK
1816 _T("ALTER TABLE items ADD flags integer\n")
1817 _T("UPDATE items SET flags=adv_schedule+(all_thresholds*2)\n")
1818 _T("ALTER TABLE items DROP COLUMN adv_schedule\n")
1819 _T("ALTER TABLE items DROP COLUMN all_thresholds\n")
e320f8ce
VK
1820 _T("<END>");
1821
1822 CHK_EXEC(SQLBatch(batch));
1823 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='243' WHERE var_name='SchemaVersion'")));
1824 return TRUE;
1825}
1826
1827
f5e80875
VK
1828//
1829// Upgrade from V241 to V242
1830//
1831
1832static BOOL H_UpgradeFromV241(int currVersion, int newVersion)
1833{
1834 static TCHAR batch[] =
1835 _T("DROP TABLE business_service_templates\n")
1836 _T("ALTER TABLE dashboards ADD options integer\n")
1837 _T("UPDATE dashboards SET options=0\n")
1838 _T("<END>");
1839
1840 CHK_EXEC(SQLBatch(batch));
1841 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='242' WHERE var_name='SchemaVersion'")));
1842 return TRUE;
1843}
1844
1845
6ff21d27
VK
1846//
1847// Upgrade from V240 to V241
1848//
1849
1850static BOOL H_UpgradeFromV240(int currVersion, int newVersion)
1851{
1852 static TCHAR batch[] =
1853 _T("ALTER TABLE slm_checks ADD template_id integer\n")
1854 _T("ALTER TABLE slm_checks ADD current_ticket integer\n")
1855 _T("UPDATE slm_checks SET template_id=0,current_ticket=0\n")
1856 _T("<END>");
1857
1858 CHK_EXEC(SQLBatch(batch));
1859 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='241' WHERE var_name='SchemaVersion'")));
1860 return TRUE;
1861}
1862
1863
5fe19f9e
VK
1864//
1865// Upgrade from V239 to V240
1866//
1867
1868static BOOL H_UpgradeFromV239(int currVersion, int newVersion)
1869{
1870 CHK_EXEC(SQLQuery(_T("ALTER TABLE raw_dci_values ADD transformed_value varchar(255)")));
1871 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='240' WHERE var_name='SchemaVersion'")));
1872 return TRUE;
1873}
1874
1875
5a7d6a10
VK
1876//
1877// Upgrade from V238 to V239
1878//
1879
1880static BOOL H_UpgradeFromV238(int currVersion, int newVersion)
1881{
1882 CHK_EXEC(SQLQuery(
1883 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES ")
1884 _T("(56,'SYS_IP_ADDRESS_CHANGED',1,1,'Primary IP address changed from %2 to %1',")
1885 _T("'Generated when primary IP address changed (usually because of primary name change or DNS change).#0D#0A")
1886 _T("Parameters:#0D#0A 1) New IP address#0D#0A 2) Old IP address#0D#0A 3) Primary host name')")));
1887
1888 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='239' WHERE var_name='SchemaVersion'")));
1889 return TRUE;
1890}
1891
1892
34ccf87f
VK
1893//
1894// Upgrade from V232 to V238
1895//
1896
1897static BOOL H_UpgradeFromV232toV238(int currVersion, int newVersion)
1898{
1899 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_checks (")
1900 _T("id integer not null,")
1901 _T("type integer not null,")
1902 _T("content $SQL:TEXT null,")
1903 _T("threshold_id integer not null,")
1904 _T("reason varchar(255) null,")
1905 _T("is_template integer not null,")
1906 _T("PRIMARY KEY(id))")));
1907
1908 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_tickets (")
1909 _T("ticket_id integer not null,")
1910 _T("service_id integer not null,")
1911 _T("check_id integer not null,")
1912 _T("create_timestamp integer not null,")
1913 _T("close_timestamp integer not null,")
1914 _T("reason varchar(255) null,")
1915 _T("PRIMARY KEY(ticket_id))")));
1916
1917 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_service_history (")
1918 _T("record_id integer not null,")
1919 _T("service_id integer not null,")
1920 _T("change_timestamp integer not null,")
1921 _T("new_status integer not null,")
1922 _T("PRIMARY KEY(record_id))")));
1923
1924 CHK_EXEC(CreateTable(_T("CREATE TABLE report_results (")
1925 _T("report_id integer not null,")
1926 _T("generated integer not null,")
1927 _T("job_id integer not null,")
1928 _T("PRIMARY KEY(report_id,job_id))")));
1929
1930 CHK_EXEC(CreateTable(_T("CREATE TABLE reports (")
1931 _T("id integer not null,")
1932 _T("definition $SQL:TEXT null,")
1933 _T("PRIMARY KEY(id))")));
1934
1935 CHK_EXEC(CreateTable(_T("CREATE TABLE job_history (")
1936 _T("id integer not null,")
1937 _T("time_created integer not null,")
1938 _T("time_started integer not null,")
1939 _T("time_finished integer not null,")
1940 _T("job_type varchar(127) null,")
1941 _T("description varchar(255) null,")
1942 _T("additional_info varchar(255) null,")
1943 _T("node_id integer not null,")
1944 _T("user_id integer not null,")
1945 _T("status integer not null,")
1946 _T("failure_message varchar(255) null,")
1947 _T("PRIMARY KEY(id))")));
1948
1949 CHK_EXEC(CreateTable(_T("CREATE TABLE business_services (")
1950 _T("service_id integer not null,")
1951 _T("PRIMARY KEY(service_id))")));
1952
1953 CHK_EXEC(CreateTable(_T("CREATE TABLE business_service_templates (")
1954 _T("service_id integer not null,")
1955 _T("template_id integer not null,")
1956 _T("PRIMARY KEY(service_id,template_id))")));
1957
1958 CHK_EXEC(CreateTable(_T("CREATE TABLE node_links (")
1959 _T("nodelink_id integer not null,")
1960 _T("node_id integer not null,")
1961 _T("PRIMARY KEY(nodelink_id))")));
1962
1963 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_agreements (")
1964 _T("agreement_id integer not null,")
1965 _T("service_id integer not null,")
1966 _T("org_id integer not null,")
1967 _T("uptime varchar(63) not null,")
1968 _T("period integer not null,")
1969 _T("start_date integer not null,")
1970 _T("notes varchar(255),")
1971 _T("PRIMARY KEY(agreement_id))")));
1972
1973 CHK_EXEC(CreateTable(_T("CREATE TABLE organizations (")
1974 _T("id integer not null,")
1975 _T("parent_id integer not null,")
1976 _T("org_type integer not null,")
1977 _T("name varchar(63) not null,")
1978 _T("description varchar(255),")
1979 _T("manager integer not null,")
1980 _T("PRIMARY KEY(id))")));
1981
1982 CHK_EXEC(CreateTable(_T("CREATE TABLE persons (")
1983 _T("id integer not null,")
1984 _T("org_id integer not null,")
1985 _T("first_name varchar(63),")
1986 _T("last_name varchar(63),")
1987 _T("title varchar(255),")
1988 _T("status integer not null,")
1989 _T("PRIMARY KEY(id))")));
1990
1991 CHK_EXEC(CreateConfigParam(_T("JobHistoryRetentionTime"), _T("90"), 1, 0));
1992
1993 CHK_EXEC(SQLQuery(_T("UPDATE event_cfg SET description=")
1994 _T("'Generated when threshold check is rearmed for specific data collection item.#0D#0A")
1995 _T("Parameters:#0D#0A")
1996 _T(" 1) Parameter name#0D#0A")
1997 _T(" 2) Item description#0D#0A")
1998 _T(" 3) Data collection item ID#0D#0A")
1999 _T(" 4) Instance#0D#0A")
2000 _T(" 5) Threshold value#0D#0A")
2001 _T(" 6) Actual value' WHERE event_code=18")));
2002
2003 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='238' WHERE var_name='SchemaVersion'")));
2004 return TRUE;
2005}
2006
2007
9c529287
VK
2008//
2009// Upgrade from V237 to V238
2010//
2011
2012static BOOL H_UpgradeFromV237(int currVersion, int newVersion)
2013{
2014 static TCHAR batch[] =
2015 _T("DROP TABLE slm_check_templates\n")
2016 _T("DROP TABLE node_link_checks\n")
2017 _T("DROP TABLE slm_checks\n")
2018 _T("DROP TABLE slm_tickets\n")
2019 _T("<END>");
2020
2021 CHK_EXEC(SQLBatch(batch));
2022
2023 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_checks (")
2024 _T("id integer not null,")
2025 _T("type integer not null,")
2026 _T("content $SQL:TEXT null,")
2027 _T("threshold_id integer not null,")
2028 _T("reason varchar(255) null,")
2029 _T("is_template integer not null,")
2030 _T("PRIMARY KEY(id))")));
2031
2032 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_tickets (")
2033 _T("ticket_id integer not null,")
2034 _T("service_id integer not null,")
2035 _T("check_id integer not null,")
2036 _T("create_timestamp integer not null,")
2037 _T("close_timestamp integer not null,")
2038 _T("reason varchar(255) null,")
2039 _T("PRIMARY KEY(ticket_id))")));
2040
2041 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_service_history (")
2042 _T("record_id integer not null,")
2043 _T("service_id integer not null,")
2044 _T("change_timestamp integer not null,")
2045 _T("new_status integer not null,")
2046 _T("PRIMARY KEY(record_id))")));
2047
2048 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='238' WHERE var_name='SchemaVersion'")));
2049 return TRUE;
2050}
2051
2052
f5c9fdc5
VK
2053//
2054// Upgrade from V236 to V237
2055//
2056
2057static BOOL H_UpgradeFromV236(int currVersion, int newVersion)
2058{
2059 static TCHAR batch[] =
2060 _T("ALTER TABLE business_services DROP COLUMN name\n")
2061 _T("ALTER TABLE business_services DROP COLUMN parent_id\n")
2062 _T("ALTER TABLE business_services DROP COLUMN status\n")
2063 _T("ALTER TABLE slm_checks DROP COLUMN name\n")
2064 _T("<END>");
2065
2066 CHK_EXEC(SQLBatch(batch));
2067
2068 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='237' WHERE var_name='SchemaVersion'")));
2069 return TRUE;
2070}
2071
2072
5418326b
AK
2073//
2074// Upgrade from V235 to V236
2075//
2076
2077static BOOL H_UpgradeFromV235(int currVersion, int newVersion)
2078{
2079 CHK_EXEC(CreateTable(_T("CREATE TABLE report_results (")
2080 _T("report_id integer not null,")
2081 _T("generated integer not null,")
2082 _T("job_id integer not null,")
2083 _T("PRIMARY KEY(report_id,job_id))")));
2084
2085 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='236' WHERE var_name='SchemaVersion'")));
2086 return TRUE;
2087}
2088
2089
845b8121
VK
2090//
2091// Upgrade from V234 to V235
2092//
2093
2094static BOOL H_UpgradeFromV234(int currVersion, int newVersion)
2095{
2096 CHK_EXEC(CreateTable(_T("CREATE TABLE reports (")
2097 _T("id integer not null,")
2098 _T("definition $SQL:TEXT null,")
2099 _T("PRIMARY KEY(id))")));
2100
845b8121
VK
2101 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='235' WHERE var_name='SchemaVersion'")));
2102 return TRUE;
2103}
2104
2105
878b4261
VK
2106//
2107// Upgrade from V233 to V234
2108//
2109
2110static BOOL H_UpgradeFromV233(int currVersion, int newVersion)
2111{
2112 CHK_EXEC(CreateTable(_T("CREATE TABLE job_history (")
2113 _T("id integer not null,")
2114 _T("time_created integer not null,")
2115 _T("time_started integer not null,")
2116 _T("time_finished integer not null,")
2117 _T("job_type varchar(127) null,")
2118 _T("description varchar(255) null,")
24dc5346 2119 _T("additional_info varchar(255) null,")
878b4261
VK
2120 _T("node_id integer not null,")
2121 _T("user_id integer not null,")
2122 _T("status integer not null,")
2123 _T("failure_message varchar(255) null,")
2124 _T("PRIMARY KEY(id))")));
2125
2126 CHK_EXEC(CreateConfigParam(_T("JobHistoryRetentionTime"), _T("90"), 1, 0));
2127
2128 CHK_EXEC(SQLQuery(_T("UPDATE event_cfg SET description=")
2129 _T("'Generated when threshold check is rearmed for specific data collection item.#0D#0A")
2130 _T("Parameters:#0D#0A")
2131 _T(" 1) Parameter name#0D#0A")
2132 _T(" 2) Item description#0D#0A")
2133 _T(" 3) Data collection item ID#0D#0A")
2134 _T(" 4) Instance#0D#0A")
2135 _T(" 5) Threshold value#0D#0A")
2136 _T(" 6) Actual value' WHERE event_code=18")));
2137
2138 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='234' WHERE var_name='SchemaVersion'")));
2139 return TRUE;
2140}
2141
2142
128681c8
VK
2143//
2144// Upgrade from V232 to V233
2145//
2146
2147static BOOL H_UpgradeFromV232(int currVersion, int newVersion)
2148{
2149 CHK_EXEC(CreateTable(_T("CREATE TABLE business_services (")
2150 _T("service_id integer not null,")
2151 _T("name varchar(63) not null,")
2498594e
VK
2152 _T("parent_id integer not null,")
2153 _T("status integer not null,")
128681c8
VK
2154 _T("PRIMARY KEY(service_id))")));
2155
128681c8
VK
2156 CHK_EXEC(CreateTable(_T("CREATE TABLE business_service_templates (")
2157 _T("service_id integer not null,")
2158 _T("template_id integer not null,")
2159 _T("PRIMARY KEY(service_id,template_id))")));
2160
2161 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_checks (")
2162 _T("check_id integer not null,")
2163 _T("name varchar(63) not null,")
2498594e 2164 _T("type integer not null,")
128681c8 2165 _T("content $SQL:TEXT,")
2498594e 2166 _T("threshold_id integer not null,")
128681c8
VK
2167 _T("state integer not null,")
2168 _T("reason varchar(255) not null,")
2169 _T("PRIMARY KEY(check_id))")));
2170
2171 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_check_templates (")
2172 _T("id integer not null,")
2173 _T("name varchar(63) not null,")
2498594e 2174 _T("type integer not null,")
128681c8 2175 _T("content $SQL:TEXT,")
2498594e 2176 _T("threshold_id integer not null,")
128681c8
VK
2177 _T("PRIMARY KEY(id))")));
2178
2179 CHK_EXEC(CreateTable(_T("CREATE TABLE node_links (")
2180 _T("nodelink_id integer not null,")
2181 _T("node_id integer not null,")
2182 _T("PRIMARY KEY(nodelink_id))")));
2183
2184 CHK_EXEC(CreateTable(_T("CREATE TABLE node_link_checks (")
2185 _T("nodelink_id integer not null,")
2186 _T("check_id integer not null,")
2187 _T("PRIMARY KEY(nodelink_id,check_id))")));
2188
2189 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_agreements (")
2190 _T("agreement_id integer not null,")
2191 _T("service_id integer not null,")
2192 _T("org_id integer not null,")
2193 _T("uptime varchar(63) not null,")
2194 _T("period integer not null,")
2195 _T("start_date integer not null,")
2196 _T("notes varchar(255),")
2197 _T("PRIMARY KEY(agreement_id))")));
2198
2199 CHK_EXEC(CreateTable(_T("CREATE TABLE slm_tickets (")
2200 _T("ticket_id integer not null,")
2201 _T("service_id integer not null,")
2202 _T("create_timestamp integer not null,")
2203 _T("close_timestamp integer not null,")
2204 _T("reason varchar(255) not null,")
2205 _T("PRIMARY KEY(ticket_id))")));
2206
2207 CHK_EXEC(CreateTable(_T("CREATE TABLE organizations (")
2208 _T("id integer not null,")
2209 _T("parent_id integer not null,")
2210 _T("org_type integer not null,")
2211 _T("name varchar(63) not null,")
2212 _T("description varchar(255),")
2213 _T("manager integer not null,")
2214 _T("PRIMARY KEY(id))")));
2215
2216 CHK_EXEC(CreateTable(_T("CREATE TABLE persons (")
2217 _T("id integer not null,")
2218 _T("org_id integer not null,")
2219 _T("first_name varchar(63),")
2220 _T("last_name varchar(63),")
2221 _T("title varchar(255),")
2222 _T("status integer not null,")
2223 _T("PRIMARY KEY(id))")));
2224
2225 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='233' WHERE var_name='SchemaVersion'")));
2226 return TRUE;
2227}
2228
2229
8f245200
VK
2230//
2231// Upgrade from V231 to V232
2232//
2233
2234static BOOL H_UpgradeFromV231(int currVersion, int newVersion)
2235{
2236 static TCHAR batch[] =
2237 _T("ALTER TABLE object_properties ADD submap_id integer\n")
2238 _T("UPDATE object_properties SET submap_id=0\n")
2239 _T("DROP TABLE maps\n")
2240 _T("DROP TABLE map_access_lists\n")
2241 _T("DROP TABLE submaps\n")
2242 _T("DROP TABLE submap_object_positions\n")
2243 _T("DROP TABLE submap_links\n")
2244 _T("<END>");
2245
2246 CHK_EXEC(SQLBatch(batch));
2247
2248 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='232' WHERE var_name='SchemaVersion'")));
2249 return TRUE;
2250}
2251
2252
3eab63f2
VK
2253//
2254// Upgrade from V230 to V231
2255//
2256
2257static BOOL H_UpgradeFromV230(int currVersion, int newVersion)
2258{
2259 static TCHAR batch[] =
2260 _T("ALTER TABLE nodes ADD bridge_base_addr varchar(15)\n")
2261 _T("UPDATE nodes SET bridge_base_addr='000000000000'\n")
2262 _T("<END>");
2263
2264 CHK_EXEC(SQLBatch(batch));
2265
2266 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='231' WHERE var_name='SchemaVersion'")));
2267 return TRUE;
2268}
2269
2270
fceea457
VK
2271//
2272// Upgrade from V229 to V230
2273//
2274
2275static BOOL H_UpgradeFromV229(int currVersion, int newVersion)
2276{
2277 static TCHAR batch1[] =
1a74dc37
VK
2278 _T("ALTER TABLE network_maps ADD bg_latitude varchar(20)\n")
2279 _T("ALTER TABLE network_maps ADD bg_longitude varchar(20)\n")
2280 _T("ALTER TABLE network_maps ADD bg_zoom integer\n")
fceea457
VK
2281 _T("ALTER TABLE dashboard_elements ADD layout_data $SQL:TEXT\n")
2282 _T("<END>");
2283
2284 CHK_EXEC(SQLBatch(batch1));
2285
2286 DB_RESULT hResult = SQLSelect(_T("SELECT dashboard_id,element_id,horizontal_span,vertical_span,horizontal_alignment,vertical_alignment FROM dashboard_elements"));
2287 if (hResult != NULL)
2288 {
2289 TCHAR query[1024], xml[1024];
2290
2291 int count = DBGetNumRows(hResult);
2292 for(int i = 0; i < count; i++)
2293 {
2294 _sntprintf(xml, 1024, _T("<layout><horizontalSpan>%d</horizontalSpan><verticalSpan>%d</verticalSpan><horizontalAlignment>%d</horizontalAlignment><verticalAlignment>%d</verticalAlignment></layout>"),
2295 (int)DBGetFieldLong(hResult, i, 2), (int)DBGetFieldLong(hResult, i, 3),
2296 (int)DBGetFieldLong(hResult, i, 4), (int)DBGetFieldLong(hResult, i, 5));
2297 _sntprintf(query, 1024, _T("UPDATE dashboard_elements SET layout_data=%s WHERE dashboard_id=%d AND element_id=%d"),
2298 (const TCHAR *)DBPrepareString(g_hCoreDB, xml), (int)DBGetFieldLong(hResult, i, 0), (int)DBGetFieldLong(hResult, i, 1));
2299 CHK_EXEC(SQLQuery(query));
2300 }
2301 DBFreeResult(hResult);
2302 }
2303 else
2304 {
2305 if (!g_bIgnoreErrors)
2306 return FALSE;
2307 }
2308
2309 static TCHAR batch2[] =
2310 _T("ALTER TABLE dashboard_elements DROP COLUMN horizontal_span\n")
2311 _T("ALTER TABLE dashboard_elements DROP COLUMN vertical_span\n")
2312 _T("ALTER TABLE dashboard_elements DROP COLUMN horizontal_alignment\n")
2313 _T("ALTER TABLE dashboard_elements DROP COLUMN vertical_alignment\n")
2314 _T("<END>");
2315
2316 CHK_EXEC(SQLBatch(batch2));
2317
2318 CreateConfigParam(_T("TileServerURL"), _T("http://tile.openstreetmap.org/"), 1, 0);
2319
2320 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='230' WHERE var_name='SchemaVersion'")));
2321 return TRUE;
2322}
2323
2324
926e8ce7
VK
2325//
2326// Upgrade from V228 to V229
2327//
2328
2329static BOOL H_UpgradeFromV228(int currVersion, int newVersion)
2330{
2331 CHK_EXEC(CreateTable(_T("CREATE TABLE dashboards (")
2332 _T(" id integer not null,")
2333 _T(" num_columns integer not null,")
2334 _T(" PRIMARY KEY(id))")));
2335
2336 CHK_EXEC(CreateTable(_T("CREATE TABLE dashboard_elements (")
2337 _T(" dashboard_id integer not null,")
2338 _T(" element_id integer not null,")
2339 _T(" element_type integer not null,")
2340 _T(" element_data $SQL:TEXT null,")
2341 _T(" horizontal_span integer not null,")
2342 _T(" vertical_span integer not null,")
2343 _T(" horizontal_alignment integer not null,")
2344 _T(" vertical_alignment integer not null,")
2345 _T(" PRIMARY KEY(dashboard_id,element_id))")));
2346
2347 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='229' WHERE var_name='SchemaVersion'")));
2348 return TRUE;
2349}
2350
badf9a95
VK
2351/**
2352 * Upgrade from V227 to V228
2353 */
7a41a06e
VK
2354static BOOL H_UpgradeFromV227(int currVersion, int newVersion)
2355{
2356 CHK_EXEC(SQLQuery(_T("DROP TABLE web_maps")));
2357 CHK_EXEC(MigrateMaps());
2358 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='228' WHERE var_name='SchemaVersion'")));
2359 return TRUE;
2360}
2361
badf9a95
VK
2362/**
2363 * Upgrade from V226 to V227
2364 */
89135050
VK
2365static BOOL H_UpgradeFromV226(int currVersion, int newVersion)
2366{
2367 static TCHAR batch[] =
2368 _T("ALTER TABLE clusters ADD zone_guid integer\n")
2369 _T("UPDATE clusters SET zone_guid=0\n")
2370 _T("<END>");
2371
2372 CHK_EXEC(SQLBatch(batch));
2373
2374 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='227' WHERE var_name='SchemaVersion'")));
2375 return TRUE;
2376}
2377
2378
4c16cdc7
VK
2379//
2380// Upgrade from V225 to V226
2381//
2382
2383static BOOL H_UpgradeFromV225(int currVersion, int newVersion)
2384{
2385 static TCHAR batch[] =
2386 _T("ALTER TABLE interfaces ADD flags integer\n")
2387 _T("UPDATE interfaces SET flags=0\n")
2388 _T("UPDATE interfaces SET flags=1 WHERE synthetic_mask<>0\n")
2389 _T("ALTER TABLE interfaces DROP COLUMN synthetic_mask\n")
2390 _T("<END>");
2391
2392 CHK_EXEC(SQLBatch(batch));
2393
2394 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='226' WHERE var_name='SchemaVersion'")));
2395 return TRUE;
2396}
2397
2398
478d4ff4
VK
2399//
2400// Upgrade from V224 to V225
2401//
2402
2403static BOOL H_UpgradeFromV224(int currVersion, int newVersion)
2404{
2405 static TCHAR batch[] =
2406 _T("ALTER TABLE interfaces ADD description varchar(255)\n")
2407 _T("UPDATE interfaces SET description=''\n")
2408 _T("<END>");
2409
2410 CHK_EXEC(SQLBatch(batch));
2411
2412 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='225' WHERE var_name='SchemaVersion'")));
2413 return TRUE;
2414}
2415
badf9a95
VK
2416/**
2417 * Upgrade from V223 to V224
2418 */
52c31148
VK
2419static BOOL H_UpgradeFromV223(int currVersion, int newVersion)
2420{
2421 static TCHAR batch[] =
2422 _T("DROP TABLE zone_ip_addr_list\n")
2423 _T("ALTER TABLE zones DROP COLUMN zone_type\n")
2424 _T("ALTER TABLE zones DROP COLUMN controller_ip\n")
2425 _T("ALTER TABLE zones ADD agent_proxy integer\n")
2426 _T("ALTER TABLE zones ADD snmp_proxy integer\n")
2427 _T("ALTER TABLE zones ADD icmp_proxy integer\n")
2428 _T("UPDATE zones SET agent_proxy=0,snmp_proxy=0,icmp_proxy=0\n")
2429 _T("<END>");
2430
2431 CHK_EXEC(SQLBatch(batch));
2432
2433 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='224' WHERE var_name='SchemaVersion'")));
2434 return TRUE;
2435}
2436
badf9a95
VK
2437/**
2438 * Upgrade from V222 to V223
2439 */
5ad2167d
VK
2440static BOOL H_UpgradeFromV222(int currVersion, int newVersion)
2441{
2442 static TCHAR batch[] =
2443 _T("DROP TABLE oid_to_type\n")
2444 _T("ALTER TABLE nodes DROP COLUMN node_type\n")
2445 _T("ALTER TABLE nodes ADD primary_name varchar(255)\n")
2446 _T("UPDATE nodes SET primary_name=primary_ip\n")
2447 _T("<END>");
2448
2449 CHK_EXEC(SQLBatch(batch));
2450
2451 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='223' WHERE var_name='SchemaVersion'")));
2452 return TRUE;
2453}
2454
2455
465b3f2d 2456//
f25b0d12
VK
2457// Upgrade from V221 to V222
2458//
2459
2460static BOOL H_UpgradeFromV221(int currVersion, int newVersion)
2461{
2462 static TCHAR batch[] =
2463 _T("ALTER TABLE object_properties ADD image varchar(36)\n")
2464 _T("UPDATE object_properties SET image='00000000-0000-0000-0000-000000000000'\n")
2465 _T("<END>");
2466
2467 CHK_EXEC(SQLBatch(batch));
2468
2469 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='222' WHERE var_name='SchemaVersion'")));
2470 return TRUE;
2471}
2472
2473
2474//
2475// Upgrade from V220 to V221
465b3f2d
VK
2476//
2477
2478static BOOL H_UpgradeFromV220(int currVersion, int newVersion)
2479{
2480 static TCHAR batch[] =
2481 _T("ALTER TABLE network_maps DROP COLUMN background\n")
2482 _T("ALTER TABLE network_maps ADD background varchar(36)\n")
2483 _T("<END>");
2484
2485 CHK_EXEC(SQLBatch(batch));
2486
2487 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='221' WHERE var_name='SchemaVersion'")));
2488 return TRUE;
2489}
2490
2491
d74c80ea
VK
2492//
2493// Upgrade from V219 to V220
2494//
2495
2496static BOOL H_UpgradeFromV219(int currVersion, int newVersion)
2497{
2498 static TCHAR batch[] =
2499 _T("ALTER TABLE interfaces ADD bridge_port integer\n")
2500 _T("ALTER TABLE interfaces ADD phy_slot integer\n")
2501 _T("ALTER TABLE interfaces ADD phy_port integer\n")
2502 _T("ALTER TABLE interfaces ADD peer_node_id integer\n")
2503 _T("ALTER TABLE interfaces ADD peer_if_id integer\n")
2504 _T("UPDATE interfaces SET bridge_port=0,phy_slot=0,phy_port=0,peer_node_id=0,peer_if_id=0\n")
2505 _T("ALTER TABLE nodes ADD snmp_sys_name varchar(127)\n")
2506 _T("UPDATE nodes SET snmp_sys_name=''\n")
2507 _T("<END>");
2508
2509 CHK_EXEC(SQLBatch(batch));
2510
2511 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='220' WHERE var_name='SchemaVersion'")));
2512 return TRUE;
2513}
2514
2515
e6b9439a
AK
2516//
2517// Upgrade from V218 to V219
2518//
2519
2520static BOOL H_UpgradeFromV218(int currVersion, int newVersion)
2521{
2522 CHK_EXEC(CreateTable(_T("CREATE TABLE images (")
9cd5201a
AK
2523 _T(" guid varchar(36) not null,")
2524 _T(" mimetype varchar(64) not null,")
2525 _T(" name varchar(255) not null,")
e6b9439a
AK
2526 _T(" category varchar(255) not null,")
2527 _T(" protected integer default 0,")
2528 _T(" ")
9cd5201a
AK
2529 _T(" PRIMARY KEY(guid),")
2530 _T(" UNIQUE(name, category))")));
2531
2532 static TCHAR batch[] =
2533 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2534 _T("('1ddb76a3-a05f-4a42-acda-22021768feaf', 'image/png', 'ATM', 'Network Objects', 1)\n")
9cd5201a 2535 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2536 _T("('b314cf44-b2aa-478e-b23a-73bc5bb9a624', 'image/png', 'HSM', 'Network Objects', 1)\n")
9cd5201a 2537 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2538 _T("('904e7291-ee3f-41b7-8132-2bd29288ecc8', 'image/png', 'Node', 'Network Objects', 1)\n")
9cd5201a 2539 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2540 _T("('f5214d16-1ab1-4577-bb21-063cfd45d7af', 'image/png', 'Printer', 'Network Objects', 1)\n")
9cd5201a 2541 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2542 _T("('bacde727-b183-4e6c-8dca-ab024c88b999', 'image/png', 'Router', 'Network Objects', 1)\n")
9cd5201a 2543 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2544 _T("('ba6ab507-f62d-4b8f-824c-ca9d46f22375', 'image/png', 'Server', 'Network Objects', 1)\n")
9cd5201a 2545 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2546 _T("('092e4b35-4e7c-42df-b9b7-d5805bfac64e', 'image/png', 'Service', 'Network Objects', 1)\n")
9cd5201a 2547 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2548 _T("('f9105c54-8dcf-483a-b387-b4587dfd3cba', 'image/png', 'Switch', 'Network Objects', 1)\n")
9cd5201a 2549 _T("INSERT INTO images (guid, mimetype, name, category, protected) VALUES ")
a32a5bc3 2550 _T("('7cd999e9-fbe0-45c3-a695-f84523b3a50c', 'image/png', 'Unknown', 'Network Objects', 1)\n")
9cd5201a
AK
2551 _T("<END>");
2552
2553 CHK_EXEC(SQLBatch(batch));
e6b9439a
AK
2554
2555 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='219' WHERE var_name='SchemaVersion'")));
2556 return TRUE;
2557}
2558
480e036b
VK
2559/**
2560 * Upgrade from V217 to V218
2561 */
4fe87cdc
VK
2562static BOOL H_UpgradeFromV217(int currVersion, int newVersion)
2563{
480e036b 2564 CHK_EXEC(SetColumnNullable(_T("snmp_communities"), _T("community")));
4fe87cdc
VK
2565 CHK_EXEC(ConvertStrings(_T("snmp_communities"), _T("id"), _T("community")));
2566
2567 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='218' WHERE var_name='SchemaVersion'")));
2568 return TRUE;
2569}
2570
480e036b
VK
2571/**
2572 * Upgrade from V216 to V217
2573 */
65e2005b
VK
2574static BOOL H_UpgradeFromV216(int currVersion, int newVersion)
2575{
2576 static TCHAR batch[] =
2577 _T("ALTER TABLE nodes ADD snmp_port integer\n")
8cad4ebb 2578 _T("UPDATE nodes SET snmp_port=161\n")
65e2005b
VK
2579 _T("ALTER TABLE items ADD snmp_port integer\n")
2580 _T("UPDATE items SET snmp_port=0\n")
2581 _T("<END>");
2582
2583 CHK_EXEC(SQLBatch(batch));
2584
480e036b 2585 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("community")));
65e2005b
VK
2586 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("community")));
2587
480e036b 2588 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("usm_auth_password")));
65e2005b
VK
2589 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("usm_auth_password")));
2590
480e036b 2591 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("usm_priv_password")));
65e2005b
VK
2592 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("usm_priv_password")));
2593
480e036b 2594 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("snmp_oid")));
65e2005b
VK
2595 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("snmp_oid")));
2596
480e036b 2597 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("secret")));
65e2005b
VK
2598 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("secret")));
2599
480e036b 2600 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("agent_version")));
65e2005b
VK
2601 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("agent_version")));
2602
480e036b 2603 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("platform_name")));
65e2005b
VK
2604 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("platform_name")));
2605
480e036b 2606 CHK_EXEC(SetColumnNullable(_T("nodes"), _T("uname")));
65e2005b
VK
2607 CHK_EXEC(ConvertStrings(_T("nodes"), _T("id"), _T("uname")));
2608
480e036b 2609 CHK_EXEC(SetColumnNullable(_T("items"), _T("name")));
65e2005b
VK
2610 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("name")));
2611
480e036b 2612 CHK_EXEC(SetColumnNullable(_T("items"), _T("description")));
65e2005b
VK
2613 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("description")));
2614
480e036b 2615 CHK_EXEC(SetColumnNullable(_T("items"), _T("transformation")));
65e2005b
VK
2616 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("transformation")));
2617
480e036b 2618 CHK_EXEC(SetColumnNullable(_T("items"), _T("instance")));
65e2005b
VK
2619 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("instance")));
2620
2621 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='217' WHERE var_name='SchemaVersion'")));
2622 return TRUE;
2623}
2624
480e036b
VK
2625/**
2626 * Upgrade from V215 to V216
2627 */
3f7c0fe4
VK
2628static BOOL H_UpgradeFromV215(int currVersion, int newVersion)
2629{
480e036b 2630 CHK_EXEC(SetColumnNullable(_T("ap_common"), _T("description")));
3f7c0fe4
VK
2631 CHK_EXEC(ConvertStrings(_T("ap_common"), _T("id"), _T("description")));
2632
a6c1f07f
VK
2633 if (g_iSyntax != DB_SYNTAX_SQLITE)
2634 CHK_EXEC(SQLQuery(_T("ALTER TABLE ap_config_files DROP COLUMN file_name")));
2635
480e036b 2636 CHK_EXEC(SetColumnNullable(_T("ap_config_files"), _T("file_content")));
a30fa363
VK
2637 CHK_EXEC(ConvertStrings(_T("ap_config_files"), _T("policy_id"), _T("file_content")));
2638
3f7c0fe4
VK
2639 CHK_EXEC(SQLQuery(_T("ALTER TABLE object_properties ADD guid varchar(36)")));
2640
2641 // Generate GUIDs for all objects
2642 DB_RESULT hResult = SQLSelect(_T("SELECT object_id FROM object_properties"));
2643 if (hResult != NULL)
2644 {
2645 int count = DBGetNumRows(hResult);
2646 for(int i = 0; i < count; i++)
2647 {
2648 uuid_t guid;
2649 TCHAR query[256], buffer[64];
2650
2651 uuid_generate(guid);
2652 _sntprintf(query, 256, _T("UPDATE object_properties SET guid='%s' WHERE object_id=%d"),
2653 uuid_to_string(guid, buffer), DBGetFieldULong(hResult, i, 0));
2654 CHK_EXEC(SQLQuery(query));
2655 }
2656 DBFreeResult(hResult);
2657 }
2658
2659 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='216' WHERE var_name='SchemaVersion'")));
2660 return TRUE;
2661}
2662
2663
021dcda7
VK
2664//
2665// Upgrade from V214 to V215
2666//
2667
2668static BOOL H_UpgradeFromV214(int currVersion, int newVersion)
2669{
2670 CHK_EXEC(CreateTable(_T("CREATE TABLE network_maps (")
2671 _T("id integer not null,")
2672 _T("map_type integer not null,")
2673 _T("layout integer not null,")
2674 _T("seed integer not null,")
2675 _T("background integer not null,")
2676 _T("PRIMARY KEY(id))")));
2677
2678 CHK_EXEC(CreateTable(_T("CREATE TABLE network_map_elements (")
2679 _T("map_id integer not null,")
2680 _T("element_id integer not null,")
2681 _T("element_type integer not null,")
2682 _T("element_data $SQL:TEXT not null,")
2683 _T("PRIMARY KEY(map_id,element_id))")));
2684
cce8f214
VK
2685 CHK_EXEC(CreateTable(_T("CREATE TABLE network_map_links (")
2686 _T("map_id integer not null,")
2687 _T("element1 integer not null,")
2688 _T("element2 integer not null,")
2689 _T("link_type integer not null,")
2690 _T("link_name varchar(255) null,")
2691 _T("connector_name1 varchar(255) null,")
2692 _T("connector_name2 varchar(255) null,")
2693 _T("PRIMARY KEY(map_id,element1,element2))")));
2694
021dcda7
VK
2695 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='215' WHERE var_name='SchemaVersion'")));
2696 return TRUE;
2697}
2698
480e036b
VK
2699/**
2700 * Upgrade from V213 to V214
2701 */
50da2d20
VK
2702static BOOL H_UpgradeFromV213(int currVersion, int newVersion)
2703{
480e036b 2704 CHK_EXEC(SetColumnNullable(_T("script_library"), _T("script_code")));
50da2d20
VK
2705 CHK_EXEC(ConvertStrings(_T("script_library"), _T("script_id"), _T("script_code")));
2706
480e036b 2707 CHK_EXEC(SetColumnNullable(_T("raw_dci_values"), _T("raw_value")));
50da2d20
VK
2708 CHK_EXEC(ConvertStrings(_T("raw_dci_values"), _T("item_id"), _T("raw_value")));
2709
2710 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='CREATE TABLE idata_%d (item_id integer not null,idata_timestamp integer not null,idata_value varchar(255) null)' WHERE var_name='IDataTableCreationCommand'")));
2711
2712 DB_RESULT hResult = SQLSelect(_T("SELECT id FROM nodes"));
2713 if (hResult != NULL)
2714 {
2715 int count = DBGetNumRows(hResult);
2716 for(int i = 0; i < count; i++)
2717 {
2718 TCHAR table[32];
2719
2720 DWORD nodeId = DBGetFieldULong(hResult, i, 0);
2721 _sntprintf(table, 32, _T("idata_%d"), nodeId);
480e036b 2722 CHK_EXEC(SetColumnNullable(table, _T("idata_value")));
50da2d20
VK
2723 }
2724 DBFreeResult(hResult);
2725 }
2726
2727 // Convert values for string DCIs from # encoded to normal form
2728 hResult = SQLSelect(_T("SELECT node_id,item_id FROM items WHERE datatype=4"));
2729 if (hResult != NULL)
2730 {
2731 int count = DBGetNumRows(hResult);
2732 for(int i = 0; i < count; i++)
2733 {
2734 TCHAR query[512];
2735
2736 DWORD nodeId = DBGetFieldULong(hResult, i, 0);
2737 DWORD dciId = DBGetFieldULong(hResult, i, 1);
2738
035a4d73 2739 if (IsNodeExist(nodeId))
50da2d20 2740 {
3f7c0fe4 2741 _sntprintf(query, 512, _T("SELECT idata_timestamp,idata_value FROM idata_%d WHERE item_id=%d AND idata_value LIKE '%%#%%'"), nodeId, dciId);
035a4d73
VK
2742 DB_RESULT hData = SQLSelect(query);
2743 if (hData != NULL)
50da2d20 2744 {
035a4d73
VK
2745 int valueCount = DBGetNumRows(hData);
2746 for(int j = 0; j < valueCount; j++)
2747 {
2748 TCHAR buffer[MAX_DB_STRING];
2749
2750 LONG ts = DBGetFieldLong(hData, j, 0);
2751 DBGetField(hData, j, 1, buffer, MAX_DB_STRING);
3f7c0fe4
VK
2752 DecodeSQLString(buffer);
2753
2754 _sntprintf(query, 512, _T("UPDATE idata_%d SET idata_value=%s WHERE item_id=%d AND idata_timestamp=%ld"),
2755 nodeId, (const TCHAR *)DBPrepareString(g_hCoreDB, buffer), dciId, (long)ts);
2756 CHK_EXEC(SQLQuery(query));
035a4d73
VK
2757 }
2758 DBFreeResult(hData);
50da2d20 2759 }
50da2d20
VK
2760 }
2761 }
2762 DBFreeResult(hResult);
2763 }
2764
2765 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='214' WHERE var_name='SchemaVersion'")));
50da2d20
VK
2766 return TRUE;
2767}
2768
480e036b
VK
2769/**
2770 * Upgrade from V212 to V213
2771 */
f57209fd
VK
2772static BOOL H_UpgradeFromV212(int currVersion, int newVersion)
2773{
480e036b
VK
2774 CHK_EXEC(SetColumnNullable(_T("items"), _T("custom_units_name")));
2775 CHK_EXEC(SetColumnNullable(_T("items"), _T("perftab_settings")));
f57209fd
VK
2776
2777 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("custom_units_name")));
2778 CHK_EXEC(ConvertStrings(_T("items"), _T("item_id"), _T("perftab_settings")));
2779
2780 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='213' WHERE var_name='SchemaVersion'")));
2781
2782 return TRUE;
2783}
2784
480e036b
VK
2785/**
2786 * Upgrade from V211 to V212
2787 */
1024e962
VK
2788static BOOL H_UpgradeFromV211(int currVersion, int newVersion)
2789{
480e036b
VK
2790 CHK_EXEC(SetColumnNullable(_T("snmp_trap_cfg"), _T("snmp_oid")));
2791 CHK_EXEC(SetColumnNullable(_T("snmp_trap_cfg"), _T("user_tag")));
2792 CHK_EXEC(SetColumnNullable(_T("snmp_trap_cfg"), _T("description")));
1024e962
VK
2793
2794 CHK_EXEC(ConvertStrings(_T("snmp_trap_cfg"), _T("trap_id"), _T("user_tag")));
2795 CHK_EXEC(ConvertStrings(_T("snmp_trap_cfg"), _T("trap_id"), _T("description")));
2796
2797 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='212' WHERE var_name='SchemaVersion'")));
2798
2799 return TRUE;
2800}
2801
480e036b
VK
2802/**
2803 * Upgrade from V210 to V211
2804 */
a8f60046
VK
2805static BOOL H_UpgradeFromV210(int currVersion, int newVersion)
2806{
2807 static TCHAR batch[] =
2808 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
2809 _T(" (53,'SYS_DCI_UNSUPPORTED',2,1,'Status of DCI %1 (%5: %2) changed to UNSUPPORTED',")
2810 _T("'Generated when DCI status changed to UNSUPPORTED.#0D#0AParameters:#0D#0A")
2811 _T(" 1) DCI ID#0D#0A 2) DCI Name#0D#0A 3) DCI Description#0D#0A 4) DCI Origin code#0D#0A 5) DCI Origin name')\n")
2812 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
2813 _T(" (54,'SYS_DCI_DISABLED',1,1,'Status of DCI %1 (%5: %2) changed to DISABLED',")
2814 _T("'Generated when DCI status changed to DISABLED.#0D#0AParameters:#0D#0A")
2815 _T(" 1) DCI ID#0D#0A 2) DCI Name#0D#0A 3) DCI Description#0D#0A 4) DCI Origin code#0D#0A 5) DCI Origin name')\n")
2816 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES")
2817 _T(" (55,'SYS_DCI_ACTIVE',0,1,'Status of DCI %1 (%5: %2) changed to ACTIVE',")
2818 _T("'Generated when DCI status changed to ACTIVE.#0D#0AParameters:#0D#0A")
2819 _T(" 1) DCI ID#0D#0A 2) DCI Name#0D#0A 3) DCI Description#0D#0A 4) DCI Origin code#0D#0A 5) DCI Origin name')\n")
2820 _T("<END>");
2821
1024e962
VK
2822 CHK_EXEC(SQLBatch(batch));
2823 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='211' WHERE var_name='SchemaVersion'")));
a8f60046
VK
2824
2825 return TRUE;
2826}
2827
85ae39bc
VK
2828/**
2829 * Upgrade from V209 to V210
2830 */
43c1be79
VK
2831static BOOL H_UpgradeFromV209(int currVersion, int newVersion)
2832{
2833 if (!SQLQuery(_T("DELETE FROM metadata WHERE var_name like 'IDataIndexCreationCommand_%'")))
2834 if (!g_bIgnoreErrors)
2835 return FALSE;
2836
2837 const TCHAR *query;
2838 switch(g_iSyntax)
2839 {
2840 case DB_SYNTAX_PGSQL:
2841 query = _T("INSERT INTO metadata (var_name,var_value) VALUES ('IDataIndexCreationCommand_0','CREATE INDEX idx_idata_%d_timestamp_id ON idata_%d(idata_timestamp,item_id)')");
2842 break;
2843 case DB_SYNTAX_MSSQL:
2844 query = _T("INSERT INTO metadata (var_name,var_value) VALUES ('IDataIndexCreationCommand_0','CREATE CLUSTERED INDEX idx_idata_%d_id_timestamp ON idata_%d(item_id,idata_timestamp)')");
2845 break;
2846 default:
2847 query = _T("INSERT INTO metadata (var_name,var_value) VALUES ('IDataIndexCreationCommand_0','CREATE INDEX idx_idata_%d_id_timestamp ON idata_%d(item_id,idata_timestamp)')");
2848 break;
2849 }
2850
2851 if (!SQLQuery(query))
2852 if (!g_bIgnoreErrors)
2853 return FALSE;
2854
2855 ReindexIData();
2856
2857 if (!SQLQuery(_T("UPDATE metadata SET var_value='210' WHERE var_name='SchemaVersion'")))
2858 if (!g_bIgnoreErrors)
2859 return FALSE;
2860
2861 return TRUE;
2862}
2863
7541bca2
VK
2864/**
2865 * Upgrade from V208 to V209
2866 */
ab185583
VK
2867static BOOL H_UpgradeFromV208(int currVersion, int newVersion)
2868{
2869 static TCHAR batch[] =
2870 _T("ALTER TABLE users ADD auth_failures integer\n")
2871 _T("ALTER TABLE users ADD last_passwd_change integer\n")
2872 _T("ALTER TABLE users ADD min_passwd_length integer\n")
2873 _T("ALTER TABLE users ADD disabled_until integer\n")
2874 _T("ALTER TABLE users ADD last_login integer\n")
2875 _T("ALTER TABLE users ADD password_history $SQL:TEXT\n")
2876 _T("UPDATE users SET auth_failures=0,last_passwd_change=0,min_passwd_length=-1,disabled_until=0,last_login=0\n")
2877 _T("<END>");
2878
2879 if (!SQLBatch(batch))
2880 if (!g_bIgnoreErrors)
2881 return FALSE;
2882
2883 if (!CreateConfigParam(_T("PasswordHistoryLength"), _T("0"), 1, 0))
2884 if (!g_bIgnoreErrors)
2885 return FALSE;
2886
0f1ddb74 2887 if (!CreateConfigParam(_T("IntruderLockoutThreshold"), _T("0"), 1, 0))
ab185583
VK
2888 if (!g_bIgnoreErrors)
2889 return FALSE;
2890
2891 if (!CreateConfigParam(_T("IntruderLockoutTime"), _T("30"), 1, 0))
2892 if (!g_bIgnoreErrors)
2893 return FALSE;
2894
2895 if (!CreateConfigParam(_T("MinPasswordLength"), _T("0"), 1, 0))
2896 if (!g_bIgnoreErrors)
2897 return FALSE;
2898
2899 if (!CreateConfigParam(_T("PasswordComplexity"), _T("0"), 1, 0))
2900 if (!g_bIgnoreErrors)
2901 return FALSE;
2902
2903 if (!CreateConfigParam(_T("PasswordExpiration"), _T("0"), 1, 0))
2904 if (!g_bIgnoreErrors)
2905 return FALSE;
2906
2907 if (!CreateConfigParam(_T("BlockInactiveUserAccounts"), _T("0"), 1, 0))
2908 if (!g_bIgnoreErrors)
2909 return FALSE;
2910
2911 if (!SQLQuery(_T("UPDATE metadata SET var_value='209' WHERE var_name='SchemaVersion'")))
2912 if (!g_bIgnoreErrors)
2913 return FALSE;
2914
2915 return TRUE;
2916}
2917
2918
80d3565a
VK
2919//
2920// Upgrade from V207 to V208
2921//
2922
2923static BOOL H_UpgradeFromV207(int currVersion, int newVersion)
2924{
2925 if (!SQLQuery(_T("ALTER TABLE items ADD system_tag varchar(255)")))
2926 if (!g_bIgnoreErrors)
2927 return FALSE;
2928
2929 if (!SQLQuery(_T("UPDATE metadata SET var_value='208' WHERE var_name='SchemaVersion'")))
2930 if (!g_bIgnoreErrors)
2931 return FALSE;
2932
2933 return TRUE;
2934}
2935
2936
5ab2f1ab
VK
2937//
2938// Upgrade from V206 to V207
2939//
2940
2941static BOOL H_UpgradeFromV206(int currVersion, int newVersion)
2942{
2943 if (!CreateConfigParam(_T("RADIUSSecondaryServer"), _T("none"), 1, 0))
2944 if (!g_bIgnoreErrors)
2945 return FALSE;
2946
2947 if (!CreateConfigParam(_T("RADIUSSecondarySecret"), _T("netxms"), 1, 0))
2948 if (!g_bIgnoreErrors)
2949 return FALSE;
2950
2951 if (!CreateConfigParam(_T("RADIUSSecondaryPort"), _T("1645"), 1, 0))
2952 if (!g_bIgnoreErrors)
2953 return FALSE;
2954
2955 if (!CreateConfigParam(_T("ExternalAuditServer"), _T("none"), 1, 1))
2956 if (!g_bIgnoreErrors)
2957 return FALSE;
2958
2959 if (!CreateConfigParam(_T("ExternalAuditPort"), _T("514"), 1, 1))
2960 if (!g_bIgnoreErrors)
2961 return FALSE;
2962
2963 if (!CreateConfigParam(_T("ExternalAuditFacility"), _T("13"), 1, 1))
2964 if (!g_bIgnoreErrors)
2965 return FALSE;
2966
2967 if (!CreateConfigParam(_T("ExternalAuditSeverity"), _T("5"), 1, 1))
2968 if (!g_bIgnoreErrors)
2969 return FALSE;
2970
2971 if (!CreateConfigParam(_T("ExternalAuditTag"), _T("netxmsd-audit"), 1, 1))
2972 if (!g_bIgnoreErrors)
2973 return FALSE;
2974
2975 if (!SQLQuery(_T("UPDATE metadata SET var_value='207' WHERE var_name='SchemaVersion'")))
2976 if (!g_bIgnoreErrors)
2977 return FALSE;
2978
2979 return TRUE;
2980}
2981
2982
ce7565e7
VK
2983//
2984// Upgrade from V205 to V206
2985//
2986
2987static BOOL H_UpgradeFromV205(int currVersion, int newVersion)
2988{
a4743a0f
VK
2989 if (g_iSyntax == DB_SYNTAX_ORACLE)
2990 {
2991 static TCHAR oraBatch[] =
2992 _T("ALTER TABLE audit_log MODIFY message null\n")
2993 _T("ALTER TABLE event_log MODIFY event_message null\n")
2994 _T("ALTER TABLE event_log MODIFY user_tag null\n")
2995 _T("ALTER TABLE syslog MODIFY hostname null\n")
2996 _T("ALTER TABLE syslog MODIFY msg_tag null\n")
2997 _T("ALTER TABLE syslog MODIFY msg_text null\n")
2998 _T("ALTER TABLE snmp_trap_log MODIFY trap_varlist null\n")
2999 _T("<END>");
3000
3001 if (!SQLBatch(oraBatch))
3002 if (!g_bIgnoreErrors)
3003 return FALSE;
3004 }
ce7565e7 3005
a4743a0f
VK
3006 bool clearLogs = GetYesNo(_T("This database upgrade requires log conversion. This can take significant amount of time ")
3007 _T("(up to few hours for large databases). If preserving all log records is not very important, it is ")
3008 _T("recommended to clear logs befor conversion. Clear logs?"));
ce7565e7 3009
a4743a0f
VK
3010 if (clearLogs)
3011 {
3012 if (!SQLQuery(_T("DELETE FROM audit_log")))
3013 if (!g_bIgnoreErrors)
3014 return FALSE;
ce7565e7 3015
a4743a0f
VK
3016 if (!SQLQuery(_T("DELETE FROM event_log")))
3017 if (!g_bIgnoreErrors)
3018 return FALSE;
3019
3020 if (!SQLQuery(_T("DELETE FROM syslog")))
3021 if (!g_bIgnoreErrors)
3022 return FALSE;
3023
3024 if (!SQLQuery(_T("DELETE FROM snmp_trap_log")))
3025 if (!g_bIgnoreErrors)
3026 return FALSE;
3027 }
3028 else
3029 {
3030 // Convert event log
08b214c6 3031 if (!ConvertStrings(_T("event_log"), _T("event_id"), _T("event_message")))
a4743a0f
VK
3032 if (!g_bIgnoreErrors)
3033 return FALSE;
08b214c6 3034 if (!ConvertStrings(_T("event_log"), _T("event_id"), _T("user_tag")))
a4743a0f
VK
3035 if (!g_bIgnoreErrors)
3036 return FALSE;
3037
3038 // Convert audit log
08b214c6 3039 if (!ConvertStrings(_T("audit_log"), _T("record_id"), _T("message")))
a4743a0f
VK
3040 if (!g_bIgnoreErrors)
3041 return FALSE;
3042
3043 // Convert syslog
08b214c6 3044 if (!ConvertStrings(_T("syslog"), _T("msg_id"), _T("msg_text")))
a4743a0f
VK
3045 if (!g_bIgnoreErrors)
3046 return FALSE;
3047
3048 // Convert SNMP trap log
08b214c6 3049 if (!ConvertStrings(_T("snmp_trap_log"), _T("trap_id"), _T("trap_varlist")))
a4743a0f
VK
3050 if (!g_bIgnoreErrors)
3051 return FALSE;
3052 }
ce7565e7
VK
3053
3054 if (!SQLQuery(_T("UPDATE metadata SET var_value='206' WHERE var_name='SchemaVersion'")))
3055 if (!g_bIgnoreErrors)
3056 return FALSE;
3057
3058 return TRUE;
3059}
3060
3061
df8a4ca2
VK
3062//
3063// Upgrade from V204 to V205
3064//
3065
3066static BOOL H_UpgradeFromV204(int currVersion, int newVersion)
3067{
3068 if (!CreateTable(_T("CREATE TABLE usm_credentials (")
3069 _T("id integer not null,")
3070 _T("user_name varchar(255) not null,")
3071 _T("auth_method integer not null,")
3072 _T("priv_method integer not null,")
3073 _T("auth_password varchar(255),")
3074 _T("priv_password varchar(255),")
3075 _T("PRIMARY KEY(id))")))
3076 if (!g_bIgnoreErrors)
3077 return FALSE;
3078
3079 if (!SQLQuery(_T("UPDATE metadata SET var_value='205' WHERE var_name='SchemaVersion'")))
3080 if (!g_bIgnoreErrors)
3081 return FALSE;
3082
3083 return TRUE;
3084}
3085
3086
e2babedf
VK
3087//
3088// Upgrade from V203 to V204
3089//
3090
3091static BOOL H_UpgradeFromV203(int currVersion, int newVersion)
3092{
3093 static TCHAR batch[] =
3094 _T("ALTER TABLE object_properties ADD location_type integer\n")
3095 _T("ALTER TABLE object_properties ADD latitude varchar(20)\n")
3096 _T("ALTER TABLE object_properties ADD longitude varchar(20)\n")
3097 _T("UPDATE object_properties SET location_type=0\n")
3098 _T("ALTER TABLE object_properties DROP COLUMN image_id\n")
3099 _T("<END>");
3100
3101 if (!SQLBatch(batch))
3102 if (!g_bIgnoreErrors)
3103 return FALSE;
3104
3105 if (!CreateConfigParam(_T("ConnectionPoolBaseSize"), _T("5"), 1, 1))
3106 if (!g_bIgnoreErrors)
3107 return FALSE;
3108
3109 if (!CreateConfigParam(_T("ConnectionPoolMaxSize"), _T("20"), 1, 1))
3110 if (!g_bIgnoreErrors)
3111 return FALSE;
3112
3113 if (!CreateConfigParam(_T("ConnectionPoolCooldownTime"), _T("300"), 1, 1))
3114 if (!g_bIgnoreErrors)
3115 return FALSE;
3116
a4743a0f
VK
3117 if (g_iSyntax == DB_SYNTAX_ORACLE)
3118 {
3119 if (!SQLQuery(_T("ALTER TABLE object_properties MODIFY comments null\n")))
3120 if (!g_bIgnoreErrors)
3121 return FALSE;
3122 }
3123
08b214c6 3124 if (!ConvertStrings(_T("object_properties"), _T("object_id"), _T("comments")))
e2babedf
VK
3125 if (!g_bIgnoreErrors)
3126 return FALSE;
3127
3128 if (!SQLQuery(_T("UPDATE metadata SET var_value='204' WHERE var_name='SchemaVersion'")))
3129 if (!g_bIgnoreErrors)
3130 return FALSE;
3131
3132 return TRUE;
3133}
3134
3135
7cda0d53
VK
3136//
3137// Upgrade from V202 to V203
3138//
3139
3140static BOOL H_UpgradeFromV202(int currVersion, int newVersion)
3141{
3142 static TCHAR batch[] =
3143 _T("INSERT INTO object_tools (tool_id,tool_name,tool_type,tool_data,flags,matching_oid,description,confirmation_text)")
3144 _T(" VALUES (20,'&Info->Topology table (LLDP)',2,'Topology Table',1,' ','Show topology table (LLDP)','#00')\n")
3145 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
3146 _T(" VALUES (20,0,'Chassis ID','.1.0.8802.1.1.2.1.4.1.1.5',0,0)\n")
3147 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
3148 _T(" VALUES (20,1,'Local port','.1.0.8802.1.1.2.1.4.1.1.2',5,0)\n")
3149 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
3150 _T(" VALUES (20,2,'System name','.1.0.8802.1.1.2.1.4.1.1.9',0,0)\n")
3151 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
3152 _T(" VALUES (20,3,'System description','.1.0.8802.1.1.2.1.4.1.1.10',0,0)\n")
3153 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
3154 _T(" VALUES (20,4,'Remote port ID','.1.0.8802.1.1.2.1.4.1.1.7',4,0)\n")
3155 _T("INSERT INTO object_tools_table_columns (tool_id,col_number,col_name,col_oid,col_format,col_substr)")
3156 _T(" VALUES (20,5,'Remote port description','.1.0.8802.1.1.2.1.4.1.1.8',0,0)\n")
3157 _T("INSERT INTO object_tools_acl (tool_id,user_id) VALUES (20,-2147483648)\n")
3158 _T("<END>");
3159
3160 if (!SQLBatch(batch))
3161 if (!g_bIgnoreErrors)
3162 return FALSE;
3163
3164 if (!SQLQuery(_T("UPDATE metadata SET var_value='203' WHERE var_name='SchemaVersion'")))
3165 if (!g_bIgnoreErrors)
3166 return FALSE;
3167
3168 return TRUE;
3169}
3170
3171
643c9dcb
VK
3172//
3173// Upgrade from V201 to V202
3174//
3175
3176static BOOL H_UpgradeFromV201(int currVersion, int newVersion)
3177{
a4743a0f
VK
3178 if (g_iSyntax == DB_SYNTAX_ORACLE)
3179 {
3180 static TCHAR oraBatch[] =
3181 _T("ALTER TABLE alarms MODIFY message null\n")
3182 _T("ALTER TABLE alarms MODIFY alarm_key null\n")
3183 _T("ALTER TABLE alarms MODIFY hd_ref null\n")
3184 _T("<END>");
3185
3186 if (!SQLBatch(oraBatch))
3187 if (!g_bIgnoreErrors)
3188 return FALSE;
3189 }
3190
08b214c6 3191 if (!ConvertStrings(_T("alarms"), _T("alarm_id"), _T("message")))
643c9dcb
VK
3192 if (!g_bIgnoreErrors)
3193 return FALSE;
08b214c6 3194 if (!ConvertStrings(_T("alarms"), _T("alarm_id"), _T("alarm_key")))
643c9dcb
VK
3195 if (!g_bIgnoreErrors)
3196 return FALSE;
08b214c6 3197 if (!ConvertStrings(_T("alarms"), _T("alarm_id"), _T("hd_ref")))
643c9dcb
VK
3198 if (!g_bIgnoreErrors)
3199 return FALSE;
3200
3201 if (!SQLQuery(_T("UPDATE metadata SET var_value='202' WHERE var_name='SchemaVersion'")))
3202 if (!g_bIgnoreErrors)
3203 return FALSE;
3204
3205 return TRUE;
3206}
3207
3208
31cc1924
VK
3209//
3210// Upgrade from V200 to V201
3211//
3212
3213static BOOL H_UpgradeFromV200(int currVersion, int newVersion)
3214{
3215 static TCHAR batch[] =
3216 _T("ALTER TABLE nodes ADD usm_auth_password varchar(127)\n")
3217 _T("ALTER TABLE nodes ADD usm_priv_password varchar(127)\n")
3218 _T("ALTER TABLE nodes ADD usm_methods integer\n")
e8daf6d5 3219 _T("UPDATE nodes SET usm_auth_password='#00',usm_priv_password='#00',usm_methods=0\n")
31cc1924
VK
3220 _T("<END>");
3221
3222 if (!SQLBatch(batch))
3223 if (!g_bIgnoreErrors)
3224 return FALSE;
3225
3226 if (!SQLQuery(_T("UPDATE metadata SET var_value='201' WHERE var_name='SchemaVersion'")))
3227 if (!g_bIgnoreErrors)
3228 return FALSE;
3229
3230 return TRUE;
3231}
3232
3233
45d84f8a
VK
3234//
3235// Upgrade from V92 to V200
31cc1924 3236// or from V93 to V201
e2babedf
VK
3237// or from V94 to V202
3238// or from V95 to V203
ce7565e7
VK
3239// or from V96 to V204
3240// or from V97 to V205
3241// or from V98 to V206
43c1be79 3242// or from V99 to V207
45d84f8a
VK
3243//
3244
e2babedf 3245static BOOL H_UpgradeFromV9x(int currVersion, int newVersion)
45d84f8a
VK
3246{
3247 if (!CreateTable(_T("CREATE TABLE ap_common (")
3248 _T("id integer not null,")
3249 _T("policy_type integer not null,")
3250 _T("version integer not null,")
3251 _T("description $SQL:TEXT not null,")
3252 _T("PRIMARY KEY(id))")))
3253 if (!g_bIgnoreErrors)
3254 return FALSE;
3255
3256 if (!CreateTable(_T("CREATE TABLE ap_bindings (")
3257 _T("policy_id integer not null,")
3258 _T("node_id integer not null,")
3259 _T("PRIMARY KEY(policy_id,node_id))")))
3260 if (!g_bIgnoreErrors)
3261 return FALSE;
3262
3263 if (!CreateTable(_T("CREATE TABLE ap_config_files (")
3264 _T("policy_id integer not null,")
3265 _T("file_name varchar(63) not null,")
3266 _T("file_content $SQL:TEXT not null,")
3267 _T("PRIMARY KEY(policy_id))")))
3268 if (!g_bIgnoreErrors)
3269 return FALSE;
3270
31cc1924
VK
3271 TCHAR query[256];
3272 _sntprintf(query, 256, _T("UPDATE metadata SET var_value='%d' WHERE var_name='SchemaVersion'"), newVersion);
3273 if (!SQLQuery(query))
45d84f8a
VK
3274 if (!g_bIgnoreErrors)
3275 return FALSE;
3276
3277 return TRUE;
3278}
3279
3280
43c1be79 3281//
50da2d20
VK
3282// Upgrade from V100 to V214
3283// or from V101 to V214
3284// or from V102 to V214
3285// or from V103 to V214
3286// or from V104 to V214
43c1be79
VK
3287//
3288
a8f60046 3289static BOOL H_UpgradeFromV10x(int currVersion, int newVersion)
43c1be79 3290{
50da2d20 3291 if (!H_UpgradeFromV9x(currVersion, 207))
43c1be79
VK
3292 return FALSE;
3293
3294 // Now database at V207 level
50da2d20
VK
3295 // V100 already has changes V209 -> V210, but missing V207 -> V209 and V210 -> V214 changes
3296 // V101 already has changes V209 -> V211, but missing V207 -> V209 and V211 -> V214 changes
3297 // V102 already has changes V209 -> V212, but missing V207 -> V209 and V212 -> V214 changes
3298 // V103 already has changes V209 -> V213, but missing V207 -> V209 and V213 -> V214 changes
3299 // V104 already has changes V209 -> V214, but missing V207 -> V209 changes
43c1be79
VK
3300
3301 if (!H_UpgradeFromV207(207, 208))
3302 return FALSE;
3303
a6c1f07f 3304 if (!H_UpgradeFromV208(208, 209))
43c1be79
VK
3305 return FALSE;
3306
a8f60046 3307 if (currVersion == 100)
50da2d20
VK
3308 if (!H_UpgradeFromV210(210, 211))
3309 return FALSE;
a8f60046 3310
1024e962 3311 if (currVersion < 102)
50da2d20
VK
3312 if (!H_UpgradeFromV211(211, 212))
3313 return FALSE;
1024e962 3314
f57209fd 3315 if (currVersion < 103)
50da2d20
VK
3316 if (!H_UpgradeFromV212(212, 213))
3317 return FALSE;
3318
3319 if (currVersion < 104)
3320 if (!H_UpgradeFromV213(213, 214))
3321 return FALSE;
f57209fd 3322
65e2005b
VK
3323 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='214' WHERE var_name='SchemaVersion'")));
3324 return TRUE;
3325}
3326
3327
3328//
3329// Upgrade from V105 to V217
3330//
3331
3332static BOOL H_UpgradeFromV105(int currVersion, int newVersion)
3333{
3334 if (!H_UpgradeFromV10x(currVersion, 214))
3335 return FALSE;
3336
3337 // V105 already have V216 -> V217 changes, but missing V207 -> V209 and V214 -> V216 changes
3338 if (!H_UpgradeFromV214(214, 215))
3339 return FALSE;
3340
3341 if (!H_UpgradeFromV215(215, 216))
3342 return FALSE;
43c1be79 3343
65e2005b 3344 CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='217' WHERE var_name='SchemaVersion'")));
43c1be79
VK
3345 return TRUE;
3346}
3347
3348
6e53f004
VK
3349//
3350// Upgrade from V91 to V92
3351//
3352
31cc1924 3353static BOOL H_UpgradeFromV91(int currVersion, int newVersion)
6e53f004
VK
3354{
3355 static TCHAR batch[] =
3356 _T("DROP TABLE images\n")
3357 _T("DROP TABLE default_images\n")
3358 _T("<END>");
3359
3360 if (!SQLBatch(batch))
3361 if (!g_bIgnoreErrors)
3362 return FALSE;
3363
3364 if (!SQLQuery(_T("UPDATE metadata SET var_value='92' WHERE var_name='SchemaVersion'")))
3365 if (!g_bIgnoreErrors)
3366 return FALSE;
3367
3368 return TRUE;
3369}
3370
3371
c45e0213
VK
3372//
3373// Upgrade from V90 to V91
3374//
3375
31cc1924 3376static BOOL H_UpgradeFromV90(int currVersion, int newVersion)
c45e0213
VK
3377{
3378 if (!CreateTable(_T("CREATE TABLE userdb_custom_attributes (")
3379 _T("object_id integer not null,")
3380 _T("attr_name varchar(255) not null,")
3381 _T("attr_value $SQL:TEXT not null,")
3382 _T("PRIMARY KEY(object_id,attr_name))")))
3383 if (!g_bIgnoreErrors)
3384 return FALSE;
3385
3386 if (!SQLQuery(_T("UPDATE metadata SET var_value='91' WHERE var_name='SchemaVersion'")))
3387 if (!g_bIgnoreErrors)
3388 return FALSE;
3389
3390 return TRUE;
3391}
3392
3393
4262c0dc
VK
3394//
3395// Upgrade from V89 to V90
3396//
3397
31cc1924 3398static BOOL H_UpgradeFromV89(int currVersion, int newVersion)
4262c0dc
VK
3399{
3400 static TCHAR m_szBatch[] =
3401 _T("ALTER TABLE items ADD base_units integer\n")
3402 _T("ALTER TABLE items ADD unit_multiplier integer\n")
3403 _T("ALTER TABLE items ADD custom_units_name varchar(63)\n")
3404 _T("ALTER TABLE items ADD perftab_settings $SQL:TEXT\n")
3405 _T("UPDATE items SET base_units=0,unit_multiplier=1,custom_units_name='#00',perftab_settings='#00'\n")
3406 _T("<END>");
3407
3408 if (!SQLBatch(m_szBatch))
3409 if (!g_bIgnoreErrors)
3410 return FALSE;
3411
3412 if (!SQLQuery(_T("UPDATE metadata SET var_value='90' WHERE var_name='SchemaVersion'")))
3413 if (!g_bIgnoreErrors)
3414 return FALSE;
3415
3416 return TRUE;
3417}
3418
3419
3420//
3421// Upgrade from V88 to V89
3422//
3423
31cc1924 3424static BOOL H_UpgradeFromV88(int currVersion, int newVersion)
4262c0dc
VK
3425{
3426 static TCHAR m_szBatch[] =
3427 _T("ALTER TABLE containers ADD enable_auto_bind integer\n")
3428 _T("ALTER TABLE containers ADD auto_bind_filter $SQL:TEXT\n")
3429 _T("UPDATE containers SET enable_auto_bind=0,auto_bind_filter='#00'\n")
3430 _T("ALTER TABLE cluster_resources ADD current_owner integer\n")
3431 _T("UPDATE cluster_resources SET current_owner=0\n")
3432 _T("INSERT INTO event_cfg (event_code,event_name,severity,flags,message,description) VALUES (")
3433 _T("52,'SYS_DB_QUERY_FAILED',4,1,'Database query failed (Query: %1; Error: %2)',")
3434 _T("'Generated when SQL query to backend database failed.#0D#0A")
3435 _T("Parameters:#0D#0A 1) Query#0D#0A 2) Error message')\n")
3436 _T("<END>");
3437
3438 if (!SQLBatch(m_szBatch))
3439 if (!g_bIgnoreErrors)
3440 return FALSE;
3441
3442 if (!SQLQuery(_T("UPDATE metadata SET var_value='89' WHERE var_name='SchemaVersion'")))
3443 if (!g_bIgnoreErrors)
3444 return FALSE;
3445
3446 return TRUE;
3447}
3448
3449
3450//
3451// Upgrade from V87 to V88
3452//
3453
31cc1924 3454static BOOL H_UpgradeFromV87(int currVersion, int newVersion)
4262c0dc
VK
3455{
3456 static TCHAR m_szBatch[] =
3457 _T("ALTER TABLE templates ADD enable_auto_apply integer\n")
3458 _T("ALTER TABLE templates ADD apply_filter $SQL:TEXT\n")
3459 _T("UPDATE templates SET enable_auto_apply=0,apply_filter='#00'\n")
3460 _T("<END>");
3461
3462 if (!SQLBatch(m_szBatch))
3463 if (!g_bIgnoreErrors)
3464 return FALSE;
3465
3466 if (!SQLQuery(_T("UPDATE metadata SET var_value='88' WHERE var_name='SchemaVersion'")))
3467 if (!g_bIgnoreErrors)
3468 return FALSE;
3469
3470 return TRUE;
3471}
3472
3473
28f5b9a4
VK
3474//
3475// Upgrade from V86 to V87
3476//
3477
3478static BOOL MoveConfigToMetadata(const TCHAR *cfgVar, const TCHAR *mdVar)
3479{
3480 TCHAR query[1024], buffer[256];
3481 DB_RESULT hResult;
3482 BOOL success;
3483
3484 _sntprintf(query, 1024, _T("SELECT var_value FROM config WHERE var_name='%s'"), cfgVar);
3485 hResult = SQLSelect(query);
3486 if (hResult != NULL)
3487 {
3488 if (DBGetNumRows(hResult) > 0)
3489 {
3490 DBGetField(hResult, 0, 0, buffer, 256);
3491 DecodeSQLString(buffer);
3492 _sntprintf(query, 1024, _T("INSERT INTO metadata (var_name,var_value) VALUES ('%s','%s')"),
3493 mdVar, buffer);
3494 DBFreeResult(hResult);
3495 success = SQLQuery(query);
3496 if (success)
3497 {
3498 _sntprintf(query, 1024, _T("DELETE FROM config WHERE var_name='%s'"), cfgVar);
3499 success = SQLQuery(query);
3500 }
3501 }
3502 else
3503 {
3504 success = TRUE; // Variable missing in 'config' table, nothing to move
3505 }
3506 }
3507 else
3508 {
3509 success = FALSE;
3510 }
3511 return success;
3512}
3513
31cc1924 3514static BOOL H_UpgradeFromV86(int currVersion, int newVersion)
28f5b9a4
VK
3515{
3516 if (!CreateTable(_T("CREATE TABLE metadata (")
3517 _T("var_name varchar(63) not null,")
3518 _T("var_value varchar(255) not null,")
3519 _T("PRIMARY KEY(var_name))")))
3520 if (!g_bIgnoreErrors)
3521 return FALSE;
3522
3523 if (!MoveConfigToMetadata(_T("DBFormatVersion"), _T("SchemaVersion")))
3524 if (!g_bIgnoreErrors)
3525 return FALSE;
3526
3527 if (!MoveConfigToMetadata(_T("DBSyntax"), _T("Syntax")))
3528 if (!g_bIgnoreErrors)
3529 return FALSE;
3530
3531 if (!MoveConfigToMetadata(_T("IDataTableCreationCommand"), _T("IDataTableCreationCommand")))
3532 if (!g_bIgnoreErrors)
3533 return FALSE;
3534
3535 if (!MoveConfigToMetadata(_T("IDataIndexCreationCommand_0"), _T("IDataIndexCreationCommand_0")))
3536 if (!g_bIgnoreErrors)
3537 return FALSE;
3538
3539 if (!MoveConfigToMetadata(_T("IDataIndexCreationCommand_1"), _T("IDataIndexCreationCommand_1")))
3540 if (!g_bIgnoreErrors)
3541 return FALSE;
3542
3543 if (!MoveConfigToMetadata(_T("IDataIndexCreationCommand_2"), _T("IDataIndexCreationCommand_2")))
3544 if (!g_bIgnoreErrors)
3545 return FALSE;
3546
3547 if (!MoveConfigToMetadata(_T("IDataIndexCreationCommand_3"), _T("IDataIndexCreationCommand_3")))
3548 if (!g_bIgnoreErrors)
3549 return FALSE;
3550
3551 if (!SQLQuery(_T("UPDATE metadata SET var_value='87' WHERE var_name='SchemaVersion'")))
3552 if (!g_bIgnoreErrors)
3553 return FALSE;
3554
3555 return TRUE;
3556}
3557
3558
4c4c9b03
VK
3559//
3560// Upgrade from V85 to V86
3561//
3562
31cc1924 3563static BOOL H_UpgradeFromV85(int currVersion, int newVersion)
4c4c9b03
VK
3564{
3565 static TCHAR m_szBatch[] =
3566 _T("DROP TABLE alarm_grops\n")
3567 _T("DROP TABLE alarm_group_map\n")
47912c44
VK
3568 _T("DROP TABLE alarm_change_log\n")
3569 _T("DROP TABLE lpp\n")
3570 _T("DROP TABLE lpp_associations\n")
3571 _T("DROP TABLE lpp_rulesets\n")
3572 _T("DROP TABLE lpp_rules\n")
3573 _T("DROP TABLE lpp_groups\n")
4c4c9b03
VK
3574 _T("<END>");
3575
3576 if (!SQLBatch(m_szBatch))
3577 if (!g_bIgnoreErrors)
3578 return FALSE;
3579
3580 if (!SQLQuery(_T("UPDATE config SET var_value='86' WHERE var_name='DBFormatVersion'")))
3581 if (!g_bIgnoreErrors)
3582 return FALSE;
3583
3584 return TRUE;
3585}
3586
3587
5039dede
AK
3588//
3589// Upgrade from V84 to V85
3590//
3591
31cc1924 3592static BOOL H_UpgradeFromV84(int currVersion, int newVersion)
5039dede
AK
3593{
3594 static TCHAR m_szBatch[] =
3595 _T("ALTER TABLE nodes ADD use_ifxtable integer\n")
3596 _T("UPDATE nodes SET use_ifxtable=0\n")
3597 _T("<END>");
3598
3599 if (!SQLBatch(m_szBatch))
3600 if (!g_bIgnoreErrors)
3601 return FALSE;
3602
3603 if (!CreateConfigParam(_T("UseIfXTable"), _T("1"), 1, 0))
3604<