1 /*
2 ** Zabbix
3 ** Copyright (C) 2001-2021 Zabbix SIA
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 **/
19 
20 #include "common.h"
21 #include "db.h"
22 #include "sysinfo.h"
23 #include "dbupgrade.h"
24 #include "log.h"
25 #include "sysinfo.h"
26 
27 /*
28  * 2.2 development database patches
29  */
30 
31 #ifndef HAVE_SQLITE3
32 
DBmodify_proxy_table_id_field(const char * table_name)33 static int	DBmodify_proxy_table_id_field(const char *table_name)
34 {
35 #ifdef HAVE_POSTGRESQL
36 	const ZBX_FIELD	field = {"id", NULL, NULL, NULL, 0, ZBX_TYPE_ID, ZBX_NOTNULL, 0};
37 
38 	return DBmodify_field_type(table_name, &field, NULL);
39 #else
40 	ZBX_UNUSED(table_name);
41 	return SUCCEED;
42 #endif
43 }
44 
45 /*********************************************************************************
46  *                                                                               *
47  * Function: parse_db_monitor_item_params                                        *
48  *                                                                               *
49  * Purpose: parse database monitor item params string "user=<user> password=     *
50  *          <passsword> DSN=<dsn> sql=<sql>" into parameter values.              *
51  *                                                                               *
52  * Parameters:  params     - [IN] the params string                              *
53  *              dsn        - [OUT] the ODBC DSN output buffer                    *
54  *              user       - [OUT] the user name output buffer                   *
55  *              password   - [OUT] the password output buffer                    *
56  *              sql        - [OUT] the sql query output buffer                   *
57  *                                                                               *
58  * Comments: This function allocated memory to store parsed parameters, which    *
59  *           must be freed later by the caller.                                  *
60  *           Failed (or absent) parameters will contain empty string "".         *
61  *                                                                               *
62  *********************************************************************************/
parse_db_monitor_item_params(const char * params,char ** dsn,char ** user,char ** password,char ** sql)63 static void	parse_db_monitor_item_params(const char *params, char **dsn, char **user, char **password, char **sql)
64 {
65 	const char	*pvalue, *pnext, *pend;
66 	char		**var;
67 
68 	for (; '\0' != *params; params = pnext)
69 	{
70 		while (0 != isspace(*params))
71 			params++;
72 
73 		pvalue = strchr(params, '=');
74 		pnext = strchr(params, '\n');
75 
76 		if (NULL == pvalue)
77 			break;
78 
79 		if (NULL == pnext)
80 			pnext = params + strlen(params);
81 
82 		if (pvalue > pnext || pvalue == params)
83 			continue;
84 
85 		for (pend = pvalue - 1; 0 != isspace(*pend); pend--)
86 			;
87 		pend++;
88 
89 		if (0 == strncmp(params, "user", pend - params))
90 			var = user;
91 		else if (0 == strncmp(params, "password", pend - params))
92 			var = password;
93 		else if (0 == strncmp(params, "DSN", pend - params))
94 			var = dsn;
95 		else if (0 == strncmp(params, "sql", pend - params))
96 			var = sql;
97 		else
98 			continue;
99 
100 		pvalue++;
101 		while (0 != isspace(*pvalue))
102 			pvalue++;
103 
104 		if (pvalue > pnext)
105 			continue;
106 
107 		if ('\0' == *pvalue)
108 			continue;
109 
110 		for (pend = pnext - 1; 0 != isspace(*pend); pend--)
111 			;
112 		pend++;
113 
114 		if (NULL == *var)
115 		{
116 			*var = (char *)zbx_malloc(*var, pend - pvalue + 1);
117 			memmove(*var, pvalue, pend - pvalue);
118 			(*var)[pend - pvalue] = '\0';
119 		}
120 	}
121 
122 	if (NULL == *user)
123 		*user = zbx_strdup(NULL, "");
124 
125 	if (NULL == *password)
126 		*password = zbx_strdup(NULL, "");
127 
128 	if (NULL == *dsn)
129 		*dsn = zbx_strdup(NULL, "");
130 
131 	if (NULL == *sql)
132 		*sql = zbx_strdup(NULL, "");
133 }
134 
135 /*
136  * Database patches
137  */
138 
DBpatch_2010001(void)139 static int	DBpatch_2010001(void)
140 {
141 	return DBmodify_proxy_table_id_field("proxy_autoreg_host");
142 }
143 
DBpatch_2010002(void)144 static int	DBpatch_2010002(void)
145 {
146 	return DBmodify_proxy_table_id_field("proxy_dhistory");
147 }
148 
DBpatch_2010003(void)149 static int	DBpatch_2010003(void)
150 {
151 	return DBmodify_proxy_table_id_field("proxy_history");
152 }
153 
DBpatch_2010007(void)154 static int	DBpatch_2010007(void)
155 {
156 	const char	*strings[] = {"period", "stime", "timelinefixed", NULL};
157 	int		i;
158 
159 	for (i = 0; NULL != strings[i]; i++)
160 	{
161 		if (ZBX_DB_OK > DBexecute("update profiles set idx='web.screens.%s' where idx='web.charts.%s'",
162 				strings[i], strings[i]))
163 		{
164 			return FAIL;
165 		}
166 	}
167 
168 	return SUCCEED;
169 }
170 
DBpatch_2010008(void)171 static int	DBpatch_2010008(void)
172 {
173 	const ZBX_FIELD	field = {"expression", "", NULL, NULL, 2048, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0};
174 
175 	return DBmodify_field_type("triggers", &field, NULL);
176 }
177 
DBpatch_2010009(void)178 static int	DBpatch_2010009(void)
179 {
180 	const ZBX_FIELD	field = {"applicationid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, 0, 0};
181 
182 	return DBdrop_not_null("httptest", &field);
183 }
184 
DBpatch_2010010(void)185 static int	DBpatch_2010010(void)
186 {
187 	const ZBX_FIELD	field = {"hostid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, 0, 0};
188 
189 	return DBadd_field("httptest", &field);
190 }
191 
DBpatch_2010011(void)192 static int	DBpatch_2010011(void)
193 {
194 	const char	*sql =
195 			"update httptest set hostid=("
196 				"select a.hostid"
197 				" from applications a"
198 				" where a.applicationid = httptest.applicationid"
199 			")";
200 
201 	if (ZBX_DB_OK <= DBexecute("%s", sql))
202 		return SUCCEED;
203 
204 	return FAIL;
205 }
206 
DBpatch_2010012(void)207 static int	DBpatch_2010012(void)
208 {
209 	const ZBX_FIELD	field = {"hostid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, ZBX_NOTNULL, 0};
210 
211 	return DBset_not_null("httptest", &field);
212 }
213 
DBpatch_2010013(void)214 static int	DBpatch_2010013(void)
215 {
216 	const ZBX_FIELD	field = {"templateid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, 0, 0};
217 
218 	return DBadd_field("httptest", &field);
219 }
220 
DBpatch_2010014(void)221 static int	DBpatch_2010014(void)
222 {
223 	return DBdrop_index("httptest", "httptest_2");
224 }
225 
DBpatch_2010015(void)226 static int	DBpatch_2010015(void)
227 {
228 	return DBcreate_index("httptest", "httptest_2", "hostid,name", 1);
229 }
230 
DBpatch_2010016(void)231 static int	DBpatch_2010016(void)
232 {
233 	return DBcreate_index("httptest", "httptest_4", "templateid", 0);
234 }
235 
DBpatch_2010017(void)236 static int	DBpatch_2010017(void)
237 {
238 	return DBdrop_foreign_key("httptest", 1);
239 }
240 
DBpatch_2010018(void)241 static int	DBpatch_2010018(void)
242 {
243 	const ZBX_FIELD	field = {"applicationid", NULL, "applications", "applicationid", 0, 0, 0, 0};
244 
245 	return DBadd_foreign_key("httptest", 1, &field);
246 }
247 
DBpatch_2010019(void)248 static int	DBpatch_2010019(void)
249 {
250 	const ZBX_FIELD	field = {"hostid", NULL, "hosts", "hostid", 0, 0, 0, ZBX_FK_CASCADE_DELETE};
251 
252 	return DBadd_foreign_key("httptest", 2, &field);
253 }
254 
DBpatch_2010020(void)255 static int	DBpatch_2010020(void)
256 {
257 	const ZBX_FIELD	field = {"templateid", NULL, "httptest", "httptestid", 0, 0, 0, ZBX_FK_CASCADE_DELETE};
258 
259 	return DBadd_foreign_key("httptest", 3, &field);
260 }
261 
DBpatch_2010021(void)262 static int	DBpatch_2010021(void)
263 {
264 	const ZBX_FIELD	field = {"http_proxy", "", NULL, NULL, 255, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0};
265 
266 	return DBadd_field("httptest", &field);
267 }
268 
DBpatch_2010022(void)269 static int	DBpatch_2010022(void)
270 {
271 	const ZBX_FIELD field = {"snmpv3_authprotocol", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
272 
273 	return DBadd_field("items", &field);
274 }
275 
DBpatch_2010023(void)276 static int	DBpatch_2010023(void)
277 {
278 	const ZBX_FIELD field = {"snmpv3_privprotocol", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
279 
280 	return DBadd_field("items", &field);
281 }
282 
DBpatch_2010024(void)283 static int	DBpatch_2010024(void)
284 {
285 	const ZBX_FIELD field = {"snmpv3_authprotocol", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
286 
287 	return DBadd_field("dchecks", &field);
288 }
289 
DBpatch_2010025(void)290 static int	DBpatch_2010025(void)
291 {
292 	const ZBX_FIELD field = {"snmpv3_privprotocol", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
293 
294 	return DBadd_field("dchecks", &field);
295 }
296 
DBpatch_2010026(void)297 static int	DBpatch_2010026(void)
298 {
299 	const ZBX_FIELD field = {"retries", "1", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
300 
301 	return DBadd_field("httptest", &field);
302 }
303 
DBpatch_2010027(void)304 static int	DBpatch_2010027(void)
305 {
306 	const ZBX_FIELD field = {"application", "", NULL, NULL, 255, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0};
307 
308 	return DBadd_field("screens_items", &field);
309 }
310 
DBpatch_2010028(void)311 static int	DBpatch_2010028(void)
312 {
313 	const char	*sql =
314 			"update profiles"
315 			" set value_int=case when value_str='0' then 0 else 1 end,"
316 				"value_str='',"
317 				"type=2"	/* PROFILE_TYPE_INT */
318 			" where idx='web.httpconf.showdisabled'";
319 
320 	if (ZBX_DB_OK <= DBexecute("%s", sql))
321 		return SUCCEED;
322 
323 	return FAIL;
324 }
325 
DBpatch_2010029(void)326 static int	DBpatch_2010029(void)
327 {
328 	const char	*sql =
329 			"delete from profiles where idx in ('web.httpconf.applications','web.httpmon.applications')";
330 
331 	if (ZBX_DB_OK <= DBexecute("%s", sql))
332 		return SUCCEED;
333 
334 	return FAIL;
335 }
336 
DBpatch_2010030(void)337 static int	DBpatch_2010030(void)
338 {
339 	const char	*sql = "delete from profiles where idx='web.items.filter_groupid'";
340 
341 	if (ZBX_DB_OK <= DBexecute("%s", sql))
342 		return SUCCEED;
343 
344 	return FAIL;
345 }
346 
DBpatch_2010031(void)347 static int	DBpatch_2010031(void)
348 {
349 	const char	*sql =
350 			"update profiles"
351 			" set value_id=value_int,"
352 				"value_int=0"
353 			" where idx like 'web.avail_report.%.groupid'"
354 				" or idx like 'web.avail_report.%.hostid'";
355 
356 	if (ZBX_DB_OK <= DBexecute("%s", sql))
357 		return SUCCEED;
358 
359 	return FAIL;
360 }
361 
DBpatch_2010032(void)362 static int	DBpatch_2010032(void)
363 {
364 	const ZBX_FIELD	field = {"type", "1", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
365 
366 	return DBset_default("users", &field);
367 }
368 
DBpatch_2010033(void)369 static int	DBpatch_2010033(void)
370 {
371 	if (ZBX_DB_OK <= DBexecute(
372 			"delete from events"
373 			" where source=%d"
374 				" and object=%d"
375 				" and (value=%d or value_changed=%d)",
376 			EVENT_SOURCE_TRIGGERS,
377 			EVENT_OBJECT_TRIGGER,
378 			TRIGGER_VALUE_UNKNOWN,
379 			0))	/*TRIGGER_VALUE_CHANGED_NO*/
380 	{
381 		return SUCCEED;
382 	}
383 
384 	return FAIL;
385 }
386 
DBpatch_2010034(void)387 static int	DBpatch_2010034(void)
388 {
389 	return DBdrop_field("events", "value_changed");
390 }
391 
DBpatch_2010035(void)392 static int	DBpatch_2010035(void)
393 {
394 	const char	*sql = "delete from profiles where idx='web.events.filter.showUnknown'";
395 
396 	if (ZBX_DB_OK <= DBexecute("%s", sql))
397 		return SUCCEED;
398 
399 	return FAIL;
400 }
401 
DBpatch_2010036(void)402 static int	DBpatch_2010036(void)
403 {
404 	const char	*sql =
405 			"update profiles"
406 			" set value_int=case when value_str='1' then 1 else 0 end,"
407 				"value_str='',"
408 				"type=2"	/* PROFILE_TYPE_INT */
409 			" where idx like '%isnow'";
410 
411 	if (ZBX_DB_OK <= DBexecute("%s", sql))
412 		return SUCCEED;
413 
414 	return FAIL;
415 }
416 
DBpatch_2010037(void)417 static int	DBpatch_2010037(void)
418 {
419 	if (ZBX_DB_OK <= DBexecute("update config set server_check_interval=10"))
420 		return SUCCEED;
421 
422 	return FAIL;
423 }
424 
DBpatch_2010038(void)425 static int	DBpatch_2010038(void)
426 {
427 	const ZBX_FIELD	field = {"server_check_interval", "10", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
428 
429 	return DBset_default("config", &field);
430 }
431 
DBpatch_2010039(void)432 static int	DBpatch_2010039(void)
433 {
434 	return DBdrop_field("alerts", "nextcheck");
435 }
436 
DBpatch_2010040(void)437 static int	DBpatch_2010040(void)
438 {
439 	const ZBX_FIELD	field = {"state", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
440 
441 	return DBrename_field("triggers", "value_flags", &field);
442 }
443 
DBpatch_2010043(void)444 static int	DBpatch_2010043(void)
445 {
446 	const ZBX_FIELD field = {"state", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
447 
448 	return DBadd_field("items", &field);
449 }
450 
DBpatch_2010044(void)451 static int	DBpatch_2010044(void)
452 {
453 	if (ZBX_DB_OK <= DBexecute(
454 			"update items"
455 			" set state=%d,"
456 				"status=%d"
457 			" where status=%d",
458 			ITEM_STATE_NOTSUPPORTED, ITEM_STATUS_ACTIVE, 3 /*ITEM_STATUS_NOTSUPPORTED*/))
459 		return SUCCEED;
460 
461 	return FAIL;
462 }
463 
DBpatch_2010045(void)464 static int	DBpatch_2010045(void)
465 {
466 	const ZBX_FIELD	field = {"state", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
467 
468 	return DBrename_field("proxy_history", "status", &field);
469 }
470 
DBpatch_2010046(void)471 static int	DBpatch_2010046(void)
472 {
473 	if (ZBX_DB_OK <= DBexecute(
474 			"update proxy_history"
475 			" set state=%d"
476 			" where state=%d",
477 			ITEM_STATE_NOTSUPPORTED, 3 /*ITEM_STATUS_NOTSUPPORTED*/))
478 		return SUCCEED;
479 
480 	return FAIL;
481 }
482 
DBpatch_2010047(void)483 static int	DBpatch_2010047(void)
484 {
485 	const ZBX_FIELD	field = {"itemid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, 0, 0};
486 
487 	return DBadd_field("escalations", &field);
488 }
489 
DBpatch_2010048(void)490 static int	DBpatch_2010048(void)
491 {
492 	return DBdrop_index("escalations", "escalations_1");
493 }
494 
DBpatch_2010049(void)495 static int	DBpatch_2010049(void)
496 {
497 	return DBcreate_index("escalations", "escalations_1", "actionid,triggerid,itemid,escalationid", 1);
498 }
499 
DBpatch_2010050(void)500 static int	DBpatch_2010050(void)
501 {
502 	const char	*fields[] = {"ts_from", "ts_to", NULL};
503 	DB_RESULT	result;
504 	DB_ROW		row;
505 	int		i;
506 	time_t		ts;
507 	struct tm	*tm;
508 
509 	for (i = 0; NULL != fields[i]; i++)
510 	{
511 		result = DBselect(
512 				"select timeid,%s"
513 				" from services_times"
514 				" where type in (%d,%d)"
515 					" and %s>%d",
516 				fields[i], 0 /* SERVICE_TIME_TYPE_UPTIME */, 1 /* SERVICE_TIME_TYPE_DOWNTIME */,
517 				fields[i], SEC_PER_WEEK);
518 
519 		while (NULL != (row = DBfetch(result)))
520 		{
521 			if (SEC_PER_WEEK < (ts = (time_t)atoi(row[1])))
522 			{
523 				tm = localtime(&ts);
524 				ts = tm->tm_wday * SEC_PER_DAY + tm->tm_hour * SEC_PER_HOUR + tm->tm_min * SEC_PER_MIN;
525 				DBexecute("update services_times set %s=%d where timeid=%s",
526 						fields[i], (int)ts, row[0]);
527 			}
528 		}
529 		DBfree_result(result);
530 	}
531 
532 	return SUCCEED;
533 }
534 
DBpatch_2010051(void)535 static int	DBpatch_2010051(void)
536 {
537 	const ZBX_FIELD field = {"hk_events_mode", "1", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
538 
539 	return DBadd_field("config", &field);
540 }
541 
DBpatch_2010052(void)542 static int	DBpatch_2010052(void)
543 {
544 	const ZBX_FIELD field = {"hk_events_trigger", "365", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
545 
546 	return DBadd_field("config", &field);
547 }
548 
DBpatch_2010053(void)549 static int	DBpatch_2010053(void)
550 {
551 	const ZBX_FIELD field = {"hk_events_internal", "365", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
552 
553 	return DBadd_field("config", &field);
554 }
555 
DBpatch_2010054(void)556 static int	DBpatch_2010054(void)
557 {
558 	const ZBX_FIELD field = {"hk_events_discovery", "365", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
559 
560 	return DBadd_field("config", &field);
561 }
562 
DBpatch_2010055(void)563 static int	DBpatch_2010055(void)
564 {
565 	const ZBX_FIELD field = {"hk_events_autoreg", "365", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
566 
567 	return DBadd_field("config", &field);
568 }
569 
DBpatch_2010056(void)570 static int	DBpatch_2010056(void)
571 {
572 	const ZBX_FIELD field = {"hk_services_mode", "1", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
573 
574 	return DBadd_field("config", &field);
575 }
576 
DBpatch_2010057(void)577 static int	DBpatch_2010057(void)
578 {
579 	const ZBX_FIELD field = {"hk_services", "365", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
580 
581 	return DBadd_field("config", &field);
582 }
583 
DBpatch_2010058(void)584 static int	DBpatch_2010058(void)
585 {
586 	const ZBX_FIELD field = {"hk_audit_mode", "1", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
587 
588 	return DBadd_field("config", &field);
589 }
590 
DBpatch_2010059(void)591 static int	DBpatch_2010059(void)
592 {
593 	const ZBX_FIELD field = {"hk_audit", "365", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
594 
595 	return DBadd_field("config", &field);
596 }
597 
DBpatch_2010060(void)598 static int	DBpatch_2010060(void)
599 {
600 	const ZBX_FIELD field = {"hk_sessions_mode", "1", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
601 
602 	return DBadd_field("config", &field);
603 }
604 
DBpatch_2010061(void)605 static int	DBpatch_2010061(void)
606 {
607 	const ZBX_FIELD field = {"hk_sessions", "365", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
608 
609 	return DBadd_field("config", &field);
610 }
611 
DBpatch_2010062(void)612 static int	DBpatch_2010062(void)
613 {
614 	const ZBX_FIELD field = {"hk_history_mode", "1", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
615 
616 	return DBadd_field("config", &field);
617 }
618 
DBpatch_2010063(void)619 static int	DBpatch_2010063(void)
620 {
621 	const ZBX_FIELD field = {"hk_history_global", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
622 
623 	return DBadd_field("config", &field);
624 }
625 
DBpatch_2010064(void)626 static int	DBpatch_2010064(void)
627 {
628 	const ZBX_FIELD field = {"hk_history", "90", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
629 
630 	return DBadd_field("config", &field);
631 }
632 
DBpatch_2010065(void)633 static int	DBpatch_2010065(void)
634 {
635 	const ZBX_FIELD field = {"hk_trends_mode", "1", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
636 
637 	return DBadd_field("config", &field);
638 }
639 
DBpatch_2010066(void)640 static int	DBpatch_2010066(void)
641 {
642 	const ZBX_FIELD field = {"hk_trends_global", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
643 
644 	return DBadd_field("config", &field);
645 }
646 
DBpatch_2010067(void)647 static int	DBpatch_2010067(void)
648 {
649 	const ZBX_FIELD field = {"hk_trends", "365", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
650 
651 	return DBadd_field("config", &field);
652 }
653 
DBpatch_2010068(void)654 static int	DBpatch_2010068(void)
655 {
656 	if (ZBX_DB_OK <= DBexecute(
657 			"update config"
658 			" set hk_events_mode=0,"
659 				"hk_services_mode=0,"
660 				"hk_audit_mode=0,"
661 				"hk_sessions_mode=0,"
662 				"hk_history_mode=0,"
663 				"hk_trends_mode=0,"
664 				"hk_events_trigger="
665 					"case when event_history>alert_history"
666 					" then event_history else alert_history end,"
667 				"hk_events_discovery="
668 					"case when event_history>alert_history"
669 					" then event_history else alert_history end,"
670 				"hk_events_autoreg="
671 					"case when event_history>alert_history"
672 					" then event_history else alert_history end,"
673 				"hk_events_internal="
674 					"case when event_history>alert_history"
675 					" then event_history else alert_history end"))
676 	{
677 		return SUCCEED;
678 	}
679 
680 	return FAIL;
681 }
682 
DBpatch_2010069(void)683 static int	DBpatch_2010069(void)
684 {
685 	return DBdrop_field("config", "event_history");
686 }
687 
DBpatch_2010070(void)688 static int	DBpatch_2010070(void)
689 {
690 	return DBdrop_field("config", "alert_history");
691 }
692 
DBpatch_2010071(void)693 static int	DBpatch_2010071(void)
694 {
695 	const ZBX_FIELD	field = {"snmpv3_contextname", "", NULL, NULL, 255, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0};
696 
697 	return DBadd_field("items", &field);
698 }
699 
DBpatch_2010072(void)700 static int	DBpatch_2010072(void)
701 {
702 	const ZBX_FIELD	field = {"snmpv3_contextname", "", NULL, NULL, 255, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0};
703 
704 	return DBadd_field("dchecks", &field);
705 }
706 
DBpatch_2010073(void)707 static int	DBpatch_2010073(void)
708 {
709 	const char	*sql = "delete from ids where table_name='events'";
710 
711 	if (ZBX_DB_OK <= DBexecute("%s", sql))
712 		return SUCCEED;
713 
714 	return FAIL;
715 }
716 
DBpatch_2010074(void)717 static int	DBpatch_2010074(void)
718 {
719 	const ZBX_FIELD	field = {"variables", "", NULL, NULL, 0, ZBX_TYPE_SHORTTEXT, ZBX_NOTNULL, 0};
720 
721 	return DBrename_field("httptest", "macros", &field);
722 }
723 
DBpatch_2010075(void)724 static int	DBpatch_2010075(void)
725 {
726 	const ZBX_FIELD	field = {"variables", "", NULL, NULL, 0, ZBX_TYPE_SHORTTEXT, ZBX_NOTNULL, 0};
727 
728 	return DBadd_field("httpstep", &field);
729 }
730 
DBpatch_2010076(void)731 static int	DBpatch_2010076(void)
732 {
733 	const ZBX_TABLE	table =
734 			{"application_template", "application_templateid", 0,
735 				{
736 					{"application_templateid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, ZBX_NOTNULL, 0},
737 					{"applicationid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, ZBX_NOTNULL, 0},
738 					{"templateid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, ZBX_NOTNULL, 0},
739 					{NULL}
740 				},
741 				NULL
742 			};
743 
744 	return DBcreate_table(&table);
745 }
746 
DBpatch_2010077(void)747 static int	DBpatch_2010077(void)
748 {
749 	return DBcreate_index("application_template", "application_template_1", "applicationid,templateid", 1);
750 }
751 
DBpatch_2010078(void)752 static int	DBpatch_2010078(void)
753 {
754 	const ZBX_FIELD	field = {"applicationid", NULL, "applications", "applicationid", 0, 0, 0, ZBX_FK_CASCADE_DELETE};
755 
756 	return DBadd_foreign_key("application_template", 1, &field);
757 }
758 
DBpatch_2010079(void)759 static int	DBpatch_2010079(void)
760 {
761 	const ZBX_FIELD	field = {"templateid", NULL, "applications", "applicationid", 0, 0, 0, ZBX_FK_CASCADE_DELETE};
762 
763 	return DBadd_foreign_key("application_template", 2, &field);
764 }
765 
DBpatch_2010080(void)766 static int	DBpatch_2010080(void)
767 {
768 	DB_RESULT	result;
769 	DB_ROW		row;
770 	zbx_uint64_t	applicationid, templateid, application_templateid = 1;
771 	int		ret = FAIL;
772 
773 	result = DBselect("select applicationid,templateid from applications where templateid is not null");
774 
775 	while (NULL != (row = DBfetch(result)))
776 	{
777 		ZBX_STR2UINT64(applicationid, row[0]);
778 		ZBX_STR2UINT64(templateid, row[1]);
779 
780 		if (ZBX_DB_OK > DBexecute(
781 				"insert into application_template"
782 					" (application_templateid,applicationid,templateid)"
783 					" values (" ZBX_FS_UI64 "," ZBX_FS_UI64 "," ZBX_FS_UI64 ")",
784 				application_templateid++, applicationid, templateid))
785 		{
786 			goto out;
787 		}
788 	}
789 
790 	ret = SUCCEED;
791 out:
792 	DBfree_result(result);
793 
794 	return ret;
795 }
796 
DBpatch_2010081(void)797 static int	DBpatch_2010081(void)
798 {
799 	return DBdrop_foreign_key("applications", 2);
800 }
801 
DBpatch_2010082(void)802 static int	DBpatch_2010082(void)
803 {
804 	return DBdrop_index("applications", "applications_1");
805 }
806 
DBpatch_2010083(void)807 static int	DBpatch_2010083(void)
808 {
809 	return DBdrop_field("applications", "templateid");
810 }
811 
DBpatch_2010084(void)812 static int	DBpatch_2010084(void)
813 {
814 	const ZBX_FIELD field = {"severity_min", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
815 
816 	return DBadd_field("sysmaps", &field);
817 }
818 
DBpatch_2010085(void)819 static int	DBpatch_2010085(void)
820 {
821 	const ZBX_FIELD	field = {"host_metadata", "", NULL, NULL, 255, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0};
822 
823 	return DBadd_field("autoreg_host", &field);
824 }
825 
DBpatch_2010086(void)826 static int	DBpatch_2010086(void)
827 {
828 	const ZBX_FIELD	field = {"host_metadata", "", NULL, NULL, 255, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0};
829 
830 	return DBadd_field("proxy_autoreg_host", &field);
831 }
832 
DBpatch_2010087(void)833 static int	DBpatch_2010087(void)
834 {
835 	return DBdrop_field("items", "lastclock");
836 }
837 
DBpatch_2010088(void)838 static int	DBpatch_2010088(void)
839 {
840 	return DBdrop_field("items", "lastns");
841 }
842 
DBpatch_2010089(void)843 static int	DBpatch_2010089(void)
844 {
845 	return DBdrop_field("items", "lastvalue");
846 }
847 
DBpatch_2010090(void)848 static int	DBpatch_2010090(void)
849 {
850 	return DBdrop_field("items", "prevvalue");
851 }
852 
DBpatch_2010091(void)853 static int	DBpatch_2010091(void)
854 {
855 	return DBdrop_field("items", "prevorgvalue");
856 }
857 
DBpatch_2010092(void)858 static int	DBpatch_2010092(void)
859 {
860 	const ZBX_FIELD	field = {"width", "900", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
861 
862 	return DBset_default("graphs", &field);
863 }
864 
DBpatch_2010093(void)865 static int	DBpatch_2010093(void)
866 {
867 	const ZBX_FIELD	field = {"height", "200", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
868 
869 	return DBset_default("graphs", &field);
870 }
871 
DBpatch_2010094(void)872 static int	DBpatch_2010094(void)
873 {
874 	if (ZBX_DB_OK <= DBexecute("update items set history=1 where history=0"))
875 	{
876 		return SUCCEED;
877 	}
878 
879 	return FAIL;
880 }
881 
DBpatch_2010098(void)882 static int	DBpatch_2010098(void)
883 {
884 #ifdef HAVE_MYSQL
885 	return DBdrop_index("proxy_history", "id");
886 #else
887 	return SUCCEED;
888 #endif
889 }
890 
DBpatch_2010099(void)891 static int	DBpatch_2010099(void)
892 {
893 #ifdef HAVE_MYSQL
894 	return DBdrop_index("proxy_dhistory", "id");
895 #else
896 	return SUCCEED;
897 #endif
898 }
899 
DBpatch_2010100(void)900 static int	DBpatch_2010100(void)
901 {
902 #ifdef HAVE_MYSQL
903 	return DBdrop_index("proxy_autoreg_host", "id");
904 #else
905 	return SUCCEED;
906 #endif
907 }
908 
DBpatch_2010101(void)909 static int	DBpatch_2010101(void)
910 {
911 	DB_RESULT	result;
912 	DB_ROW		row;
913 	int		ret = SUCCEED;
914 	char		*key = NULL;
915 	size_t		key_alloc = 0, key_offset;
916 
917 	result = DBselect(
918 			"select i.itemid,i.key_,i.params,h.name"
919 			" from items i,hosts h"
920 			" where i.hostid=h.hostid"
921 				" and i.type=%d",
922 			ITEM_TYPE_DB_MONITOR);
923 
924 	while (NULL != (row = DBfetch(result)) && SUCCEED == ret)
925 	{
926 		char		*user = NULL, *password = NULL, *dsn = NULL, *sql = NULL, *error_message = NULL;
927 		zbx_uint64_t	itemid;
928 		size_t		key_len;
929 
930 		key_len = strlen(row[1]);
931 
932 		parse_db_monitor_item_params(row[2], &dsn, &user, &password, &sql);
933 
934 		if (0 != strncmp(row[1], "db.odbc.select[", 15) || ']' != row[1][key_len - 1])
935 			error_message = zbx_dsprintf(error_message, "key \"%s\" is invalid", row[1]);
936 		else if (ITEM_USERNAME_LEN < strlen(user))
937 			error_message = zbx_dsprintf(error_message, "ODBC username \"%s\" is too long", user);
938 		else if (ITEM_PASSWORD_LEN < strlen(password))
939 			error_message = zbx_dsprintf(error_message, "ODBC password \"%s\" is too long", password);
940 		else
941 		{
942 			char	*param = NULL;
943 			size_t	param_alloc = 0, param_offset = 0;
944 			int	nparam;
945 
946 			zbx_strncpy_alloc(&param, &param_alloc, &param_offset, row[1] + 15, key_len - 16);
947 
948 			if (1 != (nparam = num_param(param)))
949 			{
950 				if (FAIL == (ret = quote_key_param(&param, 0)))
951 					error_message = zbx_dsprintf(error_message, "unique description"
952 							" \"%s\" contains invalid symbols and cannot be quoted", param);
953 			}
954 			if (FAIL == (ret = quote_key_param(&dsn, 0)))
955 			{
956 				error_message = zbx_dsprintf(error_message, "data source name"
957 						" \"%s\" contains invalid symbols and cannot be quoted", dsn);
958 			}
959 
960 			if (SUCCEED == ret)
961 			{
962 				key_offset = 0;
963 				zbx_snprintf_alloc(&key, &key_alloc, &key_offset, "db.odbc.select[%s,%s]", param, dsn);
964 
965 				zbx_free(param);
966 
967 				if (255 /* ITEM_KEY_LEN */ < zbx_strlen_utf8(key))
968 					error_message = zbx_dsprintf(error_message, "key \"%s\" is too long", row[1]);
969 			}
970 
971 			zbx_free(param);
972 		}
973 
974 		if (NULL == error_message)
975 		{
976 			char	*username_esc, *password_esc, *params_esc, *key_esc;
977 
978 			ZBX_STR2UINT64(itemid, row[0]);
979 
980 			username_esc = DBdyn_escape_string(user);
981 			password_esc = DBdyn_escape_string(password);
982 			params_esc = DBdyn_escape_string(sql);
983 			key_esc = DBdyn_escape_string(key);
984 
985 			if (ZBX_DB_OK > DBexecute("update items set username='%s',password='%s',key_='%s',params='%s'"
986 					" where itemid=" ZBX_FS_UI64,
987 					username_esc, password_esc, key_esc, params_esc, itemid))
988 			{
989 				ret = FAIL;
990 			}
991 
992 			zbx_free(username_esc);
993 			zbx_free(password_esc);
994 			zbx_free(params_esc);
995 			zbx_free(key_esc);
996 		}
997 		else
998 		{
999 			zabbix_log(LOG_LEVEL_WARNING, "Failed to convert host \"%s\" db monitoring item because"
1000 					" %s. See upgrade notes for manual database monitor item conversion.",
1001 					row[3], error_message);
1002 		}
1003 
1004 		zbx_free(error_message);
1005 		zbx_free(user);
1006 		zbx_free(password);
1007 		zbx_free(dsn);
1008 		zbx_free(sql);
1009 	}
1010 	DBfree_result(result);
1011 
1012 	zbx_free(key);
1013 
1014 	return ret;
1015 }
1016 
DBpatch_2010102(void)1017 static int	DBpatch_2010102(void)
1018 {
1019 	return DBcreate_index("hosts", "hosts_5", "maintenanceid", 0);
1020 }
1021 
DBpatch_2010103(void)1022 static int	DBpatch_2010103(void)
1023 {
1024 	return DBcreate_index("screens", "screens_1", "templateid", 0);
1025 }
1026 
DBpatch_2010104(void)1027 static int	DBpatch_2010104(void)
1028 {
1029 	return DBcreate_index("screens_items", "screens_items_1", "screenid", 0);
1030 }
1031 
DBpatch_2010105(void)1032 static int	DBpatch_2010105(void)
1033 {
1034 	return DBcreate_index("slides", "slides_2", "screenid", 0);
1035 }
1036 
DBpatch_2010106(void)1037 static int	DBpatch_2010106(void)
1038 {
1039 	return DBcreate_index("drules", "drules_1", "proxy_hostid", 0);
1040 }
1041 
DBpatch_2010107(void)1042 static int	DBpatch_2010107(void)
1043 {
1044 	return DBcreate_index("items", "items_6", "interfaceid", 0);
1045 }
1046 
DBpatch_2010108(void)1047 static int	DBpatch_2010108(void)
1048 {
1049 	return DBcreate_index("httpstepitem", "httpstepitem_2", "itemid", 0);
1050 }
1051 
DBpatch_2010109(void)1052 static int	DBpatch_2010109(void)
1053 {
1054 	return DBcreate_index("httptestitem", "httptestitem_2", "itemid", 0);
1055 }
1056 
DBpatch_2010110(void)1057 static int	DBpatch_2010110(void)
1058 {
1059 	return DBcreate_index("users_groups", "users_groups_2", "userid", 0);
1060 }
1061 
DBpatch_2010111(void)1062 static int	DBpatch_2010111(void)
1063 {
1064 	return DBcreate_index("scripts", "scripts_1", "usrgrpid", 0);
1065 }
1066 
DBpatch_2010112(void)1067 static int	DBpatch_2010112(void)
1068 {
1069 	return DBcreate_index("scripts", "scripts_2", "groupid", 0);
1070 }
1071 
DBpatch_2010113(void)1072 static int	DBpatch_2010113(void)
1073 {
1074 	return DBcreate_index("opmessage", "opmessage_1", "mediatypeid", 0);
1075 }
1076 
DBpatch_2010114(void)1077 static int	DBpatch_2010114(void)
1078 {
1079 	return DBcreate_index("opmessage_grp", "opmessage_grp_2", "usrgrpid", 0);
1080 }
1081 
DBpatch_2010115(void)1082 static int	DBpatch_2010115(void)
1083 {
1084 	return DBcreate_index("opmessage_usr", "opmessage_usr_2", "userid", 0);
1085 }
1086 
DBpatch_2010116(void)1087 static int	DBpatch_2010116(void)
1088 {
1089 	return DBcreate_index("opcommand", "opcommand_1", "scriptid", 0);
1090 }
1091 
DBpatch_2010117(void)1092 static int	DBpatch_2010117(void)
1093 {
1094 	return DBcreate_index("opcommand_hst", "opcommand_hst_2", "hostid", 0);
1095 }
1096 
DBpatch_2010118(void)1097 static int	DBpatch_2010118(void)
1098 {
1099 	return DBcreate_index("opcommand_grp", "opcommand_grp_2", "groupid", 0);
1100 }
1101 
DBpatch_2010119(void)1102 static int	DBpatch_2010119(void)
1103 {
1104 	return DBcreate_index("opgroup", "opgroup_2", "groupid", 0);
1105 }
1106 
DBpatch_2010120(void)1107 static int	DBpatch_2010120(void)
1108 {
1109 	return DBcreate_index("optemplate", "optemplate_2", "templateid", 0);
1110 }
1111 
DBpatch_2010121(void)1112 static int	DBpatch_2010121(void)
1113 {
1114 	return DBcreate_index("config", "config_1", "alert_usrgrpid", 0);
1115 }
1116 
DBpatch_2010122(void)1117 static int	DBpatch_2010122(void)
1118 {
1119 	return DBcreate_index("config", "config_2", "discovery_groupid", 0);
1120 }
1121 
DBpatch_2010123(void)1122 static int	DBpatch_2010123(void)
1123 {
1124 	return DBcreate_index("triggers", "triggers_3", "templateid", 0);
1125 }
1126 
DBpatch_2010124(void)1127 static int	DBpatch_2010124(void)
1128 {
1129 	return DBcreate_index("graphs", "graphs_2", "templateid", 0);
1130 }
1131 
DBpatch_2010125(void)1132 static int	DBpatch_2010125(void)
1133 {
1134 	return DBcreate_index("graphs", "graphs_3", "ymin_itemid", 0);
1135 }
1136 
DBpatch_2010126(void)1137 static int	DBpatch_2010126(void)
1138 {
1139 	return DBcreate_index("graphs", "graphs_4", "ymax_itemid", 0);
1140 }
1141 
DBpatch_2010127(void)1142 static int	DBpatch_2010127(void)
1143 {
1144 	return DBcreate_index("icon_map", "icon_map_2", "default_iconid", 0);
1145 }
1146 
DBpatch_2010128(void)1147 static int	DBpatch_2010128(void)
1148 {
1149 	return DBcreate_index("icon_mapping", "icon_mapping_2", "iconid", 0);
1150 }
1151 
DBpatch_2010129(void)1152 static int	DBpatch_2010129(void)
1153 {
1154 	return DBcreate_index("sysmaps", "sysmaps_2", "backgroundid", 0);
1155 }
1156 
DBpatch_2010130(void)1157 static int	DBpatch_2010130(void)
1158 {
1159 	return DBcreate_index("sysmaps", "sysmaps_3", "iconmapid", 0);
1160 }
1161 
DBpatch_2010131(void)1162 static int	DBpatch_2010131(void)
1163 {
1164 	return DBcreate_index("sysmaps_elements", "sysmaps_elements_1", "sysmapid", 0);
1165 }
1166 
DBpatch_2010132(void)1167 static int	DBpatch_2010132(void)
1168 {
1169 	return DBcreate_index("sysmaps_elements", "sysmaps_elements_2", "iconid_off", 0);
1170 }
1171 
DBpatch_2010133(void)1172 static int	DBpatch_2010133(void)
1173 {
1174 	return DBcreate_index("sysmaps_elements", "sysmaps_elements_3", "iconid_on", 0);
1175 }
1176 
DBpatch_2010134(void)1177 static int	DBpatch_2010134(void)
1178 {
1179 	return DBcreate_index("sysmaps_elements", "sysmaps_elements_4", "iconid_disabled", 0);
1180 }
1181 
DBpatch_2010135(void)1182 static int	DBpatch_2010135(void)
1183 {
1184 	return DBcreate_index("sysmaps_elements", "sysmaps_elements_5", "iconid_maintenance", 0);
1185 }
1186 
DBpatch_2010136(void)1187 static int	DBpatch_2010136(void)
1188 {
1189 	return DBcreate_index("sysmaps_links", "sysmaps_links_1", "sysmapid", 0);
1190 }
1191 
DBpatch_2010137(void)1192 static int	DBpatch_2010137(void)
1193 {
1194 	return DBcreate_index("sysmaps_links", "sysmaps_links_2", "selementid1", 0);
1195 }
1196 
DBpatch_2010138(void)1197 static int	DBpatch_2010138(void)
1198 {
1199 	return DBcreate_index("sysmaps_links", "sysmaps_links_3", "selementid2", 0);
1200 }
1201 
DBpatch_2010139(void)1202 static int	DBpatch_2010139(void)
1203 {
1204 	return DBcreate_index("sysmaps_link_triggers", "sysmaps_link_triggers_2", "triggerid", 0);
1205 }
1206 
DBpatch_2010140(void)1207 static int	DBpatch_2010140(void)
1208 {
1209 	return DBcreate_index("maintenances_hosts", "maintenances_hosts_2", "hostid", 0);
1210 }
1211 
DBpatch_2010141(void)1212 static int	DBpatch_2010141(void)
1213 {
1214 	return DBcreate_index("maintenances_groups", "maintenances_groups_2", "groupid", 0);
1215 }
1216 
DBpatch_2010142(void)1217 static int	DBpatch_2010142(void)
1218 {
1219 	return DBcreate_index("maintenances_windows", "maintenances_windows_2", "timeperiodid", 0);
1220 }
1221 
DBpatch_2010143(void)1222 static int	DBpatch_2010143(void)
1223 {
1224 	return DBcreate_index("nodes", "nodes_1", "masterid", 0);
1225 }
1226 
DBpatch_2010144(void)1227 static int	DBpatch_2010144(void)
1228 {
1229 	return DBcreate_index("graph_discovery", "graph_discovery_2", "parent_graphid", 0);
1230 }
1231 
DBpatch_2010145(void)1232 static int	DBpatch_2010145(void)
1233 {
1234 	return DBcreate_index("item_discovery", "item_discovery_2", "parent_itemid", 0);
1235 }
1236 
DBpatch_2010146(void)1237 static int	DBpatch_2010146(void)
1238 {
1239 	return DBcreate_index("trigger_discovery", "trigger_discovery_2", "parent_triggerid", 0);
1240 }
1241 
DBpatch_2010147(void)1242 static int	DBpatch_2010147(void)
1243 {
1244 	return DBcreate_index("application_template", "application_template_2", "templateid", 0);
1245 }
1246 
DBpatch_2010148(void)1247 static int	DBpatch_2010148(void)
1248 {
1249 	return DBrename_index("slides", "slides_slides_1", "slides_1", "slideshowid", 0);
1250 }
1251 
DBpatch_2010149(void)1252 static int	DBpatch_2010149(void)
1253 {
1254 	return DBrename_index("httptest", "httptest_httptest_1", "httptest_1", "applicationid", 0);
1255 }
1256 
DBpatch_2010150(void)1257 static int	DBpatch_2010150(void)
1258 {
1259 	return DBrename_index("httpstep", "httpstep_httpstep_1", "httpstep_1", "httptestid", 0);
1260 }
1261 
DBpatch_2010151(void)1262 static int	DBpatch_2010151(void)
1263 {
1264 	return DBrename_index("httpstepitem", "httpstepitem_httpstepitem_1", "httpstepitem_1", "httpstepid,itemid", 1);
1265 }
1266 
DBpatch_2010152(void)1267 static int	DBpatch_2010152(void)
1268 {
1269 	return DBrename_index("httptestitem", "httptestitem_httptestitem_1", "httptestitem_1", "httptestid,itemid", 1);
1270 }
1271 
DBpatch_2010153(void)1272 static int	DBpatch_2010153(void)
1273 {
1274 	return DBrename_index("graphs", "graphs_graphs_1", "graphs_1", "name", 0);
1275 }
1276 
DBpatch_2010154(void)1277 static int	DBpatch_2010154(void)
1278 {
1279 	return DBrename_index("services_links", "services_links_links_1", "services_links_1", "servicedownid", 0);
1280 }
1281 
DBpatch_2010155(void)1282 static int	DBpatch_2010155(void)
1283 {
1284 	return DBrename_index("services_links", "services_links_links_2", "services_links_2",
1285 			"serviceupid,servicedownid", 1);
1286 }
1287 
DBpatch_2010156(void)1288 static int	DBpatch_2010156(void)
1289 {
1290 	return DBrename_index("services_times", "services_times_times_1", "services_times_1",
1291 			"serviceid,type,ts_from,ts_to", 0);
1292 }
1293 
DBpatch_2010157(void)1294 static int	DBpatch_2010157(void)
1295 {
1296 	const ZBX_FIELD field = {"flags", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
1297 
1298 	return DBadd_field("hosts", &field);
1299 }
1300 
DBpatch_2010158(void)1301 static int	DBpatch_2010158(void)
1302 {
1303 	const ZBX_TABLE	table =
1304 			{"host_discovery", "hostid", 0,
1305 				{
1306 					{"hostid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, ZBX_NOTNULL, 0},
1307 					{"parent_hostid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, 0, 0},
1308 					{"parent_itemid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, 0, 0},
1309 					{"host", "", NULL, NULL, 64, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0},
1310 					{"lastcheck", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0},
1311 					{"ts_delete", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0},
1312 					{NULL}
1313 				},
1314 				NULL
1315 			};
1316 
1317 	return DBcreate_table(&table);
1318 }
1319 
DBpatch_2010159(void)1320 static int	DBpatch_2010159(void)
1321 {
1322 	const ZBX_FIELD	field = {"hostid", NULL, "hosts", "hostid", 0, 0, 0, ZBX_FK_CASCADE_DELETE};
1323 
1324 	return DBadd_foreign_key("host_discovery", 1, &field);
1325 }
1326 
DBpatch_2010160(void)1327 static int	DBpatch_2010160(void)
1328 {
1329 	const ZBX_FIELD	field = {"parent_hostid", NULL, "hosts", "hostid", 0, 0, 0, 0};
1330 
1331 	return DBadd_foreign_key("host_discovery", 2, &field);
1332 }
1333 
DBpatch_2010161(void)1334 static int	DBpatch_2010161(void)
1335 {
1336 	const ZBX_FIELD	field = {"parent_itemid", NULL, "items", "itemid", 0, 0, 0, 0};
1337 
1338 	return DBadd_foreign_key("host_discovery", 3, &field);
1339 }
1340 
DBpatch_2010162(void)1341 static int	DBpatch_2010162(void)
1342 {
1343 	const ZBX_FIELD field = {"templateid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, 0, 0};
1344 
1345 	return DBadd_field("hosts", &field);
1346 }
1347 
DBpatch_2010163(void)1348 static int	DBpatch_2010163(void)
1349 {
1350 	const ZBX_FIELD	field = {"templateid", NULL, "hosts", "hostid", 0, 0, 0, ZBX_FK_CASCADE_DELETE};
1351 
1352 	return DBadd_foreign_key("hosts", 3, &field);
1353 }
1354 
DBpatch_2010164(void)1355 static int	DBpatch_2010164(void)
1356 {
1357 	const ZBX_TABLE	table =
1358 			{"interface_discovery", "interfaceid", 0,
1359 				{
1360 					{"interfaceid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, ZBX_NOTNULL, 0},
1361 					{"parent_interfaceid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, ZBX_NOTNULL, 0},
1362 					{NULL}
1363 				},
1364 				NULL
1365 			};
1366 
1367 	return DBcreate_table(&table);
1368 }
1369 
DBpatch_2010165(void)1370 static int	DBpatch_2010165(void)
1371 {
1372 	const ZBX_FIELD	field = {"interfaceid", NULL, "interface", "interfaceid", 0, 0, 0, ZBX_FK_CASCADE_DELETE};
1373 
1374 	return DBadd_foreign_key("interface_discovery", 1, &field);
1375 }
1376 
DBpatch_2010166(void)1377 static int	DBpatch_2010166(void)
1378 {
1379 	const ZBX_FIELD	field =
1380 			{"parent_interfaceid", NULL, "interface", "interfaceid", 0, 0, 0, ZBX_FK_CASCADE_DELETE};
1381 
1382 	return DBadd_foreign_key("interface_discovery", 2, &field);
1383 }
1384 
DBpatch_2010167(void)1385 static int	DBpatch_2010167(void)
1386 {
1387 	const ZBX_TABLE	table =
1388 			{"group_prototype", "group_prototypeid", 0,
1389 				{
1390 					{"group_prototypeid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, ZBX_NOTNULL, 0},
1391 					{"hostid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, ZBX_NOTNULL, 0},
1392 					{"name", "", NULL, NULL, 64, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0},
1393 					{"groupid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, 0, 0},
1394 					{"templateid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, 0, 0},
1395 					{NULL}
1396 				},
1397 				NULL
1398 			};
1399 
1400 	return DBcreate_table(&table);
1401 }
1402 
DBpatch_2010168(void)1403 static int	DBpatch_2010168(void)
1404 {
1405 	const ZBX_FIELD	field = {"hostid", NULL, "hosts", "hostid", 0, 0, 0, ZBX_FK_CASCADE_DELETE};
1406 
1407 	return DBadd_foreign_key("group_prototype", 1, &field);
1408 }
1409 
DBpatch_2010169(void)1410 static int	DBpatch_2010169(void)
1411 {
1412 	const ZBX_FIELD	field = {"groupid", NULL, "groups", "groupid", 0, 0, 0, 0};
1413 
1414 	return DBadd_foreign_key("group_prototype", 2, &field);
1415 }
1416 
DBpatch_2010170(void)1417 static int	DBpatch_2010170(void)
1418 {
1419 	const ZBX_FIELD	field = {"templateid", NULL, "group_prototype", "group_prototypeid", 0, 0, 0, ZBX_FK_CASCADE_DELETE};
1420 
1421 	return DBadd_foreign_key("group_prototype", 3, &field);
1422 }
1423 
DBpatch_2010171(void)1424 static int	DBpatch_2010171(void)
1425 {
1426 	return DBcreate_index("group_prototype", "group_prototype_1", "hostid", 0);
1427 }
1428 
DBpatch_2010172(void)1429 static int	DBpatch_2010172(void)
1430 {
1431 	const ZBX_TABLE	table =
1432 			{"group_discovery", "groupid", 0,
1433 				{
1434 					{"groupid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, ZBX_NOTNULL, 0},
1435 					{"parent_group_prototypeid", NULL, NULL, NULL, 0, ZBX_TYPE_ID, ZBX_NOTNULL, 0},
1436 					{"name", "", NULL, NULL, 64, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0},
1437 					{"lastcheck", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0},
1438 					{"ts_delete", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0},
1439 					{NULL}
1440 				},
1441 				NULL
1442 			};
1443 
1444 	return DBcreate_table(&table);
1445 }
1446 
DBpatch_2010173(void)1447 static int	DBpatch_2010173(void)
1448 {
1449 	const ZBX_FIELD	field = {"groupid", NULL, "groups", "groupid", 0, 0, 0, ZBX_FK_CASCADE_DELETE};
1450 
1451 	return DBadd_foreign_key("group_discovery", 1, &field);
1452 }
1453 
DBpatch_2010174(void)1454 static int	DBpatch_2010174(void)
1455 {
1456 	const ZBX_FIELD	field = {"parent_group_prototypeid", NULL, "group_prototype", "group_prototypeid", 0, 0, 0, 0};
1457 
1458 	return DBadd_foreign_key("group_discovery", 2, &field);
1459 }
1460 
DBpatch_2010175(void)1461 static int	DBpatch_2010175(void)
1462 {
1463 	const ZBX_FIELD field = {"flags", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
1464 
1465 	return DBadd_field("groups", &field);
1466 }
1467 
DBpatch_2010176(void)1468 static int	DBpatch_2010176(void)
1469 {
1470 	DB_RESULT	result;
1471 	DB_ROW		row;
1472 	char		*name, *name_esc;
1473 	int		ret = SUCCEED;
1474 
1475 	result = DBselect("select scriptid,name from scripts");
1476 
1477 	while (SUCCEED == ret && NULL != (row = DBfetch(result)))
1478 	{
1479 		name = zbx_dyn_escape_string(row[1], "/\\");
1480 
1481 		if (0 != strcmp(name, row[1]))
1482 		{
1483 			name_esc = DBdyn_escape_string_len(name, 255);
1484 
1485 			if (ZBX_DB_OK > DBexecute("update scripts set name='%s' where scriptid=%s", name_esc, row[0]))
1486 				ret = FAIL;
1487 
1488 			zbx_free(name_esc);
1489 		}
1490 
1491 		zbx_free(name);
1492 	}
1493 	DBfree_result(result);
1494 
1495 	return ret;
1496 }
1497 
DBpatch_2010177(void)1498 static int	DBpatch_2010177(void)
1499 {
1500 	const char	*rf_rate_strings[] = {"syssum", "hoststat", "stszbx", "lastiss", "webovr", "dscvry", NULL};
1501 	int		i;
1502 
1503 	for (i = 0; NULL != rf_rate_strings[i]; i++)
1504 	{
1505 		if (ZBX_DB_OK > DBexecute(
1506 				"update profiles"
1507 				" set idx='web.dashboard.widget.%s.rf_rate'"
1508 				" where idx='web.dashboard.rf_rate.hat_%s'",
1509 				rf_rate_strings[i], rf_rate_strings[i]))
1510 		{
1511 			return FAIL;
1512 		}
1513 	}
1514 
1515 	return SUCCEED;
1516 }
1517 
DBpatch_2010178(void)1518 static int	DBpatch_2010178(void)
1519 {
1520 	const char	*state_strings[] = {"favgrph", "favscr", "favmap", "syssum", "hoststat", "stszbx", "lastiss",
1521 			"webovr", "dscvry", NULL};
1522 	int		i;
1523 
1524 	for (i = 0; NULL != state_strings[i]; i++)
1525 	{
1526 		if (ZBX_DB_OK > DBexecute(
1527 				"update profiles"
1528 				" set idx='web.dashboard.widget.%s.state'"
1529 				" where idx='web.dashboard.hats.hat_%s.state'",
1530 				state_strings[i], state_strings[i]))
1531 		{
1532 			return FAIL;
1533 		}
1534 	}
1535 
1536 	return SUCCEED;
1537 }
1538 
DBpatch_2010179(void)1539 static int	DBpatch_2010179(void)
1540 {
1541 	const ZBX_FIELD	field = {"yaxismax", "100", NULL, NULL, 0, ZBX_TYPE_FLOAT, ZBX_NOTNULL, 0};
1542 
1543 	return DBset_default("graphs", &field);
1544 }
1545 
DBpatch_2010180(void)1546 static int	DBpatch_2010180(void)
1547 {
1548 	const ZBX_FIELD	field = {"yaxisside", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
1549 
1550 	return DBset_default("graphs_items", &field);
1551 }
1552 
DBpatch_2010181(void)1553 static int	DBpatch_2010181(void)
1554 {
1555 	const ZBX_FIELD	field = {"ip", "127.0.0.1", NULL, NULL, 64, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0};
1556 
1557 	return DBmodify_field_type("interface", &field, NULL);
1558 }
1559 
DBpatch_2010182(void)1560 static int	DBpatch_2010182(void)
1561 {
1562 	const ZBX_FIELD	field = {"label", "", NULL, NULL, 2048, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0};
1563 
1564 	return DBmodify_field_type("sysmaps_elements", &field, NULL);
1565 }
1566 
DBpatch_2010183(void)1567 static int	DBpatch_2010183(void)
1568 {
1569 	const ZBX_FIELD	field = {"label", "", NULL, NULL, 2048, ZBX_TYPE_CHAR, ZBX_NOTNULL, 0};
1570 
1571 	return DBmodify_field_type("sysmaps_links", &field, NULL);
1572 }
1573 
DBpatch_2010184(void)1574 static int	DBpatch_2010184(void)
1575 {
1576 	const ZBX_FIELD	field = {"label_location", "0", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
1577 
1578 	return DBset_default("sysmaps", &field);
1579 }
1580 
DBpatch_2010185(void)1581 static int	DBpatch_2010185(void)
1582 {
1583 	if (ZBX_DB_OK > DBexecute("update sysmaps_elements set label_location=-1 where label_location is null"))
1584 		return FAIL;
1585 
1586 	return SUCCEED;
1587 }
1588 
DBpatch_2010186(void)1589 static int	DBpatch_2010186(void)
1590 {
1591 	const ZBX_FIELD	field = {"label_location", "-1", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
1592 
1593 	return DBset_default("sysmaps_elements", &field);
1594 }
1595 
DBpatch_2010187(void)1596 static int	DBpatch_2010187(void)
1597 {
1598 	const ZBX_FIELD	field = {"label_location", "-1", NULL, NULL, 0, ZBX_TYPE_INT, ZBX_NOTNULL, 0};
1599 
1600 	return DBset_not_null("sysmaps_elements", &field);
1601 }
1602 
DBpatch_2010188(void)1603 static int	DBpatch_2010188(void)
1604 {
1605 	return DBdrop_index("events", "events_1");
1606 }
1607 
DBpatch_2010189(void)1608 static int	DBpatch_2010189(void)
1609 {
1610 	return DBdrop_index("events", "events_2");
1611 }
1612 
DBpatch_2010190(void)1613 static int	DBpatch_2010190(void)
1614 {
1615 	return DBcreate_index("events", "events_1", "source,object,objectid,clock", 0);
1616 }
1617 
DBpatch_2010191(void)1618 static int	DBpatch_2010191(void)
1619 {
1620 	return DBcreate_index("events", "events_2", "source,object,clock", 0);
1621 }
1622 
DBpatch_2010192(void)1623 static int	DBpatch_2010192(void)
1624 {
1625 	if (ZBX_DB_OK <= DBexecute(
1626 			"update triggers"
1627 			" set state=%d,value=%d,lastchange=0,error=''"
1628 			" where exists ("
1629 				"select null"
1630 				" from functions f,items i,hosts h"
1631 				" where triggers.triggerid=f.triggerid"
1632 					" and f.itemid=i.itemid"
1633 					" and i.hostid=h.hostid"
1634 					" and h.status=%d"
1635 			")",
1636 			TRIGGER_STATE_NORMAL, TRIGGER_VALUE_OK, HOST_STATUS_TEMPLATE))
1637 	{
1638 		return SUCCEED;
1639 	}
1640 
1641 	return FAIL;
1642 }
1643 
DBpatch_2010193(void)1644 static int	DBpatch_2010193(void)
1645 {
1646 	if (ZBX_DB_OK <= DBexecute(
1647 			"update items"
1648 			" set state=%d,error=''"
1649 			" where exists ("
1650 				"select null"
1651 				" from hosts h"
1652 				" where items.hostid=h.hostid"
1653 					" and h.status=%d"
1654 			")",
1655 			ITEM_STATE_NORMAL, HOST_STATUS_TEMPLATE))
1656 	{
1657 		return SUCCEED;
1658 	}
1659 
1660 	return FAIL;
1661 }
1662 
DBpatch_2010194(void)1663 static int	DBpatch_2010194(void)
1664 {
1665 	return DBdrop_table("help_items");
1666 }
1667 
1668 /******************************************************************************
1669  *                                                                            *
1670  * Function: DBpatch_2010195_replace_key_param_cb                             *
1671  *                                                                            *
1672  * Comments: auxiliary function for DBpatch_2010195()                         *
1673  *                                                                            *
1674  ******************************************************************************/
DBpatch_2010195_replace_key_param_cb(const char * data,int key_type,int level,int num,int quoted,void * cb_data,char ** new_param)1675 static int	DBpatch_2010195_replace_key_param_cb(const char *data, int key_type, int level, int num, int quoted,
1676 			void *cb_data, char **new_param)
1677 {
1678 	char	*param;
1679 	int	ret;
1680 
1681 	ZBX_UNUSED(key_type);
1682 	ZBX_UNUSED(cb_data);
1683 
1684 	if (1 != level || 4 != num)	/* the fourth parameter on first level should be updated */
1685 		return SUCCEED;
1686 
1687 	param = zbx_strdup(NULL, data);
1688 
1689 	unquote_key_param(param);
1690 
1691 	if ('\0' == *param)
1692 	{
1693 		zbx_free(param);
1694 		return SUCCEED;
1695 	}
1696 
1697 	*new_param = zbx_dsprintf(NULL, "^%s$", param);
1698 
1699 	zbx_free(param);
1700 
1701 	if (FAIL == (ret = quote_key_param(new_param, quoted)))
1702 		zbx_free(new_param);
1703 
1704 	return ret;
1705 }
1706 
DBpatch_2010195(void)1707 static int	DBpatch_2010195(void)
1708 {
1709 	DB_RESULT	result;
1710 	DB_ROW		row;
1711 	char		*key = NULL, *key_esc, error[64];
1712 	int		ret = SUCCEED;
1713 
1714 	result = DBselect("select itemid,key_ from items where key_ like 'eventlog[%%'");
1715 
1716 	while (SUCCEED == ret && NULL != (row = DBfetch(result)))
1717 	{
1718 		key = zbx_strdup(key, row[1]);
1719 
1720 		if (SUCCEED != replace_key_params_dyn(&key, ZBX_KEY_TYPE_ITEM, DBpatch_2010195_replace_key_param_cb,
1721 				NULL, error, sizeof(error)))
1722 		{
1723 			zabbix_log(LOG_LEVEL_WARNING, "cannot convert item key \"%s\": %s", row[1], error);
1724 			continue;
1725 		}
1726 
1727 		if (255 /* ITEM_KEY_LEN */ < zbx_strlen_utf8(key))
1728 		{
1729 			zabbix_log(LOG_LEVEL_WARNING, "cannot convert item key \"%s\": key is too long", row[1]);
1730 			continue;
1731 		}
1732 
1733 		if (0 != strcmp(key, row[1]))
1734 		{
1735 			key_esc = DBdyn_escape_string(key);
1736 
1737 			if (ZBX_DB_OK > DBexecute("update items set key_='%s' where itemid=%s", key_esc, row[0]))
1738 				ret = FAIL;
1739 
1740 			zbx_free(key_esc);
1741 		}
1742 	}
1743 	DBfree_result(result);
1744 
1745 	zbx_free(key);
1746 
1747 	return ret;
1748 }
1749 
DBpatch_2010196(void)1750 static int	DBpatch_2010196(void)
1751 {
1752 #ifdef HAVE_ORACLE
1753 	const ZBX_FIELD	field = {"message_tmp", "", NULL, NULL, 0, ZBX_TYPE_TEXT, ZBX_NOTNULL, 0};
1754 
1755 	return DBadd_field("alerts", &field);
1756 #else
1757 	return SUCCEED;
1758 #endif
1759 }
1760 
DBpatch_2010197(void)1761 static int	DBpatch_2010197(void)
1762 {
1763 #ifdef HAVE_ORACLE
1764 	return ZBX_DB_OK > DBexecute("update alerts set message_tmp=message") ? FAIL : SUCCEED;
1765 #else
1766 	return SUCCEED;
1767 #endif
1768 }
1769 
DBpatch_2010198(void)1770 static int	DBpatch_2010198(void)
1771 {
1772 #ifdef HAVE_ORACLE
1773 	return DBdrop_field("alerts", "message");
1774 #else
1775 	return SUCCEED;
1776 #endif
1777 }
1778 
DBpatch_2010199(void)1779 static int	DBpatch_2010199(void)
1780 {
1781 #ifdef HAVE_ORACLE
1782 	const ZBX_FIELD	field = {"message", "", NULL, NULL, 0, ZBX_TYPE_TEXT, ZBX_NOTNULL, 0};
1783 
1784 	return DBrename_field("alerts", "message_tmp", &field);
1785 #else
1786 	return SUCCEED;
1787 #endif
1788 }
1789 
1790 #endif
1791 
1792 DBPATCH_START(2010)
1793 
1794 /* version, duplicates flag, mandatory flag */
1795 DBPATCH_ADD(2010001, 0, 1)
1796 DBPATCH_ADD(2010002, 0, 1)
1797 DBPATCH_ADD(2010003, 0, 1)
1798 DBPATCH_ADD(2010007, 0, 0)
1799 DBPATCH_ADD(2010008, 0, 1)
1800 DBPATCH_ADD(2010009, 0, 1)
1801 DBPATCH_ADD(2010010, 0, 1)
1802 DBPATCH_ADD(2010011, 0, 1)
1803 DBPATCH_ADD(2010012, 0, 1)
1804 DBPATCH_ADD(2010013, 0, 1)
1805 DBPATCH_ADD(2010014, 0, 1)
1806 DBPATCH_ADD(2010015, 0, 1)
1807 DBPATCH_ADD(2010016, 0, 1)
1808 DBPATCH_ADD(2010017, 0, 1)
1809 DBPATCH_ADD(2010018, 0, 1)
1810 DBPATCH_ADD(2010019, 0, 1)
1811 DBPATCH_ADD(2010020, 0, 1)
1812 DBPATCH_ADD(2010021, 0, 1)
1813 DBPATCH_ADD(2010022, 0, 1)
1814 DBPATCH_ADD(2010023, 0, 1)
1815 DBPATCH_ADD(2010024, 0, 1)
1816 DBPATCH_ADD(2010025, 0, 1)
1817 DBPATCH_ADD(2010026, 0, 1)
1818 DBPATCH_ADD(2010027, 0, 1)
1819 DBPATCH_ADD(2010028, 0, 0)
1820 DBPATCH_ADD(2010029, 0, 0)
1821 DBPATCH_ADD(2010030, 0, 0)
1822 DBPATCH_ADD(2010031, 0, 0)
1823 DBPATCH_ADD(2010032, 0, 1)
1824 DBPATCH_ADD(2010033, 0, 1)
1825 DBPATCH_ADD(2010034, 0, 1)
1826 DBPATCH_ADD(2010035, 0, 0)
1827 DBPATCH_ADD(2010036, 0, 0)
1828 DBPATCH_ADD(2010037, 0, 0)
1829 DBPATCH_ADD(2010038, 0, 0)
1830 DBPATCH_ADD(2010039, 0, 0)
1831 DBPATCH_ADD(2010040, 0, 1)
1832 DBPATCH_ADD(2010043, 0, 1)
1833 DBPATCH_ADD(2010044, 0, 1)
1834 DBPATCH_ADD(2010045, 0, 1)
1835 DBPATCH_ADD(2010046, 0, 1)
1836 DBPATCH_ADD(2010047, 0, 1)
1837 DBPATCH_ADD(2010048, 0, 0)
1838 DBPATCH_ADD(2010049, 0, 0)
1839 DBPATCH_ADD(2010050, 0, 1)
1840 DBPATCH_ADD(2010051, 0, 1)
1841 DBPATCH_ADD(2010052, 0, 1)
1842 DBPATCH_ADD(2010053, 0, 1)
1843 DBPATCH_ADD(2010054, 0, 1)
1844 DBPATCH_ADD(2010055, 0, 1)
1845 DBPATCH_ADD(2010056, 0, 1)
1846 DBPATCH_ADD(2010057, 0, 1)
1847 DBPATCH_ADD(2010058, 0, 1)
1848 DBPATCH_ADD(2010059, 0, 1)
1849 DBPATCH_ADD(2010060, 0, 1)
1850 DBPATCH_ADD(2010061, 0, 1)
1851 DBPATCH_ADD(2010062, 0, 1)
1852 DBPATCH_ADD(2010063, 0, 1)
1853 DBPATCH_ADD(2010064, 0, 1)
1854 DBPATCH_ADD(2010065, 0, 1)
1855 DBPATCH_ADD(2010066, 0, 1)
1856 DBPATCH_ADD(2010067, 0, 1)
1857 DBPATCH_ADD(2010068, 0, 1)
1858 DBPATCH_ADD(2010069, 0, 0)
1859 DBPATCH_ADD(2010070, 0, 0)
1860 DBPATCH_ADD(2010071, 0, 1)
1861 DBPATCH_ADD(2010072, 0, 1)
1862 DBPATCH_ADD(2010073, 0, 0)
1863 DBPATCH_ADD(2010074, 0, 1)
1864 DBPATCH_ADD(2010075, 0, 1)
1865 DBPATCH_ADD(2010076, 0, 1)
1866 DBPATCH_ADD(2010077, 0, 1)
1867 DBPATCH_ADD(2010078, 0, 1)
1868 DBPATCH_ADD(2010079, 0, 1)
1869 DBPATCH_ADD(2010080, 0, 1)
1870 DBPATCH_ADD(2010081, 0, 1)
1871 DBPATCH_ADD(2010082, 0, 1)
1872 DBPATCH_ADD(2010083, 0, 1)
1873 DBPATCH_ADD(2010084, 0, 1)
1874 DBPATCH_ADD(2010085, 0, 1)
1875 DBPATCH_ADD(2010086, 0, 1)
1876 DBPATCH_ADD(2010087, 0, 1)
1877 DBPATCH_ADD(2010088, 0, 1)
1878 DBPATCH_ADD(2010089, 0, 1)
1879 DBPATCH_ADD(2010090, 0, 1)
1880 DBPATCH_ADD(2010091, 0, 1)
1881 DBPATCH_ADD(2010092, 0, 1)
1882 DBPATCH_ADD(2010093, 0, 1)
1883 DBPATCH_ADD(2010094, 0, 1)
1884 DBPATCH_ADD(2010098, 0, 0)
1885 DBPATCH_ADD(2010099, 0, 0)
1886 DBPATCH_ADD(2010100, 0, 0)
1887 DBPATCH_ADD(2010101, 0, 1)
1888 DBPATCH_ADD(2010102, 0, 0)
1889 DBPATCH_ADD(2010103, 0, 0)
1890 DBPATCH_ADD(2010104, 0, 0)
1891 DBPATCH_ADD(2010105, 0, 0)
1892 DBPATCH_ADD(2010106, 0, 0)
1893 DBPATCH_ADD(2010107, 0, 0)
1894 DBPATCH_ADD(2010108, 0, 0)
1895 DBPATCH_ADD(2010109, 0, 0)
1896 DBPATCH_ADD(2010110, 0, 0)
1897 DBPATCH_ADD(2010111, 0, 0)
1898 DBPATCH_ADD(2010112, 0, 0)
1899 DBPATCH_ADD(2010113, 0, 0)
1900 DBPATCH_ADD(2010114, 0, 0)
1901 DBPATCH_ADD(2010115, 0, 0)
1902 DBPATCH_ADD(2010116, 0, 0)
1903 DBPATCH_ADD(2010117, 0, 0)
1904 DBPATCH_ADD(2010118, 0, 0)
1905 DBPATCH_ADD(2010119, 0, 0)
1906 DBPATCH_ADD(2010120, 0, 0)
1907 DBPATCH_ADD(2010121, 0, 0)
1908 DBPATCH_ADD(2010122, 0, 0)
1909 DBPATCH_ADD(2010123, 0, 0)
1910 DBPATCH_ADD(2010124, 0, 0)
1911 DBPATCH_ADD(2010125, 0, 0)
1912 DBPATCH_ADD(2010126, 0, 0)
1913 DBPATCH_ADD(2010127, 0, 0)
1914 DBPATCH_ADD(2010128, 0, 0)
1915 DBPATCH_ADD(2010129, 0, 0)
1916 DBPATCH_ADD(2010130, 0, 0)
1917 DBPATCH_ADD(2010131, 0, 0)
1918 DBPATCH_ADD(2010132, 0, 0)
1919 DBPATCH_ADD(2010133, 0, 0)
1920 DBPATCH_ADD(2010134, 0, 0)
1921 DBPATCH_ADD(2010135, 0, 0)
1922 DBPATCH_ADD(2010136, 0, 0)
1923 DBPATCH_ADD(2010137, 0, 0)
1924 DBPATCH_ADD(2010138, 0, 0)
1925 DBPATCH_ADD(2010139, 0, 0)
1926 DBPATCH_ADD(2010140, 0, 0)
1927 DBPATCH_ADD(2010141, 0, 0)
1928 DBPATCH_ADD(2010142, 0, 0)
1929 DBPATCH_ADD(2010143, 0, 0)
1930 DBPATCH_ADD(2010144, 0, 0)
1931 DBPATCH_ADD(2010145, 0, 0)
1932 DBPATCH_ADD(2010146, 0, 0)
1933 DBPATCH_ADD(2010147, 0, 0)
1934 DBPATCH_ADD(2010148, 0, 0)
1935 DBPATCH_ADD(2010149, 0, 0)
1936 DBPATCH_ADD(2010150, 0, 0)
1937 DBPATCH_ADD(2010151, 0, 0)
1938 DBPATCH_ADD(2010152, 0, 0)
1939 DBPATCH_ADD(2010153, 0, 0)
1940 DBPATCH_ADD(2010154, 0, 0)
1941 DBPATCH_ADD(2010155, 0, 0)
1942 DBPATCH_ADD(2010156, 0, 0)
1943 DBPATCH_ADD(2010157, 0, 1)
1944 DBPATCH_ADD(2010158, 0, 1)
1945 DBPATCH_ADD(2010159, 0, 1)
1946 DBPATCH_ADD(2010160, 0, 1)
1947 DBPATCH_ADD(2010161, 0, 1)
1948 DBPATCH_ADD(2010162, 0, 1)
1949 DBPATCH_ADD(2010163, 0, 1)
1950 DBPATCH_ADD(2010164, 0, 1)
1951 DBPATCH_ADD(2010165, 0, 1)
1952 DBPATCH_ADD(2010166, 0, 1)
1953 DBPATCH_ADD(2010167, 0, 1)
1954 DBPATCH_ADD(2010168, 0, 1)
1955 DBPATCH_ADD(2010169, 0, 1)
1956 DBPATCH_ADD(2010170, 0, 1)
1957 DBPATCH_ADD(2010171, 0, 1)
1958 DBPATCH_ADD(2010172, 0, 1)
1959 DBPATCH_ADD(2010173, 0, 1)
1960 DBPATCH_ADD(2010174, 0, 1)
1961 DBPATCH_ADD(2010175, 0, 1)
1962 DBPATCH_ADD(2010176, 0, 1)
1963 DBPATCH_ADD(2010177, 0, 1)
1964 DBPATCH_ADD(2010178, 0, 1)
1965 DBPATCH_ADD(2010179, 0, 1)
1966 DBPATCH_ADD(2010180, 0, 1)
1967 DBPATCH_ADD(2010181, 0, 1)
1968 DBPATCH_ADD(2010182, 0, 1)
1969 DBPATCH_ADD(2010183, 0, 1)
1970 DBPATCH_ADD(2010184, 0, 1)
1971 DBPATCH_ADD(2010185, 0, 1)
1972 DBPATCH_ADD(2010186, 0, 1)
1973 DBPATCH_ADD(2010187, 0, 1)
1974 DBPATCH_ADD(2010188, 0, 1)
1975 DBPATCH_ADD(2010189, 0, 1)
1976 DBPATCH_ADD(2010190, 0, 1)
1977 DBPATCH_ADD(2010191, 0, 1)
1978 DBPATCH_ADD(2010192, 0, 0)
1979 DBPATCH_ADD(2010193, 0, 0)
1980 DBPATCH_ADD(2010194, 0, 1)
1981 DBPATCH_ADD(2010195, 0, 1)
1982 DBPATCH_ADD(2010196, 0, 1)
1983 DBPATCH_ADD(2010197, 0, 1)
1984 DBPATCH_ADD(2010198, 0, 1)
1985 DBPATCH_ADD(2010199, 0, 1)
1986 
1987 DBPATCH_END()
1988