error_report("Error %d while closing the SQLite database, %s", rc, sqlite3_errstr(rc));
return;
}
#defineFIND_UUID_TYPE "select 1 from host where host_id = @uuid union select 2 from chart where chart_id = @uuid union select 3 from dimension where dim_id = @uuid;"
error_report("Failed to bind host parameter to %s, rc = %d", sql, rc);
goto failed;
}
rc=execute_insert(res);
if (likely(rc==SQLITE_DONE))
result=0;
else
error_report("Failed to execute %s, rc = %d", sql, rc);
failed:
rc=sqlite3_finalize(res);
if (unlikely(rc!=SQLITE_OK))
error_report("Failed to finalize statement %s, rc = %d", sql, rc);
returnresult;
}
// Migrate all hosts with hops zero to this host_uuid
voidmigrate_localhost(uuid_t*host_uuid)
{
intrc;
rc=exec_statement_with_uuid("UPDATE chart SET host_id = @host_id WHERE host_id in (SELECT host_id FROM host where host_id <> @host_id and hops = 0); ", host_uuid);
if (!rc)
rc=exec_statement_with_uuid("DELETE FROM host WHERE hops = 0 AND host_id <> @host_id; ", host_uuid);
if (!rc)
db_execute("DELETE FROM node_instance WHERE host_id NOT IN (SELECT host_id FROM host);");