#include "dbupgrade.h"
#include "zbxnum.h"
#include "zbxdbhigh.h"
#ifndef HAVE_SQLITE3
int DBpatch_3020001(void);
static int DBpatch_3020000(void)
{
return SUCCEED;
}
int DBpatch_3020001(void)
{
DB_RESULT result;
zbx_vector_uint64_t eventids;
DB_ROW row;
zbx_uint64_t eventid;
int sources[] = {EVENT_SOURCE_TRIGGERS, EVENT_SOURCE_INTERNAL};
int objects[] = {EVENT_OBJECT_ITEM, EVENT_OBJECT_LLDRULE}, i;
zbx_vector_uint64_create(&eventids);
for (i = 0; i < (int)ARRSIZE(sources); i++)
{
result = zbx_db_select(
"select p.eventid"
" from problem p"
" where p.source=%d and p.object=%d and not exists ("
"select null"
" from triggers t"
" where t.triggerid=p.objectid"
")",
sources[i], EVENT_OBJECT_TRIGGER);
while (NULL != (row = zbx_db_fetch(result)))
{
ZBX_STR2UINT64(eventid, row[0]);
zbx_vector_uint64_append(&eventids, eventid);
}
zbx_db_free_result(result);
}
for (i = 0; i < (int)ARRSIZE(objects); i++)
{
result = zbx_db_select(
"select p.eventid"
" from problem p"
" where p.source=%d and p.object=%d and not exists ("
"select null"
" from items i"
" where i.itemid=p.objectid"
")",
EVENT_SOURCE_INTERNAL, objects[i]);
while (NULL != (row = zbx_db_fetch(result)))
{
ZBX_STR2UINT64(eventid, row[0]);
zbx_vector_uint64_append(&eventids, eventid);
}
zbx_db_free_result(result);
}
zbx_vector_uint64_sort(&eventids, ZBX_DEFAULT_UINT64_COMPARE_FUNC);
if (0 != eventids.values_num)