Icinga-core 1.4.0
next gen monitoring
module/idoutils/src/dbqueries.c
Go to the documentation of this file.
00001 /***************************************************************
00002  * DBQUERIES.C - Data Query handler routines for IDO2DB daemon
00003  *
00004  * Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org)
00005  *
00006  **************************************************************/
00007 
00008 /* include our project's header files */
00009 #include "../../../include/config.h"
00010 #include "../include/common.h"
00011 #include "../include/io.h"
00012 #include "../include/utils.h"
00013 #include "../include/protoapi.h"
00014 #include "../include/ido2db.h"
00015 #include "../include/db.h"
00016 #include "../include/dbqueries.h"
00017 
00018 /* Icinga header files */
00019 #include "../../../include/icinga.h"
00020 #include "../../../include/broker.h"
00021 #include "../../../include/comments.h"
00022 
00023 extern int errno;
00024 
00025 extern char *ido2db_db_tablenames[IDO2DB_MAX_DBTABLES];
00026 
00027 int dummy;      /* reduce compiler warnings */
00028 
00029 /****************************************************************************/
00030 /* INSERT QUERIES                                                           */
00031 /****************************************************************************/
00032 
00033 /****************************************************************************/
00034 /* DELETE QUERIES                                                           */
00035 /****************************************************************************/
00036 
00037 /****************************************************************************/
00038 /* INSERT/UPDATE/MERGE QUERIES                                              */
00039 /****************************************************************************/
00040 
00041 /************************************/
00042 /* TIMEDEVENTS                      */
00043 /************************************/
00044 
00045 int ido2db_query_insert_or_update_timedevent_add(ido2db_idi *idi, void **data) {
00046         int result = IDO_OK;
00047 #ifdef USE_LIBDBI
00048         char * query1 = NULL;
00049         char * query2 = NULL;
00050 #endif
00051 
00052         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_timedevents_add() start\n");
00053 
00054         if (idi == NULL)
00055                 return IDO_ERROR;
00056 
00057         if (idi->dbinfo.connected == IDO_FALSE)
00058                 return IDO_ERROR;
00059 
00060 #ifdef USE_LIBDBI /* everything else will be libdbi */
00061         switch (idi->dbinfo.server_type) {
00062                 case IDO2DB_DBSERVER_MYSQL:
00063                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, event_type, queued_time, queued_time_usec, scheduled_time, recurring_event, object_id) VALUES (%lu, %d, %s, %lu, %s, %d, %lu) ON DUPLICATE KEY UPDATE queued_time=%s, queued_time_usec=%lu, recurring_event=%d", 
00064                                         ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTS],
00065                                         *(unsigned long *) data[0],     /* insert start */
00066                                         *(int *) data[1],
00067                                         *(char **) data[2],
00068                                         *(unsigned long *) data[3],
00069                                         *(char **) data[4],
00070                                         *(int *) data[5],
00071                                         *(unsigned long *) data[6],     /* insert end */
00072                                         *(char **) data[2],             /* update start */
00073                                         *(unsigned long *) data[3],
00074                                         *(int *) data[5]                /* update end */
00075                         );
00076                         /* send query to db */
00077                         result = ido2db_db_query(idi, query1);  
00078                         free(query1);
00079                         break;
00080                 case IDO2DB_DBSERVER_PGSQL:
00081                         dummy=asprintf(&query1, "UPDATE %s SET queued_time=%s, queued_time_usec=%lu, recurring_event=%d WHERE instance_id=%lu AND event_type=%d AND scheduled_time=%s AND object_id=%lu",
00082                                         ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTS],
00083                                         *(char **) data[2],             /* update start */
00084                                         *(unsigned long *) data[3],
00085                                         *(int *) data[5],               /* update end */
00086                                         *(unsigned long *) data[0],     /* unique constraint start */
00087                                         *(int *) data[1],
00088                                         *(char **) data[4],
00089                                         *(unsigned long *) data[6]      /* unique constraint end */
00090                         );
00091 
00092                         /* send query to db */
00093                         result = ido2db_db_query(idi, query1);          
00094                         free(query1);
00095 
00096                         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_timedevents_add(%lu) update rows matched\n", (dbi_result_get_numrows_affected(idi->dbinfo.dbi_result)));
00097                         /* check result if update was ok */
00098                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) { 
00099                                 /* try insert instead */
00100                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, event_type, queued_time, queued_time_usec, scheduled_time, recurring_event, object_id) VALUES ('%lu', '%d', %s, '%lu', %s, '%d', '%lu')",
00101                                         ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTS],
00102                                         *(unsigned long *) data[0],     /* insert start */
00103                                         *(int *) data[1],
00104                                         *(char **) data[2],
00105                                         *(unsigned long *) data[3],
00106                                         *(char **) data[4],
00107                                         *(int *) data[5],
00108                                         *(unsigned long *) data[6]     /* insert end */
00109                                 );
00110                                 /* send query to db */
00111                                 result = ido2db_db_query(idi, query2);
00112                                 free(query2);
00113                         }               
00114                         break;
00115                 case IDO2DB_DBSERVER_DB2:
00116                         break;
00117                 case IDO2DB_DBSERVER_FIREBIRD:
00118                         break;
00119                 case IDO2DB_DBSERVER_FREETDS:
00120                         break;
00121                 case IDO2DB_DBSERVER_INGRES:
00122                         break;
00123                 case IDO2DB_DBSERVER_MSQL:
00124                         break;
00125                 case IDO2DB_DBSERVER_ORACLE:
00126                         break;
00127                 case IDO2DB_DBSERVER_SQLITE:
00128                         break;
00129                 case IDO2DB_DBSERVER_SQLITE3:
00130                         break;
00131                 default:
00132                         break;
00133         }
00134 #endif
00135 
00136 #ifdef USE_PGSQL /* pgsql */
00137 
00138 #endif
00139 
00140 #ifdef USE_ORACLE /* Oracle ocilib specific */
00141 
00142         /* check if we lost connection, and reconnect */
00143         if(ido2db_db_reconnect(idi)==IDO_ERROR)
00144                 return IDO_ERROR;
00145 
00146                         /* bind params to prepared statement */
00147                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedevents_queue, MT(":X1"), (big_uint *) data[0])) {
00148                                 return IDO_ERROR;
00149                         }
00150                         if(!OCI_BindInt(idi->dbinfo.oci_statement_timedevents_queue, MT(":X2"), (int *) data[1])) {
00151                                 return IDO_ERROR;
00152                         }
00153                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedevents_queue, MT(":X3"), (big_uint *) data[7])) { /* unixtimestamp instead of time2sql */
00154                                 return IDO_ERROR;
00155                         }
00156                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedevents_queue, MT(":X4"), (big_uint *) data[3])) {
00157                                 return IDO_ERROR;
00158                         }
00159                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedevents_queue, MT(":X5"), (big_uint *) data[8])) { /* unixtimestamp instead of time2sql */
00160                                 return IDO_ERROR;
00161                         }
00162                         if(!OCI_BindInt(idi->dbinfo.oci_statement_timedevents_queue, MT(":X6"), (int *) data[5])) {
00163                                 return IDO_ERROR;
00164                         }
00165                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedevents_queue, MT(":X7"), (big_uint *) data[6])) {
00166                                 return IDO_ERROR;
00167                         }
00168 
00169                         /* execute statement */
00170                         if(!OCI_Execute(idi->dbinfo.oci_statement_timedevents_queue)) {
00171                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_timedevents_add() execute error\n");
00172                                 return IDO_ERROR;
00173                         }
00174 
00175                         /* commit statement */
00176                         OCI_Commit(idi->dbinfo.oci_connection);
00177 
00178                         /* do not free statement yet! */
00179 #endif
00180         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_timedevents_add() end\n"); 
00181 
00182         return result;
00183 }
00184 
00185 int ido2db_query_insert_or_update_timedeventqueue_add(ido2db_idi *idi, void **data) {
00186         int result = IDO_OK;
00187 #ifdef USE_LIBDBI
00188         char * query1 = NULL;
00189         char * query2 = NULL;
00190 #endif
00191         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_timedeventqueue_add() start\n");
00192 
00193         if (idi == NULL)
00194                 return IDO_ERROR;
00195 
00196         if (idi->dbinfo.connected == IDO_FALSE)
00197                 return IDO_ERROR;
00198 
00199 #ifdef USE_LIBDBI /* everything else will be libdbi */
00200         switch (idi->dbinfo.server_type) {
00201                 case IDO2DB_DBSERVER_MYSQL:
00202                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, event_type, queued_time, queued_time_usec, scheduled_time, recurring_event, object_id) VALUES (%lu, %d, %s, %lu, %s, %d, %lu) ON DUPLICATE KEY UPDATE queued_time=%s, queued_time_usec=%lu, recurring_event=%d", 
00203                                         ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTQUEUE],
00204                                         *(unsigned long *) data[0],     /* insert start */
00205                                         *(int *) data[1],
00206                                         *(char **) data[2],
00207                                         *(unsigned long *) data[3],
00208                                         *(char **) data[4],
00209                                         *(int *) data[5],
00210                                         *(unsigned long *) data[6],     /* insert end */
00211                                         *(char **) data[2],             /* update start */
00212                                         *(unsigned long *) data[3],
00213                                         *(int *) data[5]                /* update end */
00214                         );
00215                         /* send query to db */
00216                         result = ido2db_db_query(idi, query1);  
00217                         free(query1);
00218                         break;
00219                 case IDO2DB_DBSERVER_PGSQL:
00220                         dummy=asprintf(&query1, "UPDATE %s SET queued_time=%s, queued_time_usec=%lu, recurring_event=%d WHERE instance_id=%lu AND event_type=%d AND scheduled_time=%s AND object_id=%lu",
00221                                         ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTQUEUE],
00222                                         *(char **) data[2],             /* update start */
00223                                         *(unsigned long *) data[3],
00224                                         *(int *) data[5],               /* update end */
00225                                         *(unsigned long *) data[0],     /* unique constraint start */
00226                                         *(int *) data[1],
00227                                         *(char **) data[4],
00228                                         *(unsigned long *) data[6]      /* unique constraint end */
00229                         );
00230 
00231                         /* send query to db */
00232                         result = ido2db_db_query(idi, query1);          
00233                         free(query1);
00234 
00235                         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_timedeventqueue_add(%lu) update rows matched\n", (dbi_result_get_numrows_affected(idi->dbinfo.dbi_result)));
00236                         /* check result if update was ok */
00237                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) { 
00238                                 /* try insert instead */
00239                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, event_type, queued_time, queued_time_usec, scheduled_time, recurring_event, object_id) VALUES ('%lu', '%d', %s, '%lu', %s, '%d', '%lu')",
00240                                         ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTQUEUE],
00241                                         *(unsigned long *) data[0],     /* insert start */
00242                                         *(int *) data[1],
00243                                         *(char **) data[2],
00244                                         *(unsigned long *) data[3],
00245                                         *(char **) data[4],
00246                                         *(int *) data[5],
00247                                         *(unsigned long *) data[6]     /* insert end */
00248                                 );
00249                                 /* send query to db */
00250                                 result = ido2db_db_query(idi, query2);
00251                                 free(query2);
00252                         }               
00253                         break;
00254                 case IDO2DB_DBSERVER_DB2:
00255                         break;
00256                 case IDO2DB_DBSERVER_FIREBIRD:
00257                         break;
00258                 case IDO2DB_DBSERVER_FREETDS:
00259                         break;
00260                 case IDO2DB_DBSERVER_INGRES:
00261                         break;
00262                 case IDO2DB_DBSERVER_MSQL:
00263                         break;
00264                 case IDO2DB_DBSERVER_ORACLE:
00265                         break;
00266                 case IDO2DB_DBSERVER_SQLITE:
00267                         break;
00268                 case IDO2DB_DBSERVER_SQLITE3:
00269                         break;
00270                 default:
00271                         break;
00272         }
00273 #endif
00274 
00275 #ifdef USE_PGSQL /* pgsql */
00276 
00277 #endif
00278 
00279 #ifdef USE_ORACLE /* Oracle ocilib specific */
00280 
00281         /* check if we lost connection, and reconnect */
00282         if(ido2db_db_reconnect(idi)==IDO_ERROR)
00283                 return IDO_ERROR;
00284 
00285                         /* bind params to prepared statement */
00286                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedeventqueue, MT(":X1"), (big_uint *) data[0])) {
00287                                 return IDO_ERROR;
00288                         }
00289                         if(!OCI_BindInt(idi->dbinfo.oci_statement_timedeventqueue, MT(":X2"), (int *) data[1])) {
00290                                 return IDO_ERROR;
00291                         }
00292                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedeventqueue, MT(":X3"), (big_uint *) data[7])) { /* unixtimestamp instead of time2sql */
00293                                 return IDO_ERROR;
00294                         }
00295                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedeventqueue, MT(":X4"), (big_uint *) data[3])) {
00296                                 return IDO_ERROR;
00297                         }
00298                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedeventqueue, MT(":X5"), (big_uint *) data[8])) { /* unixtimestamp instead of time2sql */
00299                                 return IDO_ERROR;
00300                         }
00301                         if(!OCI_BindInt(idi->dbinfo.oci_statement_timedeventqueue, MT(":X6"), (int *) data[5])) {
00302                                 return IDO_ERROR;
00303                         }
00304                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedeventqueue, MT(":X7"), (big_uint *) data[6])) {
00305                                 return IDO_ERROR;
00306                         }
00307 
00308                         /* execute statement */
00309                         if(!OCI_Execute(idi->dbinfo.oci_statement_timedeventqueue)) {
00310                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_timedeventqueue_add() execute error\n");
00311                                 return IDO_ERROR;
00312                         }
00313 
00314                         /* commit statement */
00315                         OCI_Commit(idi->dbinfo.oci_connection);
00316 
00317                         /* do not free statement yet! */
00318 #endif
00319         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_timedeventqueue_add() end\n"); 
00320 
00321         return result;
00322 }
00323 
00324 int ido2db_query_insert_or_update_timedevents_execute_add(ido2db_idi *idi, void **data) {
00325         int result = IDO_OK;
00326 #ifdef USE_LIBDBI
00327         char * query1 = NULL;
00328         char * query2 = NULL;
00329 #endif
00330         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_timedevents_execute() start\n");
00331 
00332         if (idi == NULL)
00333                 return IDO_ERROR;
00334 
00335         if (idi->dbinfo.connected == IDO_FALSE)
00336                 return IDO_ERROR;
00337 
00338 #ifdef USE_LIBDBI /* everything else will be libdbi */
00339         switch (idi->dbinfo.server_type) {
00340                 case IDO2DB_DBSERVER_MYSQL:
00341                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, event_type, event_time, event_time_usec, scheduled_time, recurring_event, object_id) VALUES (%lu, %d, %s, %lu, %s, %d, %lu) ON DUPLICATE KEY UPDATE event_time=%s, event_time_usec=%lu, recurring_event=%d",
00342                                         ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTS],
00343                                         *(unsigned long *) data[0],     /* insert start */
00344                                         *(int *) data[1],
00345                                         *(char **) data[2],
00346                                         *(unsigned long *) data[3],
00347                                         *(char **) data[4],
00348                                         *(int *) data[5],
00349                                         *(unsigned long *) data[6],     /* insert end */
00350                                         *(char **) data[2],             /* update start */
00351                                         *(unsigned long *) data[3],
00352                                         *(int *) data[5]                /* update end */
00353                         );
00354                         /* send query to db */
00355                         result = ido2db_db_query(idi, query1);
00356                         free(query1);
00357                         break;
00358                 case IDO2DB_DBSERVER_PGSQL:
00359                         dummy=asprintf(&query1, "UPDATE %s SET event_time=%s, event_time_usec=%lu, recurring_event=%d WHERE instance_id=%lu AND event_type=%d AND scheduled_time=%s AND object_id=%lu",
00360                                         ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTS],
00361                                         *(char **) data[2],             /* update start */
00362                                         *(unsigned long *) data[3],
00363                                         *(int *) data[5],               /* update end */
00364                                         *(unsigned long *) data[0],     /* unique constraint start */
00365                                         *(int *) data[1],
00366                                         *(char **) data[4],
00367                                         *(unsigned long *) data[6]      /* unique constraint end */
00368                         );
00369                         /* send query to db */
00370                         result = ido2db_db_query(idi, query1);
00371                         free(query1);
00372 
00373                         /* check result if update was ok */
00374                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
00375                                 /* try insert instead */
00376                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, event_type, event_time, event_time_usec, scheduled_time, recurring_event, object_id) VALUES ('%lu', '%d', %s, '%lu', %s, '%d', '%lu')",
00377                                         ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEDEVENTS],
00378                                         *(unsigned long *) data[0],     /* insert start */
00379                                         *(int *) data[1],
00380                                         *(char **) data[2],
00381                                         *(unsigned long *) data[3],
00382                                         *(char **) data[4],
00383                                         *(int *) data[5],
00384                                         *(unsigned long *) data[6]     /* insert end */
00385                                 );
00386                                 /* send query to db */
00387                                 result = ido2db_db_query(idi, query2);
00388                                 free(query2);
00389                         }
00390                         break;
00391                 case IDO2DB_DBSERVER_DB2:
00392                         break;
00393                 case IDO2DB_DBSERVER_FIREBIRD:
00394                         break;
00395                 case IDO2DB_DBSERVER_FREETDS:
00396                         break;
00397                 case IDO2DB_DBSERVER_INGRES:
00398                         break;
00399                 case IDO2DB_DBSERVER_MSQL:
00400                         break;
00401                 case IDO2DB_DBSERVER_ORACLE:
00402                         break;
00403                 case IDO2DB_DBSERVER_SQLITE:
00404                         break;
00405                 case IDO2DB_DBSERVER_SQLITE3:
00406                         break;
00407                 default:
00408                         break;
00409         }
00410 #endif
00411 
00412 #ifdef USE_PGSQL /* pgsql */
00413 
00414 #endif
00415 
00416 #ifdef USE_ORACLE /* Oracle ocilib specific */
00417 
00418         /* check if we lost connection, and reconnect */
00419         if(ido2db_db_reconnect(idi)==IDO_ERROR)
00420                 return IDO_ERROR;
00421 
00422                         /* bind params to prepared statement */
00423                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedevents, MT(":X1"), (big_uint *) data[0])) {
00424                                 return IDO_ERROR;
00425                         }
00426                         if(!OCI_BindInt(idi->dbinfo.oci_statement_timedevents, MT(":X2"), (int *) data[1])) {
00427                                 return IDO_ERROR;
00428                         }
00429                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedevents, MT(":X3"), (big_uint *) data[7])) { /* unixtimestamp instead of time2sql */
00430                                 return IDO_ERROR;
00431                         }
00432                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedevents, MT(":X4"), (big_uint *) data[3])) {
00433                                 return IDO_ERROR;
00434                         }
00435                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedevents, MT(":X5"), (big_uint *) data[8])) { /* unixtimestamp instead of time2sql */
00436                                 return IDO_ERROR;
00437                         }
00438                         if(!OCI_BindInt(idi->dbinfo.oci_statement_timedevents, MT(":X6"), (int *) data[5])) {
00439                                 return IDO_ERROR;
00440                         }
00441                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timedevents, MT(":X7"), (big_uint *) data[6])) {
00442                                 return IDO_ERROR;
00443                         }
00444 
00445                         /* execute statement */
00446                         if(!OCI_Execute(idi->dbinfo.oci_statement_timedevents)) {
00447                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_timedevents_execute() execute error\n");
00448                                 return IDO_ERROR;
00449                         }
00450 
00451                         /* commit statement */
00452                         OCI_Commit(idi->dbinfo.oci_connection);
00453 
00454                         /* do not free statement yet! */
00455 #endif
00456         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_timedevents_execute() end\n");
00457 
00458         return result;
00459 }
00460 
00461 
00462 /************************************/
00463 /* SYSTEMCOMMANDDATA                */
00464 /************************************/
00465 
00466 int ido2db_query_insert_or_update_systemcommanddata_add(ido2db_idi *idi, void **data) {
00467         int result = IDO_OK;
00468 #ifdef USE_LIBDBI
00469         char * query1 = NULL;
00470         char * query2 = NULL;
00471 #endif
00472         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_systemcommanddata_add() start\n");
00473 
00474         if (idi == NULL)
00475                 return IDO_ERROR;
00476 
00477         if (idi->dbinfo.connected == IDO_FALSE)
00478                 return IDO_ERROR;
00479 
00480 #ifdef USE_LIBDBI /* everything else will be libdbi */
00481         switch (idi->dbinfo.server_type) {
00482                 case IDO2DB_DBSERVER_MYSQL:
00483                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, start_time, start_time_usec, end_time, end_time_usec, command_line, timeout, early_timeout, execution_time, return_code, output, long_output) VALUES (%lu, %s, %lu, %s, %lu, '%s', %d, %d, %lf, %d, '%s', '%s') ON DUPLICATE KEY UPDATE end_time=%s, end_time_usec=%lu, command_line='%s', timeout=%d, early_timeout=%d, execution_time=%lf, return_code=%d, output='%s', long_output='%s'",
00484                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SYSTEMCOMMANDS],
00485                                         *(unsigned long *) data[0],     /* insert start */
00486                                         *(char **) data[1],
00487                                         *(unsigned long*) data[2],
00488                                         *(char **) data[3],
00489                                         *(unsigned long *) data[4],
00490                                         *(char **) data[5],
00491                                         *(int *) data[6],
00492                                         *(int *) data[7],
00493                                         *(double *) data[8],
00494                                         *(int *) data[9],
00495                                         *(char **) data[10],
00496                                         *(char **) data[11],            /* insert end */
00497                                         *(char **) data[3],             /* update start */
00498                                         *(unsigned long *) data[4],
00499                                         *(char **) data[5],
00500                                         *(int *) data[6],
00501                                         *(int *) data[7],
00502                                         *(double *) data[8],
00503                                         *(int *) data[9],
00504                                         *(char **) data[10],
00505                                         *(char **) data[11]             /* update end */
00506                         );
00507                         /* send query to db */
00508                         result = ido2db_db_query(idi, query1);
00509                         free(query1);
00510                         break;
00511                 case IDO2DB_DBSERVER_PGSQL:
00512                         dummy=asprintf(&query1, "UPDATE %s SET end_time=%s, end_time_usec=%lu, command_line='%s', timeout=%d, early_timeout=%d, execution_time=%lf, return_code=%d, output='%s', long_output='%s' WHERE instance_id=%lu AND start_time=%s AND start_time_usec=%lu",
00513                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SYSTEMCOMMANDS],
00514                                         *(char **) data[3],             /* update start */
00515                                         *(unsigned long *) data[4],
00516                                         *(char **) data[5],
00517                                         *(int *) data[6],
00518                                         *(int *) data[7],
00519                                         *(double *) data[8],
00520                                         *(int *) data[9],
00521                                         *(char **) data[10],
00522                                         *(char **) data[11],             /* update end */
00523                                         *(unsigned long *) data[0],     /* unique constraint start */
00524                                         *(char **) data[1],
00525                                         *(unsigned long *) data[2]      /* unique constraint end */
00526                         );
00527                         /* send query to db */
00528                         result = ido2db_db_query(idi, query1);
00529                         free(query1);
00530 
00531                         /* check result if update was ok */
00532                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
00533                                 /* try insert instead */
00534                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, start_time, start_time_usec, end_time, end_time_usec, command_line, timeout, early_timeout, execution_time, return_code, output, long_output) VALUES (%lu, %s, %lu, %s, %lu, '%s', %d, %d, %lf, %d, '%s', '%s')",
00535                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SYSTEMCOMMANDS],
00536                                         *(unsigned long *) data[0],     /* insert start */
00537                                         *(char **) data[1],
00538                                         *(unsigned long*) data[2],
00539                                         *(char **) data[3],
00540                                         *(unsigned long *) data[4],
00541                                         *(char **) data[5],
00542                                         *(int *) data[6],
00543                                         *(int *) data[7],
00544                                         *(double *) data[8],
00545                                         *(int *) data[9],
00546                                         *(char **) data[10],
00547                                         *(char **) data[11]            /* insert end */
00548                                 );
00549                                 /* send query to db */
00550                                 result = ido2db_db_query(idi, query2);
00551                                 free(query2);
00552                         }
00553                         break;
00554                 case IDO2DB_DBSERVER_DB2:
00555                         break;
00556                 case IDO2DB_DBSERVER_FIREBIRD:
00557                         break;
00558                 case IDO2DB_DBSERVER_FREETDS:
00559                         break;
00560                 case IDO2DB_DBSERVER_INGRES:
00561                         break;
00562                 case IDO2DB_DBSERVER_MSQL:
00563                         break;
00564                 case IDO2DB_DBSERVER_ORACLE:
00565                         break;
00566                 case IDO2DB_DBSERVER_SQLITE:
00567                         break;
00568                 case IDO2DB_DBSERVER_SQLITE3:
00569                         break;
00570                 default:
00571                         break;
00572         }
00573 #endif
00574 
00575 #ifdef USE_PGSQL /* pgsql */
00576 
00577 #endif
00578 
00579 #ifdef USE_ORACLE /* Oracle ocilib specific */
00580 
00581         /* check if we lost connection, and reconnect */
00582         if(ido2db_db_reconnect(idi)==IDO_ERROR)
00583                 return IDO_ERROR;
00584 
00585                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_systemcommanddata, MT(":X1"), (big_uint *) data[0])) {
00586                                 return IDO_ERROR;
00587                         }
00588                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_systemcommanddata, MT(":X2"), (big_uint *) data[12])) { /* unixtimestamp instead of time2sql */
00589                                 return IDO_ERROR;
00590                         }
00591                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_systemcommanddata, MT(":X3"), (big_uint *) data[2])) {
00592                                 return IDO_ERROR;
00593                         }
00594                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_systemcommanddata, MT(":X4"), (big_uint *) data[13])) { /* unixtimestamp instead of time2sql */
00595                                 return IDO_ERROR;
00596                         }
00597                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_systemcommanddata, MT(":X5"), (big_uint *) data[4])) {
00598                                 return IDO_ERROR;
00599                         }
00600         if(*(char **) data[5]==NULL) {
00601                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_systemcommanddata, ":X6")==IDO_ERROR) {
00602                         return IDO_ERROR;
00603                 }
00604         } else {
00605                         if(!OCI_BindString(idi->dbinfo.oci_statement_systemcommanddata, MT(":X6"), *(char **) data[5], 0)) {
00606                                 return IDO_ERROR;
00607                         }
00608         }
00609                         if(!OCI_BindInt(idi->dbinfo.oci_statement_systemcommanddata, MT(":X7"), (int *) data[6])) {
00610                                 return IDO_ERROR;
00611                         }
00612                         if(!OCI_BindInt(idi->dbinfo.oci_statement_systemcommanddata, MT(":X8"), (int *) data[7])) {
00613                                 return IDO_ERROR;
00614                         }
00615                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_systemcommanddata, MT(":X9"), (double *) data[8])) {
00616                                 return IDO_ERROR;
00617                         }
00618                         if(!OCI_BindInt(idi->dbinfo.oci_statement_systemcommanddata, MT(":X10"), (int *) data[9])) {
00619                                 return IDO_ERROR;
00620                         }
00621         if(*(char **) data[10]==NULL) {
00622                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_systemcommanddata, ":X11")==IDO_ERROR) {
00623                         return IDO_ERROR;
00624                 }
00625         } else {
00626                         if(!OCI_BindString(idi->dbinfo.oci_statement_systemcommanddata, MT(":X11"), *(char **) data[10], 0)) {
00627                                 return IDO_ERROR;
00628                         }
00629         }
00630         if(*(char **) data[11]==NULL) {
00631                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_systemcommanddata, ":X12")==IDO_ERROR) {
00632                         return IDO_ERROR;
00633                 }
00634         } else {
00635                         if(!OCI_BindString(idi->dbinfo.oci_statement_systemcommanddata, MT(":X12"), *(char **) data[11], 0)) {
00636                                 return IDO_ERROR;
00637                         }
00638         }
00639                         /* execute statement */
00640                         if(!OCI_Execute(idi->dbinfo.oci_statement_systemcommanddata)) {
00641                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_systemcommanddata() execute error\n");
00642                                 return IDO_ERROR;
00643                         }
00644 
00645                         /* commit statement */
00646                         OCI_Commit(idi->dbinfo.oci_connection);
00647 
00648                         /* do not free statement yet! */
00649 #endif
00650         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_systemcommanddata_add() end\n");
00651 
00652         return result;
00653 }
00654 
00655 
00656 /************************************/
00657 /* EVENTHANDLER                     */
00658 /************************************/
00659 
00660 int ido2db_query_insert_or_update_eventhandlerdata_add(ido2db_idi *idi, void **data) {
00661         int result = IDO_OK;
00662 #ifdef USE_LIBDBI
00663         char * query1 = NULL;
00664         char * query2 = NULL;
00665 #endif
00666         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_eventhandlerdata_add() start\n");
00667 
00668         if (idi == NULL)
00669                 return IDO_ERROR;
00670 
00671         if (idi->dbinfo.connected == IDO_FALSE)
00672                 return IDO_ERROR;
00673 
00674 #ifdef USE_LIBDBI /* everything else will be libdbi */
00675         switch (idi->dbinfo.server_type) {
00676                 case IDO2DB_DBSERVER_MYSQL:
00677                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, eventhandler_type, object_id, state, state_type, start_time, start_time_usec, end_time, end_time_usec, command_object_id, command_args, command_line, timeout, early_timeout, execution_time, return_code, output, long_output) VALUES (%lu, %d, %lu, %d, %d, %s, %lu, %s, %lu, %lu, '%s', '%s', %d, %d, %lf, %d, '%s', '%s') ON DUPLICATE KEY UPDATE eventhandler_type=%d, object_id=%lu, state=%d, state_type=%d, end_time=%s, end_time_usec=%lu, command_object_id=%lu, command_args='%s', command_line='%s', timeout=%d, early_timeout=%d, execution_time=%lf, return_code=%d, output='%s', long_output='%s'",
00678                                         ido2db_db_tablenames[IDO2DB_DBTABLE_EVENTHANDLERS],
00679                                         *(unsigned long *) data[0],     /* insert start */
00680                                         *(int *) data[1],
00681                                         *(unsigned long *) data[2],
00682                                         *(int *) data[3],
00683                                         *(int *) data[4],
00684                                         *(char **) data[5],
00685                                         *(unsigned long *) data[6],
00686                                         *(char **) data[7],
00687                                         *(unsigned long *) data[8],
00688                                         *(unsigned long *) data[9],
00689                                         *(char **) data[10],
00690                                         *(char **) data[11],
00691                                         *(int *) data[12],
00692                                         *(int *) data[13],
00693                                         *(double *) data[14],
00694                                         *(int *) data[15],
00695                                         *(char **) data[16],
00696                                         *(char **) data[17],            /* insert end */
00697                                         *(int *) data[1],               /* update start */
00698                                         *(unsigned long *) data[2],
00699                                         *(int *) data[3],
00700                                         *(int *) data[4],
00701                                         *(char **) data[7],
00702                                         *(unsigned long *) data[8],
00703                                         *(unsigned long *) data[9],
00704                                         *(char **) data[10],
00705                                         *(char **) data[11],
00706                                         *(int *) data[12],
00707                                         *(int *) data[13],
00708                                         *(double *) data[14],
00709                                         *(int *) data[15],
00710                                         *(char **) data[16],
00711                                         *(char **) data[17]            /* update end */
00712                         );
00713                         /* send query to db */
00714                         result = ido2db_db_query(idi, query1);
00715                         free(query1);
00716                         break;
00717                 case IDO2DB_DBSERVER_PGSQL:
00718                         dummy=asprintf(&query1, "UPDATE %s SET eventhandler_type=%d, object_id=%lu, state=%d, state_type=%d, end_time=%s, end_time_usec=%lu, command_object_id=%lu, command_args='%s', command_line='%s', timeout=%d, early_timeout=%d, execution_time=%lf, return_code=%d, output='%s', long_output='%s' WHERE instance_id=%lu AND start_time=%s AND start_time_usec=%lu",
00719                                         ido2db_db_tablenames[IDO2DB_DBTABLE_EVENTHANDLERS],
00720                                         *(int *) data[1],               /* update start */
00721                                         *(unsigned long *) data[2],
00722                                         *(int *) data[3],
00723                                         *(int *) data[4],
00724                                         *(char **) data[7],
00725                                         *(unsigned long *) data[8],
00726                                         *(unsigned long *) data[9],
00727                                         *(char **) data[10],
00728                                         *(char **) data[11],
00729                                         *(int *) data[12],
00730                                         *(int *) data[13],
00731                                         *(double *) data[14],
00732                                         *(int *) data[15],
00733                                         *(char **) data[16],
00734                                         *(char **) data[17],            /* update end */
00735                                         *(unsigned long *) data[0],     /* unique constraint start */
00736                                         *(char **) data[5],
00737                                         *(unsigned long *) data[6]      /* unique constraint end */
00738                         );
00739                         /* send query to db */
00740                         result = ido2db_db_query(idi, query1);
00741                         free(query1);
00742 
00743                         /* check result if update was ok */
00744                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
00745                                 /* try insert instead */
00746                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, eventhandler_type, object_id, state, state_type, start_time, start_time_usec, end_time, end_time_usec, command_object_id, command_args, command_line, timeout, early_timeout, execution_time, return_code, output, long_output) VALUES (%lu, %d, %lu, %d, %d, %s, %lu, %s, %lu, %lu, '%s', '%s', %d, %d, %lf, %d, '%s', '%s')",
00747                                         ido2db_db_tablenames[IDO2DB_DBTABLE_EVENTHANDLERS],
00748                                         *(unsigned long *) data[0],     /* insert start */
00749                                         *(int *) data[1],
00750                                         *(unsigned long *) data[2],
00751                                         *(int *) data[3],
00752                                         *(int *) data[4],
00753                                         *(char **) data[5],
00754                                         *(unsigned long *) data[6],
00755                                         *(char **) data[7],
00756                                         *(unsigned long *) data[8],
00757                                         *(unsigned long *) data[9],
00758                                         *(char **) data[10],
00759                                         *(char **) data[11],
00760                                         *(int *) data[12],
00761                                         *(int *) data[13],
00762                                         *(double *) data[14],
00763                                         *(int *) data[15],
00764                                         *(char **) data[16],
00765                                         *(char **) data[17]            /* insert end */
00766                                 );
00767                                 /* send query to db */
00768                                 result = ido2db_db_query(idi, query2);
00769                                 free(query2);
00770                         }
00771                         break;
00772                 case IDO2DB_DBSERVER_DB2:
00773                         break;
00774                 case IDO2DB_DBSERVER_FIREBIRD:
00775                         break;
00776                 case IDO2DB_DBSERVER_FREETDS:
00777                         break;
00778                 case IDO2DB_DBSERVER_INGRES:
00779                         break;
00780                 case IDO2DB_DBSERVER_MSQL:
00781                         break;
00782                 case IDO2DB_DBSERVER_ORACLE:
00783                         break;
00784                 case IDO2DB_DBSERVER_SQLITE:
00785                         break;
00786                 case IDO2DB_DBSERVER_SQLITE3:
00787                         break;
00788                 default:
00789                         break;
00790         }
00791 #endif
00792 
00793 #ifdef USE_PGSQL /* pgsql */
00794 
00795 #endif
00796 
00797 #ifdef USE_ORACLE /* Oracle ocilib specific */
00798 
00799         /* check if we lost connection, and reconnect */
00800         if(ido2db_db_reconnect(idi)==IDO_ERROR)
00801                 return IDO_ERROR;
00802 
00803                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_eventhandlerdata, MT(":X1"), (big_uint *) data[0])) {
00804                                 return IDO_ERROR;
00805                         }
00806                         if(!OCI_BindInt(idi->dbinfo.oci_statement_eventhandlerdata, MT(":X2"), (int *) data[1])) {
00807                                 return IDO_ERROR;
00808                         }
00809                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_eventhandlerdata, MT(":X3"), (big_uint *) data[2])) {
00810                                 return IDO_ERROR;
00811                         }
00812                         if(!OCI_BindInt(idi->dbinfo.oci_statement_eventhandlerdata, MT(":X4"), (int *) data[3])) {
00813                                 return IDO_ERROR;
00814                         }                        
00815                         if(!OCI_BindInt(idi->dbinfo.oci_statement_eventhandlerdata, MT(":X5"), (int *) data[4])) {
00816                                 return IDO_ERROR;
00817                         }
00818                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_eventhandlerdata, MT(":X6"), (big_uint *) data[18])) { /* unixtimestamp instead of time2sql */
00819                                 return IDO_ERROR;
00820                         }
00821                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_eventhandlerdata, MT(":X7"), (big_uint *) data[6])) {
00822                                 return IDO_ERROR;
00823                         }
00824                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_eventhandlerdata, MT(":X8"), (big_uint *) data[19])) { /* unixtimestamp instead of time2sql */
00825                                 return IDO_ERROR;
00826                         }
00827                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_eventhandlerdata, MT(":X9"), (big_uint *) data[8])) {
00828                                 return IDO_ERROR;
00829                         }
00830                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_eventhandlerdata, MT(":X10"), (big_uint *) data[9])) {
00831                                 return IDO_ERROR;
00832                         }
00833         if(*(char **) data[10]==NULL) {
00834                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_eventhandlerdata, ":X11")==IDO_ERROR) {
00835                         return IDO_ERROR;
00836                 }
00837         } else {
00838                         if(!OCI_BindString(idi->dbinfo.oci_statement_eventhandlerdata, MT(":X11"), *(char **) data[10], 0)) {
00839                                 return IDO_ERROR;
00840                         }
00841         }
00842         if(*(char **) data[11]==NULL) {
00843                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_eventhandlerdata, ":X12")==IDO_ERROR) {
00844                         return IDO_ERROR;
00845                 }
00846         } else {
00847                         if(!OCI_BindString(idi->dbinfo.oci_statement_eventhandlerdata, MT(":X12"), *(char **) data[11], 0)) {
00848                                 return IDO_ERROR;
00849                         }
00850         }
00851                         if(!OCI_BindInt(idi->dbinfo.oci_statement_eventhandlerdata, MT(":X13"), (int *) data[12])) {
00852                                 return IDO_ERROR;
00853                         }
00854                         if(!OCI_BindInt(idi->dbinfo.oci_statement_eventhandlerdata, MT(":X14"), (int *) data[13])) {
00855                                 return IDO_ERROR;
00856                         }
00857                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_eventhandlerdata, MT(":X15"), (double *) data[14])) {
00858                                 return IDO_ERROR;
00859                         }
00860                         if(!OCI_BindInt(idi->dbinfo.oci_statement_eventhandlerdata, MT(":X16"), (int *) data[15])) {
00861                                 return IDO_ERROR;
00862                         }
00863         if(*(char **) data[16]==NULL) {
00864                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_eventhandlerdata, ":X17")==IDO_ERROR) {
00865                         return IDO_ERROR;
00866                 }
00867         } else {
00868                         if(!OCI_BindString(idi->dbinfo.oci_statement_eventhandlerdata, MT(":X17"), *(char **) data[16], 0)) {
00869                                 return IDO_ERROR;
00870                         }
00871         }
00872         if(*(char **) data[17]==NULL) {
00873                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_eventhandlerdata, ":X18")==IDO_ERROR) {
00874                         return IDO_ERROR;
00875                 }
00876         } else {
00877                         if(!OCI_BindString(idi->dbinfo.oci_statement_eventhandlerdata, MT(":X18"), *(char **) data[17], 0)) {
00878                                 return IDO_ERROR;
00879                         }
00880         }
00881                         /* execute statement */
00882                         if(!OCI_Execute(idi->dbinfo.oci_statement_eventhandlerdata)) {
00883                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_() execute error\n");
00884                                 return IDO_ERROR;
00885                         }
00886 
00887                         /* commit statement */
00888                         OCI_Commit(idi->dbinfo.oci_connection);
00889 
00890                         /* do not free statement yet! */
00891 #endif
00892         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_eventhandlerdata_add() end\n");
00893 
00894         return result;
00895 }
00896 
00897 
00898 /************************************/
00899 /* NOTIFICATIONS                    */
00900 /************************************/
00901 
00902 int ido2db_query_insert_or_update_notificationdata_add(ido2db_idi *idi, void **data) {
00903         int result = IDO_OK;
00904 #ifdef USE_LIBDBI
00905         char * query1 = NULL;
00906         char * query2 = NULL;
00907 #endif
00908         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_notificationdata_add() start\n");
00909 
00910         if (idi == NULL)
00911                 return IDO_ERROR;
00912 
00913         if (idi->dbinfo.connected == IDO_FALSE)
00914                 return IDO_ERROR;
00915 
00916 #ifdef USE_LIBDBI /* everything else will be libdbi */
00917         switch (idi->dbinfo.server_type) {
00918                 case IDO2DB_DBSERVER_MYSQL:
00919                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, notification_type, notification_reason, start_time, start_time_usec, end_time, end_time_usec, object_id, state, output, long_output, escalated, contacts_notified) VALUES (%lu, %d, %d, %s, %lu, %s, %lu, %lu, %d, '%s', '%s', %d, %d) ON DUPLICATE KEY UPDATE notification_type=%d, notification_reason=%d, end_time=%s, end_time_usec=%lu, state=%d, output='%s', long_output='%s', escalated=%d, contacts_notified=%d",
00920                                         ido2db_db_tablenames[IDO2DB_DBTABLE_NOTIFICATIONS],
00921                                         *(unsigned long *) data[0],     /* insert start */
00922                                         *(int *) data[1],
00923                                         *(int *) data[2],
00924                                         *(char **) data[3],
00925                                         *(unsigned long *) data[4],
00926                                         *(char **) data[5],
00927                                         *(unsigned long *) data[6],    
00928                                         *(unsigned long *) data[7],     
00929                                         *(int *) data[8],     
00930                                         *(char **) data[9],     
00931                                         *(char **) data[10],     
00932                                         *(int *) data[11],     
00933                                         *(int *) data[12],              /* insert end */
00934                                         *(int *) data[1],               /* update start */
00935                                         *(int *) data[2],
00936                                         *(char **) data[5],
00937                                         *(unsigned long *) data[6],
00938                                         *(int *) data[8],
00939                                         *(char **) data[9],
00940                                         *(char **) data[10],
00941                                         *(int *) data[11],
00942                                         *(int *) data[12]               /* update end */
00943                         );
00944                         /* send query to db */
00945                         result = ido2db_db_query(idi, query1);
00946                         free(query1);
00947                         break;
00948                 case IDO2DB_DBSERVER_PGSQL:
00949                         dummy=asprintf(&query1, "UPDATE %s SET notification_type=%d, notification_reason=%d, end_time=%s, end_time_usec=%lu, state=%d, output='%s', long_output='%s', escalated=%d, contacts_notified=%d  WHERE instance_id=%lu AND start_time=%s AND start_time_usec=%lu AND object_id=%lu",
00950                                         ido2db_db_tablenames[IDO2DB_DBTABLE_NOTIFICATIONS],
00951                                         *(int *) data[1],               /* update start */
00952                                         *(int *) data[2],
00953                                         *(char **) data[5],
00954                                         *(unsigned long *) data[6],
00955                                         *(int *) data[8],
00956                                         *(char **) data[9],
00957                                         *(char **) data[10],
00958                                         *(int *) data[11],
00959                                         *(int *) data[12],               /* update end */
00960                                         *(unsigned long *) data[0],     /* unique constraint start */
00961                                         *(char **) data[3],
00962                                         *(unsigned long *) data[4],
00963                                         *(unsigned long *) data[7]      /* unique constraint end */
00964                         );
00965                         /* send query to db */
00966                         result = ido2db_db_query(idi, query1);
00967                         free(query1);
00968 
00969                         /* check result if update was ok */
00970                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
00971                                 /* try insert instead */
00972                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, notification_type, notification_reason, start_time, start_time_usec, end_time, end_time_usec, object_id, state, output, long_output, escalated, contacts_notified) VALUES (%lu, %d, %d, %s, %lu, %s, %lu, %lu, %d, '%s', '%s', %d, %d)",
00973                                         ido2db_db_tablenames[IDO2DB_DBTABLE_NOTIFICATIONS],
00974                                         *(unsigned long *) data[0],     /* insert start */
00975                                         *(int *) data[1],
00976                                         *(int *) data[2],
00977                                         *(char **) data[3],
00978                                         *(unsigned long *) data[4],
00979                                         *(char **) data[5],
00980                                         *(unsigned long *) data[6],
00981                                         *(unsigned long *) data[7],
00982                                         *(int *) data[8],
00983                                         *(char **) data[9],
00984                                         *(char **) data[10],
00985                                         *(int *) data[11],
00986                                         *(int *) data[12]               /* insert end */
00987                                 );
00988                                 /* send query to db */
00989                                 result = ido2db_db_query(idi, query2);
00990                                 free(query2);
00991                         }
00992                         break;
00993                 case IDO2DB_DBSERVER_DB2:
00994                         break;
00995                 case IDO2DB_DBSERVER_FIREBIRD:
00996                         break;
00997                 case IDO2DB_DBSERVER_FREETDS:
00998                         break;
00999                 case IDO2DB_DBSERVER_INGRES:
01000                         break;
01001                 case IDO2DB_DBSERVER_MSQL:
01002                         break;
01003                 case IDO2DB_DBSERVER_ORACLE:
01004                         break;
01005                 case IDO2DB_DBSERVER_SQLITE:
01006                         break;
01007                 case IDO2DB_DBSERVER_SQLITE3:
01008                         break;
01009                 default:
01010                         break;
01011         }
01012 #endif
01013 
01014 #ifdef USE_PGSQL /* pgsql */
01015 
01016 #endif
01017 
01018 #ifdef USE_ORACLE /* Oracle ocilib specific */
01019 
01020         /* check if we lost connection, and reconnect */
01021         if(ido2db_db_reconnect(idi)==IDO_ERROR)
01022                 return IDO_ERROR;
01023 
01024                         /* use prepared statements and ocilib */
01025                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_notificationdata, MT(":X1"), (big_uint *) data[0])) {
01026                                 return IDO_ERROR;
01027                         }
01028                         if(!OCI_BindInt(idi->dbinfo.oci_statement_notificationdata, MT(":X2"), (int *) data[1])) {
01029                                 return IDO_ERROR;
01030                         }
01031                         if(!OCI_BindInt(idi->dbinfo.oci_statement_notificationdata, MT(":X3"), (int *) data[2])) {
01032                                 return IDO_ERROR;
01033                         }
01034                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_notificationdata, MT(":X4"), (big_uint *) data[13])) { /* unixtimestamp instead of time2sql */
01035                                 return IDO_ERROR;
01036                         }
01037                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_notificationdata, MT(":X5"), (big_uint *) data[4])) {
01038                                 return IDO_ERROR;
01039                         }
01040                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_notificationdata, MT(":X6"), (big_uint *) data[14])) { /* unixtimestamp instead of time2sql */
01041                                 return IDO_ERROR;
01042                         }
01043                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_notificationdata, MT(":X7"), (big_uint *) data[6])) {
01044                                 return IDO_ERROR;
01045                         }
01046                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_notificationdata, MT(":X8"), (big_uint *) data[7])) {
01047                                 return IDO_ERROR;
01048                         }
01049                         if(!OCI_BindInt(idi->dbinfo.oci_statement_notificationdata, MT(":X9"), (int *) data[8])) {
01050                                 return IDO_ERROR;
01051                         }
01052         if(*(char **) data[9]==NULL) {
01053                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_notificationdata, ":X10")==IDO_ERROR) {
01054                         return IDO_ERROR;
01055                 }
01056         } else {
01057 
01058                         if(!OCI_BindString(idi->dbinfo.oci_statement_notificationdata, MT(":X10"), *(char **) data[9], 0)) {
01059                                 return IDO_ERROR;
01060                         }
01061         }
01062         if(*(char **) data[10]==NULL) {
01063                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_notificationdata, ":X11")==IDO_ERROR) {
01064                         return IDO_ERROR;
01065                 }
01066         } else {
01067 
01068                         if(!OCI_BindString(idi->dbinfo.oci_statement_notificationdata, MT(":X11"), *(char **) data[10], 0)) {
01069                                 return IDO_ERROR;
01070                         }
01071         }
01072                         if(!OCI_BindInt(idi->dbinfo.oci_statement_notificationdata, MT(":X12"), (int *) data[11])) {
01073                                 return IDO_ERROR;
01074                         }
01075                         if(!OCI_BindInt(idi->dbinfo.oci_statement_notificationdata, MT(":X13"), (int *) data[12])) {
01076                                 return IDO_ERROR;
01077                         }
01078 
01079                         /* execute statement */
01080                         if(!OCI_Execute(idi->dbinfo.oci_statement_notificationdata)) {
01081                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_notificationdata() execute error\n");
01082                                 return IDO_ERROR;
01083                         }
01084 
01085                         /* commit statement */
01086                         OCI_Commit(idi->dbinfo.oci_connection);
01087 
01088                         /* do not free statement yet! */
01089 #endif
01090         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_notificationdata_add() end\n");
01091 
01092         return result;
01093 }
01094 
01095 
01096 /************************************/
01097 /* CONTACTNOTIFICATIONS             */
01098 /************************************/
01099 
01100 int ido2db_query_insert_or_update_contactnotificationdata_add(ido2db_idi *idi, void **data) {
01101         int result = IDO_OK;
01102 #ifdef USE_LIBDBI
01103         char * query1 = NULL;
01104         char * query2 = NULL;
01105 #endif
01106         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_contactnotificationdata_add() start\n");
01107 
01108         if (idi == NULL)
01109                 return IDO_ERROR;
01110 
01111         if (idi->dbinfo.connected == IDO_FALSE)
01112                 return IDO_ERROR;
01113 
01114 #ifdef USE_LIBDBI /* everything else will be libdbi */
01115         switch (idi->dbinfo.server_type) {
01116                 case IDO2DB_DBSERVER_MYSQL:
01117                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, notification_id, start_time, start_time_usec, end_time, end_time_usec, contact_object_id) VALUES (%lu, %lu, %s, %lu, %s, %lu, %lu) ON DUPLICATE KEY UPDATE notification_id=%lu, end_time=%s, end_time_usec=%lu",
01118                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTNOTIFICATIONS],
01119                                         *(unsigned long *) data[0],     /* insert start */
01120                                         *(unsigned long *) data[1],
01121                                         *(char **) data[2],
01122                                         *(unsigned long *) data[3],
01123                                         *(char **) data[4],
01124                                         *(unsigned long *) data[5],     
01125                                         *(unsigned long *) data[6],     /* insert end */
01126                                         *(unsigned long *) data[1],     /* update start */
01127                                         *(char **) data[4],
01128                                         *(unsigned long *) data[5]      /* update end */
01129                         );
01130                         /* send query to db */
01131                         result = ido2db_db_query(idi, query1);
01132                         free(query1);
01133                         break;
01134                 case IDO2DB_DBSERVER_PGSQL:
01135                         dummy=asprintf(&query1, "UPDATE %s SET notification_id=%lu, end_time=%s, end_time_usec=%lu WHERE instance_id=%lu AND contact_object_id=%lu AND start_time=%s AND start_time_usec=%lu",
01136                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTNOTIFICATIONS],
01137                                         *(unsigned long *) data[1],     /* update start */
01138                                         *(char **) data[4],
01139                                         *(unsigned long *) data[5],     /* update end */
01140                                         *(unsigned long *) data[0],     /* unique constraint start */
01141                                         *(unsigned long *) data[6],
01142                                         *(char **) data[2],
01143                                         *(unsigned long *) data[3]      /* unique constraint end */
01144                         );
01145                         /* send query to db */
01146                         result = ido2db_db_query(idi, query1);
01147                         free(query1);
01148 
01149                         /* check result if update was ok */
01150                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
01151                                 /* try insert instead */
01152                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, notification_id, start_time, start_time_usec, end_time, end_time_usec, contact_object_id) VALUES (%lu, %lu, %s, %lu, %s, %lu, %lu)",
01153                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTNOTIFICATIONS],
01154                                         *(unsigned long *) data[0],     /* insert start */
01155                                         *(unsigned long *) data[1],
01156                                         *(char **) data[2],
01157                                         *(unsigned long *) data[3],
01158                                         *(char **) data[4],
01159                                         *(unsigned long *) data[5],     
01160                                         *(unsigned long *) data[6]      /* insert end */
01161                                 );
01162                                 /* send query to db */
01163                                 result = ido2db_db_query(idi, query2);
01164                                 free(query2);
01165                         }
01166                         break;
01167                 case IDO2DB_DBSERVER_DB2:
01168                         break;
01169                 case IDO2DB_DBSERVER_FIREBIRD:
01170                         break;
01171                 case IDO2DB_DBSERVER_FREETDS:
01172                         break;
01173                 case IDO2DB_DBSERVER_INGRES:
01174                         break;
01175                 case IDO2DB_DBSERVER_MSQL:
01176                         break;
01177                 case IDO2DB_DBSERVER_ORACLE:
01178                         break;
01179                 case IDO2DB_DBSERVER_SQLITE:
01180                         break;
01181                 case IDO2DB_DBSERVER_SQLITE3:
01182                         break;
01183                 default:
01184                         break;
01185         }
01186 #endif
01187 
01188 #ifdef USE_PGSQL /* pgsql */
01189 
01190 #endif
01191 
01192 #ifdef USE_ORACLE /* Oracle ocilib specific */
01193 
01194         /* check if we lost connection, and reconnect */
01195         if(ido2db_db_reconnect(idi)==IDO_ERROR)
01196                 return IDO_ERROR;
01197 
01198                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactnotificationdata, MT(":X1"), (big_uint *) data[0])) {
01199                                 return IDO_ERROR;
01200                         }
01201                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactnotificationdata, MT(":X2"), (big_uint *) data[1])) {
01202                                 return IDO_ERROR;
01203                         }
01204                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactnotificationdata, MT(":X3"), (big_uint *) data[7])) { /* unixtimestamp instead of time2sql */
01205                                 return IDO_ERROR;
01206                         }
01207                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactnotificationdata, MT(":X4"), (big_uint *) data[3])) {
01208                                 return IDO_ERROR;
01209                         }
01210                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactnotificationdata, MT(":X5"), (big_uint *) data[8])) { /* unixtimestamp instead of time2sql */
01211                                 return IDO_ERROR;
01212                         }
01213                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactnotificationdata, MT(":X6"), (big_uint *) data[5])) {
01214                                 return IDO_ERROR;
01215                         }
01216                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactnotificationdata, MT(":X7"), (big_uint *) data[6])) {
01217                                 return IDO_ERROR;
01218                         }
01219 
01220                         /* execute statement */
01221                         if(!OCI_Execute(idi->dbinfo.oci_statement_contactnotificationdata)) {
01222                                 syslog(LOG_USER | LOG_INFO, "contactnotificationdata execute\n");
01223                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_contactnotificationdata() execute error\n");
01224                                 return IDO_ERROR;
01225                         }
01226 
01227                         /* commit statement */
01228                         OCI_Commit(idi->dbinfo.oci_connection);
01229 
01230                         /* do not free statement yet! */
01231 #endif
01232         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_contactnotificationdata_add() end\n");
01233 
01234         return result;
01235 }
01236 
01237 
01238 int ido2db_query_insert_or_update_contactnotificationmethoddata_add(ido2db_idi *idi, void **data) {
01239         int result = IDO_OK;
01240 #ifdef USE_LIBDBI
01241         char * query1 = NULL;
01242         char * query2 = NULL;
01243 #endif
01244 
01245         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_contactnotificationmethoddata_add() start\n");
01246 
01247         if (idi == NULL)
01248                 return IDO_ERROR;
01249 
01250         if (idi->dbinfo.connected == IDO_FALSE)
01251                 return IDO_ERROR;
01252 
01253 #ifdef USE_LIBDBI /* everything else will be libdbi */
01254         switch (idi->dbinfo.server_type) {
01255                 case IDO2DB_DBSERVER_MYSQL:
01256                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, contactnotification_id, start_time, start_time_usec, end_time, end_time_usec, command_object_id, command_args) VALUES (%lu, %lu, %s, %lu, %s, %lu, %lu, '%s') ON DUPLICATE KEY UPDATE end_time=%s, end_time_usec=%lu, command_object_id=%lu, command_args='%s'",
01257                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTNOTIFICATIONMETHODS],
01258                                         *(unsigned long *) data[0],     /* insert start */
01259                                         *(unsigned long *) data[1],
01260                                         *(char **) data[2],
01261                                         *(unsigned long *) data[3],
01262                                         *(char **) data[4],
01263                                         *(unsigned long *) data[5],
01264                                         *(unsigned long *) data[6],     
01265                                         (*(char **) data[7]==NULL)?"":*(char **) data[7],       /* insert end */
01266                                         *(char **) data[4],             /* update start */
01267                                         *(unsigned long *) data[5],
01268                                         *(unsigned long *) data[6],
01269                                         (*(char **) data[7]==NULL)?"":*(char **) data[7]        /* update end */
01270                         );
01271                         /* send query to db */
01272                         result = ido2db_db_query(idi, query1);
01273                         free(query1);
01274                         break;
01275                 case IDO2DB_DBSERVER_PGSQL:
01276                         dummy=asprintf(&query1, "UPDATE %s SET end_time=%s, end_time_usec=%lu, command_object_id=%lu, command_args='%s' WHERE instance_id=%lu AND contactnotification_id=%lu AND start_time=%s AND start_time_usec=%lu",
01277                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTNOTIFICATIONMETHODS],
01278                                         *(char **) data[4],             /* update start */
01279                                         *(unsigned long *) data[5],
01280                                         *(unsigned long *) data[6],
01281                                         (*(char **) data[7]==NULL)?"":*(char **) data[7],             /* update end */
01282                                         *(unsigned long *) data[0],     /* unique constraint start */
01283                                         *(unsigned long *) data[1],
01284                                         *(char **) data[2],
01285                                         *(unsigned long *) data[3]      /* unique constraint end */
01286                         );
01287                         /* send query to db */
01288                         result = ido2db_db_query(idi, query1);
01289                         free(query1);
01290 
01291                         /* check result if update was ok */
01292                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
01293                                 /* try insert instead */
01294                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, contactnotification_id, start_time, start_time_usec, end_time, end_time_usec, command_object_id, command_args) VALUES (%lu, %lu, %s, %lu, %s, %lu, %lu, '%s')",
01295                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTNOTIFICATIONMETHODS],
01296                                         *(unsigned long *) data[0],     /* insert start */
01297                                         *(unsigned long *) data[1],
01298                                         *(char **) data[2],
01299                                         *(unsigned long *) data[3],
01300                                         *(char **) data[4],
01301                                         *(unsigned long *) data[5],
01302                                         *(unsigned long *) data[6],     
01303                                         (*(char **) data[7]==NULL)?"":*(char **) data[7]             /* insert end */
01304                                 );
01305                                 /* send query to db */
01306                                 result = ido2db_db_query(idi, query2);
01307                                 free(query2);
01308                         }
01309                         break;
01310                 case IDO2DB_DBSERVER_DB2:
01311                         break;
01312                 case IDO2DB_DBSERVER_FIREBIRD:
01313                         break;
01314                 case IDO2DB_DBSERVER_FREETDS:
01315                         break;
01316                 case IDO2DB_DBSERVER_INGRES:
01317                         break;
01318                 case IDO2DB_DBSERVER_MSQL:
01319                         break;
01320                 case IDO2DB_DBSERVER_ORACLE:
01321                         break;
01322                 case IDO2DB_DBSERVER_SQLITE:
01323                         break;
01324                 case IDO2DB_DBSERVER_SQLITE3:
01325                         break;
01326                 default:
01327                         break;
01328         }
01329 #endif
01330 
01331 #ifdef USE_PGSQL /* pgsql */
01332 
01333 #endif
01334 
01335 #ifdef USE_ORACLE /* Oracle ocilib specific */
01336 
01337         /* check if we lost connection, and reconnect */
01338         if(ido2db_db_reconnect(idi)==IDO_ERROR)
01339                 return IDO_ERROR;
01340 
01341                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactnotificationmethoddata, MT(":X1"), (big_uint *) data[0])) {
01342                                 return IDO_ERROR;
01343                         }
01344                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactnotificationmethoddata, MT(":X2"), (big_uint *) data[1])) {
01345                                 return IDO_ERROR;
01346                         }
01347                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactnotificationmethoddata, MT(":X3"), (big_uint *) data[8])) { /* unixtimestamp instead of time2sql */
01348                                 return IDO_ERROR;
01349                         }
01350                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactnotificationmethoddata, MT(":X4"), (big_uint *) data[3])) {
01351                                 return IDO_ERROR;
01352                         }
01353                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactnotificationmethoddata, MT(":X5"), (big_uint *) data[9])) { /* unixtimestamp instead of time2sql */
01354                                 return IDO_ERROR;
01355                         }
01356                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactnotificationmethoddata, MT(":X6"), (big_uint *) data[5])) {
01357                                 return IDO_ERROR;
01358                         }
01359                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactnotificationmethoddata, MT(":X7"), (big_uint *) data[6])) {
01360                                 return IDO_ERROR;
01361                         }
01362         if(*(char **) data[7]==NULL) {
01363                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_contactnotificationmethoddata, ":X8")==IDO_ERROR) {
01364                         return IDO_ERROR;
01365                 }
01366         } else {
01367                                 if(!OCI_BindString(idi->dbinfo.oci_statement_contactnotificationmethoddata, MT(":X8"), *(char **) data[7], 0)) {
01368                                         return IDO_ERROR;
01369                                 }
01370         }
01371 
01372                         /* execute statement */
01373                         if(!OCI_Execute(idi->dbinfo.oci_statement_contactnotificationmethoddata)) {
01374                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_contactnotificationmethoddata() execute error\n");
01375                                 return IDO_ERROR;
01376                         }
01377 
01378                         /* commit statement */
01379                         OCI_Commit(idi->dbinfo.oci_connection);
01380 
01381                         /* do not free statement yet! */
01382 #endif
01383         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_contactnotificationmethoddata_add() end\n");
01384 
01385         return result;
01386 }
01387 
01388 
01389 /************************************/
01390 /* SERVICECHECKS                    */
01391 /************************************/
01392 
01393 int ido2db_query_insert_servicecheckdata_add(ido2db_idi *idi, void **data) {
01394         int result = IDO_OK;
01395 #ifdef USE_LIBDBI
01396         char * query1 = NULL;
01397 #endif
01398         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_servicecheckdata_add() start\n");
01399 
01400         if (idi == NULL)
01401                 return IDO_ERROR;
01402 
01403         if (idi->dbinfo.connected == IDO_FALSE)
01404                 return IDO_ERROR;
01405 
01406 #ifdef USE_LIBDBI /* everything else will be libdbi */
01407         switch (idi->dbinfo.server_type) {
01408                 case IDO2DB_DBSERVER_MYSQL:
01409                 case IDO2DB_DBSERVER_PGSQL:
01410                         /* insert statement is the same for mysql and postgresql */
01411                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, service_object_id, check_type, current_check_attempt, max_check_attempts, state, state_type, start_time, start_time_usec, end_time, end_time_usec, timeout, early_timeout, execution_time, latency, return_code, output, long_output, perfdata, command_object_id, command_args, command_line) VALUES (%lu, %lu, %d, %d, %d, %d, %d, %s, %lu, %s, %lu, %d, %d, %lf, %lf, %d, '%s', '%s', '%s', %lu, '%s', '%s')",
01412                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICECHECKS],
01413                                         *(unsigned long *) data[0],     /* insert start */
01414                                         *(unsigned long *) data[1],
01415                                         *(int *) data[2],
01416                                         *(int *) data[3],
01417                                         *(int *) data[4],
01418                                         *(int *) data[5],
01419                                         *(int *) data[6],
01420                                         *(char **) data[7],
01421                                         *(unsigned long *) data[8],
01422                                         *(char **) data[9],
01423                                         *(unsigned long *) data[10],
01424                                         *(int *) data[11],
01425                                         *(int *) data[12],
01426                                         *(double *) data[13],
01427                                         *(double *) data[14],
01428                                         *(int *) data[15],
01429                                         *(char **) data[16],
01430                                         *(char **) data[17],
01431                                         *(char **) data[18],
01432                                         *(unsigned long *) data[19],
01433                                         *(char **) data[20],
01434                                         *(char **) data[21]             /* insert end */
01435                                 );
01436                         /* send query to db */
01437                         result = ido2db_db_query(idi, query1);
01438                         free(query1);
01439                         break;
01440                 case IDO2DB_DBSERVER_DB2:
01441                         break;
01442                 case IDO2DB_DBSERVER_FIREBIRD:
01443                         break;
01444                 case IDO2DB_DBSERVER_FREETDS:
01445                         break;
01446                 case IDO2DB_DBSERVER_INGRES:
01447                         break;
01448                 case IDO2DB_DBSERVER_MSQL:
01449                         break;
01450                 case IDO2DB_DBSERVER_ORACLE:
01451                         break;
01452                 case IDO2DB_DBSERVER_SQLITE:
01453                         break;
01454                 case IDO2DB_DBSERVER_SQLITE3:
01455                         break;
01456                 default:
01457                         break;
01458         }
01459 #endif
01460 
01461 #ifdef USE_PGSQL /* pgsql */
01462 
01463 #endif
01464 
01465 #ifdef USE_ORACLE /* Oracle ocilib specific */
01466 
01467         /* check if we lost connection, and reconnect */
01468         if(ido2db_db_reconnect(idi)==IDO_ERROR)
01469                 return IDO_ERROR;
01470 
01471                         /* bind params to prepared statement */ 
01472                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicechecks, MT(":X1"), (big_uint *) data[0])) {
01473                                 return IDO_ERROR;
01474                         }
01475                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicechecks, MT(":X2"), (big_uint *) data[1])) {
01476                                 return IDO_ERROR;
01477                         }
01478                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicechecks, MT(":X3"), (int *) data[2])) {
01479                                 return IDO_ERROR;
01480                         }
01481                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicechecks, MT(":X4"), (int *) data[3])) {
01482                                 return IDO_ERROR;
01483                         }
01484                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicechecks, MT(":X5"), (int *) data[4])) {
01485                                 return IDO_ERROR;
01486                         }
01487                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicechecks, MT(":X6"), (int *) data[5])) {
01488                                 return IDO_ERROR;
01489                         }
01490                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicechecks, MT(":X7"), (int *) data[6])) {
01491                                 return IDO_ERROR;
01492                         }
01493                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicechecks, MT(":X8"), (big_uint *) data[22])) {
01494                                 return IDO_ERROR;
01495                         }
01496                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicechecks, MT(":X9"), (big_uint *) data[8])) {
01497                                 return IDO_ERROR;
01498                         }
01499                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicechecks, MT(":X10"), (big_uint *) data[23])) {
01500                                 return IDO_ERROR;
01501                         }
01502                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicechecks, MT(":X11"), (big_uint *) data[10])) {
01503                                 return IDO_ERROR;
01504                         }
01505                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicechecks, MT(":X12"), (int *) data[11])) {
01506                                 return IDO_ERROR;
01507                         }
01508                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicechecks, MT(":X13"), (int *) data[12])) {
01509                                 return IDO_ERROR;
01510                         }
01511                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_servicechecks, MT(":X14"), (double *) data[13])) {
01512                                 return IDO_ERROR;
01513                         }
01514                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_servicechecks, MT(":X15"), (double *) data[14])) {
01515                                 return IDO_ERROR;
01516                         }
01517                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicechecks, MT(":X16"), (int *) data[15])) {
01518                                 return IDO_ERROR;
01519                         }
01520 
01521                         if(*(char **) data[16]==NULL) {
01522                                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_servicechecks, ":X17")==IDO_ERROR) {
01523                                         return IDO_ERROR;
01524                                 }
01525                         } else {
01526                                 if(!OCI_BindString(idi->dbinfo.oci_statement_servicechecks, MT(":X17"), *(char **) data[16], 0)) {
01527                                         return IDO_ERROR;
01528                                 }
01529                         }
01530 
01531                         if(*(char **) data[17]==NULL) {
01532                                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_servicechecks, ":X18")==IDO_ERROR) {
01533                                         return IDO_ERROR;
01534                                 }
01535                         } else {
01536                                 if(!OCI_BindString(idi->dbinfo.oci_statement_servicechecks, MT(":X18"), *(char **) data[17], 0)) {
01537                                         return IDO_ERROR;
01538                                 }
01539                         }
01540 
01541                         if(*(char **) data[18]==NULL) {
01542                                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_servicechecks, ":X19")==IDO_ERROR) {
01543                                         return IDO_ERROR;
01544                                 }
01545                         } else {
01546                                 if(!OCI_BindString(idi->dbinfo.oci_statement_servicechecks, MT(":X19"), *(char **) data[18], 0)) {
01547                                         return IDO_ERROR;
01548                                 }
01549                         }
01550 
01551                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicechecks, MT(":X20"), (big_uint *) data[19])) {
01552                                 return IDO_ERROR;
01553                         }
01554 
01555                         if(*(char **) data[20]==NULL) {
01556                                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_servicechecks, ":X21")==IDO_ERROR) {
01557                                         return IDO_ERROR;
01558                                 }
01559                         } else {
01560                                 if(!OCI_BindString(idi->dbinfo.oci_statement_servicechecks, MT(":X21"), *(char **) data[20], 0)) {
01561                                         return IDO_ERROR;
01562                                 }
01563                         }
01564 
01565                         if(*(char **) data[21]==NULL) {
01566                                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_servicechecks, ":X22")==IDO_ERROR) {
01567                                         return IDO_ERROR;
01568                                 }
01569                         } else {
01570                                 if(!OCI_BindString(idi->dbinfo.oci_statement_servicechecks, MT(":X22"), *(char **) data[21], 0)) {
01571                                         return IDO_ERROR;
01572                                 }
01573                         }
01574 
01575                         /* execute statement */
01576                         if(!OCI_Execute(idi->dbinfo.oci_statement_servicechecks)) {
01577                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_servicechecks() execute error\n");
01578                                 return IDO_ERROR;
01579                         }
01580 
01581                         /* commit statement */
01582                         OCI_Commit(idi->dbinfo.oci_connection);
01583 
01584                         /* do not free statement yet! */
01585 #endif
01586         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_servicecheckdata_add() end\n");
01587 
01588         return result;
01589 }
01590 
01591 
01592 /************************************/
01593 /* HOSTCHECKS                       */
01594 /************************************/
01595 
01596 int ido2db_query_insert_hostcheckdata_add(ido2db_idi *idi, void **data) {
01597         int result = IDO_OK;
01598 #ifdef USE_LIBDBI
01599         char * query1 = NULL;
01600 #endif
01601         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_hostcheckdata_add() start\n");
01602 
01603         if (idi == NULL)
01604                 return IDO_ERROR;
01605 
01606         if (idi->dbinfo.connected == IDO_FALSE)
01607                 return IDO_ERROR;
01608 
01609 #ifdef USE_LIBDBI /* everything else will be libdbi */
01610         switch (idi->dbinfo.server_type) {
01611                 case IDO2DB_DBSERVER_MYSQL:
01612                 case IDO2DB_DBSERVER_PGSQL:
01613                         /* the insert queries are the same for mysql and postgresql :) */
01614                         dummy=asprintf(&query1, "INSERT INTO %s (command_object_id, command_args, command_line, instance_id, host_object_id, check_type, is_raw_check, current_check_attempt, max_check_attempts, state, state_type, start_time, start_time_usec, end_time, end_time_usec, timeout, early_timeout, execution_time, latency, return_code, output, long_output, perfdata) VALUES (%lu, '%s', '%s', %lu, %lu, %d, %d, %d, %d, %d, %d, %s, %lu, %s, %lu, %d, %d, %lf, %lf, %d, '%s', '%s', '%s')",
01615                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTCHECKS],
01616                                         *(unsigned long *) data[0],     /* insert start */
01617                                         *(char **) data[1],
01618                                         *(char **) data[2],
01619                                         *(unsigned long *) data[3],
01620                                         *(unsigned long *) data[4],
01621                                         *(int *) data[5],
01622                                         *(int *) data[6],
01623                                         *(int *) data[7],
01624                                         *(int *) data[8],
01625                                         *(int *) data[9],
01626                                         *(int *) data[10],
01627                                         *(char **) data[11],
01628                                         *(unsigned long *) data[12],
01629                                         *(char **) data[13],
01630                                         *(unsigned long *) data[14],
01631                                         *(int *) data[15],
01632                                         *(int *) data[16],
01633                                         *(double *) data[17],
01634                                         *(double *) data[18],
01635                                         *(int *) data[19],
01636                                         *(char **) data[20],
01637                                         *(char **) data[21],
01638                                         *(char **) data[22]            /* insert end */
01639                                 );
01640                         /* send query to db */
01641                         result = ido2db_db_query(idi, query1);
01642                         free(query1);
01643                         break;
01644                 case IDO2DB_DBSERVER_DB2:
01645                         break;
01646                 case IDO2DB_DBSERVER_FIREBIRD:
01647                         break;
01648                 case IDO2DB_DBSERVER_FREETDS:
01649                         break;
01650                 case IDO2DB_DBSERVER_INGRES:
01651                         break;
01652                 case IDO2DB_DBSERVER_MSQL:
01653                         break;
01654                 case IDO2DB_DBSERVER_ORACLE:
01655                         break;
01656                 case IDO2DB_DBSERVER_SQLITE:
01657                         break;
01658                 case IDO2DB_DBSERVER_SQLITE3:
01659                         break;
01660                 default:
01661                         break;
01662         }
01663 #endif
01664 
01665 #ifdef USE_PGSQL /* pgsql */
01666 
01667 #endif
01668 
01669 #ifdef USE_ORACLE /* Oracle ocilib specific */
01670 
01671         /* check if we lost connection, and reconnect */
01672         if(ido2db_db_reconnect(idi)==IDO_ERROR)
01673                 return IDO_ERROR;
01674 
01675                         /* bind params to prepared statement */
01676                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostchecks, MT(":X1"), (big_uint *) data[0])) {
01677                                 return IDO_ERROR;
01678                         }
01679                         if(*(char **) data[1]==NULL) {
01680                                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hostchecks, ":X2")==IDO_ERROR) {
01681                                         return IDO_ERROR;
01682                                 }
01683                         } else {
01684                                 if(!OCI_BindString(idi->dbinfo.oci_statement_hostchecks, MT(":X2"), *(char **) data[1], 0)) {
01685                                         return IDO_ERROR;
01686                                 }
01687                         }
01688                         if(*(char **) data[2]==NULL) {
01689                                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hostchecks, ":X3")==IDO_ERROR) {
01690                                         return IDO_ERROR;
01691                                 }
01692                         } else {
01693                                 if(!OCI_BindString(idi->dbinfo.oci_statement_hostchecks, MT(":X3"), *(char **) data[2], 0)) {
01694                                         return IDO_ERROR;
01695                                 }
01696                         }
01697                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostchecks, MT(":X4"), (big_uint *) data[3])) {
01698                                 return IDO_ERROR;
01699                         }
01700                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostchecks, MT(":X5"), (big_uint *) data[4])) {
01701                                 return IDO_ERROR;
01702                         }
01703                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostchecks, MT(":X6"), (int *) data[5])) {
01704                                 return IDO_ERROR;
01705                         }
01706                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostchecks, MT(":X7"), (int *) data[6])) {
01707                                 return IDO_ERROR;
01708                         }
01709                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostchecks, MT(":X8"), (int *) data[7])) {
01710                                 return IDO_ERROR;
01711                         }
01712                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostchecks, MT(":X9"), (int *) data[8])) {
01713                                 return IDO_ERROR;
01714                         }
01715                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostchecks, MT(":X10"), (int *) data[9])) {
01716                                 return IDO_ERROR;
01717                         }
01718                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostchecks, MT(":X11"), (int *) data[10])) {
01719                                 return IDO_ERROR;
01720                         }
01721                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostchecks, MT(":X12"), (big_uint *) data[23])) { /* unixtimestamp instead of time2sql */
01722                                 return IDO_ERROR;
01723                         }
01724                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostchecks, MT(":X13"), (big_uint *) data[12])) {
01725                                 return IDO_ERROR;
01726                         }
01727                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostchecks, MT(":X14"), (big_uint *) data[24])) { /* unixtimestamp instead of time2sql */
01728                                 return IDO_ERROR;
01729                         }
01730                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostchecks, MT(":X15"), (big_uint *) data[14])) {
01731                                 return IDO_ERROR;
01732                         }
01733                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostchecks, MT(":X16"), (int *) data[15])) {
01734                                 return IDO_ERROR;
01735                         }
01736                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostchecks, MT(":X17"), (int *) data[16])) {
01737                                 return IDO_ERROR;
01738                         }
01739                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_hostchecks, MT(":X18"), (double *) data[17])) {
01740                                 return IDO_ERROR;
01741                         }
01742                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_hostchecks, MT(":X19"), (double *) data[18])) {
01743                                 return IDO_ERROR;
01744                         }
01745                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostchecks, MT(":X20"), (int *) data[19])) {
01746                                 return IDO_ERROR;
01747                         }
01748                         if(*(char **) data[20]==NULL) {
01749                                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hostchecks, ":X21")==IDO_ERROR) {
01750                                         return IDO_ERROR;
01751                                 }
01752                         } else {
01753                                 if(!OCI_BindString(idi->dbinfo.oci_statement_hostchecks, MT(":X21"), *(char **) data[20], 0)) {
01754                                         return IDO_ERROR;
01755                                 }
01756                         }
01757                         if(*(char **) data[21]==NULL) {
01758                                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hostchecks, ":X22")==IDO_ERROR) {
01759                                         return IDO_ERROR;
01760                                 }
01761                         } else {
01762                                 if(!OCI_BindString(idi->dbinfo.oci_statement_hostchecks, MT(":X22"), *(char **) data[21], 0)) {
01763                                         return IDO_ERROR;
01764                                 }
01765                         }
01766                         if(*(char **) data[22]==NULL) {
01767                                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hostchecks, ":X23")==IDO_ERROR) {
01768                                         return IDO_ERROR;
01769                                 }
01770                         } else {
01771                                 if(!OCI_BindString(idi->dbinfo.oci_statement_hostchecks, MT(":X23"), *(char **) data[22], 0)) {
01772                                         return IDO_ERROR;
01773                                 }
01774                         }
01775 
01776                         /* execute statement */
01777                         if(!OCI_Execute(idi->dbinfo.oci_statement_hostchecks)) {
01778                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_hostchecks() execute error\n");
01779                                 return IDO_ERROR;
01780                         }
01781 
01782                         /* commit statement */
01783                         OCI_Commit(idi->dbinfo.oci_connection);
01784 
01785                         /* do not free statement yet! */
01786 #endif
01787         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_hostcheckdata_add() end\n");
01788 
01789         return result;
01790 }
01791 
01792 
01793 /************************************/
01794 /* COMMENTS                         */
01795 /************************************/
01796 
01797 int ido2db_query_insert_or_update_commentdata_add(ido2db_idi *idi, void **data) {
01798         int result = IDO_OK;
01799 #ifdef USE_LIBDBI
01800         char * query1 = NULL;
01801         char * query2 = NULL;
01802 #endif
01803         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_commentdata_add() start\n");
01804 
01805         if (idi == NULL)
01806                 return IDO_ERROR;
01807 
01808         if (idi->dbinfo.connected == IDO_FALSE)
01809                 return IDO_ERROR;
01810 
01811 #ifdef USE_LIBDBI /* everything else will be libdbi */
01812         switch (idi->dbinfo.server_type) {
01813                 case IDO2DB_DBSERVER_MYSQL:
01814                         dummy=asprintf(&query1, "INSERT INTO %s (entry_time, entry_time_usec, instance_id, comment_type, entry_type, object_id, comment_time, internal_comment_id, author_name, comment_data, is_persistent, comment_source, expires, expiration_time) VALUES (%s, %lu, %lu, %d, %d, %lu, %s, %lu, '%s', '%s', %d, %d, %d, %s) ON DUPLICATE KEY UPDATE comment_type=%d, entry_type=%d, object_id=%lu, author_name='%s', comment_data='%s', is_persistent=%d, comment_source=%d, expires=%d, expiration_time=%s",
01815                                         ido2db_db_tablenames[IDO2DB_DBTABLE_COMMENTS],
01816                                         *(char **) data[0],             /* insert start */
01817                                         *(unsigned long *) data[1],
01818                                         *(unsigned long *) data[2],
01819                                         *(int *) data[3],
01820                                         *(int *) data[4],
01821                                         *(unsigned long *) data[5],
01822                                         *(char **) data[6],
01823                                         *(unsigned long *) data[7],
01824                                         *(char **) data[8],
01825                                         *(char **) data[9],
01826                                         *(int *) data[10],
01827                                         *(int *) data[11],
01828                                         *(int *) data[12],
01829                                         *(char **) data[13],            /* insert end */
01830                                         *(int *) data[3],               /* update start */
01831                                         *(int *) data[4],
01832                                         *(unsigned long *) data[5],
01833                                         *(char **) data[8],
01834                                         *(char **) data[9],
01835                                         *(int *) data[10],
01836                                         *(int *) data[11],
01837                                         *(int *) data[12],
01838                                         *(char **) data[13]             /* end end */
01839                         );
01840                         /* send query to db */
01841                         result = ido2db_db_query(idi, query1);
01842                         free(query1);
01843                         break;
01844                 case IDO2DB_DBSERVER_PGSQL:
01845                         dummy=asprintf(&query1, "UPDATE %s SET comment_type=%d, entry_type=%d, object_id=%lu, author_name='%s', comment_data='%s', is_persistent=%d, comment_source=%d, expires=%d, expiration_time=%s WHERE instance_id=%lu AND comment_time=%s AND internal_comment_id=%lu",
01846                                         ido2db_db_tablenames[IDO2DB_DBTABLE_COMMENTS],
01847                                         *(int *) data[3],               /* update start */
01848                                         *(int *) data[4],
01849                                         *(unsigned long *) data[5],
01850                                         *(char **) data[8],
01851                                         *(char **) data[9],
01852                                         *(int *) data[10],
01853                                         *(int *) data[11],
01854                                         *(int *) data[12],
01855                                         *(char **) data[13],            /* end end */
01856                                         *(unsigned long *) data[2],     /* unique constraint start */
01857                                         *(char **) data[6],
01858                                         *(unsigned long *) data[7]      /* unique constraint end */
01859                         );
01860                         /* send query to db */
01861                         result = ido2db_db_query(idi, query1);
01862                         free(query1);
01863 
01864                         /* check result if update was ok */
01865                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
01866                                 /* try insert instead */
01867                                 dummy=asprintf(&query2, "INSERT INTO %s (entry_time, entry_time_usec, instance_id, comment_type, entry_type, object_id, comment_time, internal_comment_id, author_name, comment_data, is_persistent, comment_source, expires, expiration_time) VALUES (%s, %lu, %lu, %d, %d, %lu, %s, %lu, '%s', '%s', %d, %d, %d, %s)",
01868                                         ido2db_db_tablenames[IDO2DB_DBTABLE_COMMENTS],
01869                                         *(char **) data[0],             /* insert start */
01870                                         *(unsigned long *) data[1],
01871                                         *(unsigned long *) data[2],
01872                                         *(int *) data[3],
01873                                         *(int *) data[4],
01874                                         *(unsigned long *) data[5],
01875                                         *(char **) data[6],
01876                                         *(unsigned long *) data[7],
01877                                         *(char **) data[8],
01878                                         *(char **) data[9],
01879                                         *(int *) data[10],
01880                                         *(int *) data[11],
01881                                         *(int *) data[12],
01882                                         *(char **) data[13]            /* insert end */
01883                                 );
01884                                 /* send query to db */
01885                                 result = ido2db_db_query(idi, query2);
01886                                 free(query2);
01887                         }
01888                         break;
01889                 case IDO2DB_DBSERVER_DB2:
01890                         break;
01891                 case IDO2DB_DBSERVER_FIREBIRD:
01892                         break;
01893                 case IDO2DB_DBSERVER_FREETDS:
01894                         break;
01895                 case IDO2DB_DBSERVER_INGRES:
01896                         break;
01897                 case IDO2DB_DBSERVER_MSQL:
01898                         break;
01899                 case IDO2DB_DBSERVER_ORACLE:
01900                         break;
01901                 case IDO2DB_DBSERVER_SQLITE:
01902                         break;
01903                 case IDO2DB_DBSERVER_SQLITE3:
01904                         break;
01905                 default:
01906                         break;
01907         }
01908 #endif
01909 
01910 #ifdef USE_PGSQL /* pgsql */
01911 
01912 #endif
01913 
01914 #ifdef USE_ORACLE /* Oracle ocilib specific */
01915 
01916         /* check if we lost connection, and reconnect */
01917         if(ido2db_db_reconnect(idi)==IDO_ERROR)
01918                 return IDO_ERROR;
01919 
01920                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_commentdata, MT(":X1"), (big_uint *) data[14])) { /* unixtimestamp instead of time2sql */
01921                                 return IDO_ERROR;
01922                         }
01923                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_commentdata, MT(":X2"), (big_uint *) data[1])) {
01924                                 return IDO_ERROR;
01925                         }
01926                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_commentdata, MT(":X3"), (big_uint *) data[2])) {
01927                                 return IDO_ERROR;
01928                         }
01929                         if(!OCI_BindInt(idi->dbinfo.oci_statement_commentdata, MT(":X4"), (int *) data[3])) {
01930                                 return IDO_ERROR;
01931                         }
01932                         if(!OCI_BindInt(idi->dbinfo.oci_statement_commentdata, MT(":X5"), (int *) data[4])) {
01933                                 return IDO_ERROR;
01934                         }
01935                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_commentdata, MT(":X6"), (big_uint *) data[5])) {
01936                                 return IDO_ERROR;
01937                         }
01938                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_commentdata, MT(":X7"), (big_uint *) data[15])) { /* unixtimestamp instead of time2sql */
01939                                 return IDO_ERROR;
01940                         }
01941                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_commentdata, MT(":X8"), (big_uint *) data[7])) {
01942                                 return IDO_ERROR;
01943                         }
01944         if(*(char **) data[8]==NULL) {
01945                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_commentdata, ":X9")==IDO_ERROR) {
01946                         return IDO_ERROR;
01947                 }
01948         } else {
01949                         if(!OCI_BindString(idi->dbinfo.oci_statement_commentdata, MT(":X9"), *(char **) data[8], 0)) {
01950                                 return IDO_ERROR;
01951                         }
01952         }
01953         if(*(char **) data[9]==NULL) {
01954                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_commentdata, ":X10")==IDO_ERROR) {
01955                         return IDO_ERROR;
01956                 }
01957         } else {
01958                         if(!OCI_BindString(idi->dbinfo.oci_statement_commentdata, MT(":X10"), *(char **) data[9], 0)) {
01959                                 return IDO_ERROR;
01960                         }
01961         }
01962                         if(!OCI_BindInt(idi->dbinfo.oci_statement_commentdata, MT(":X11"), (int *) data[10])) {
01963                                 return IDO_ERROR;
01964                         }
01965                         if(!OCI_BindInt(idi->dbinfo.oci_statement_commentdata, MT(":X12"), (int *) data[11])) {
01966                                 return IDO_ERROR;
01967                         }
01968                         if(!OCI_BindInt(idi->dbinfo.oci_statement_commentdata, MT(":X13"), (int *) data[12])) {
01969                                 return IDO_ERROR;
01970                         }
01971                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_commentdata, MT(":X14"), (big_uint *) data[16])) { /* unixtimestamp instead of time2sql */
01972                                 return IDO_ERROR;
01973                         }
01974 
01975                         /* execute statement */
01976                         if(!OCI_Execute(idi->dbinfo.oci_statement_commentdata)) {
01977                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_commentdata() execute error\n");
01978                                 return IDO_ERROR;
01979                         }
01980 
01981                         /* commit statement */
01982                         OCI_Commit(idi->dbinfo.oci_connection);
01983 
01984                         /* do not free statement yet! */
01985 #endif
01986         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_commentdata_add() end\n");
01987 
01988         return result;
01989 }
01990 
01991 
01992 int ido2db_query_insert_or_update_commentdata_history_add(ido2db_idi *idi, void **data) {
01993         int result = IDO_OK;
01994 #ifdef USE_LIBDBI
01995         char * query1 = NULL;
01996         char * query2 = NULL;
01997 #endif
01998         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_commentdata_history_add() start\n");
01999 
02000         if (idi == NULL)
02001                 return IDO_ERROR;
02002 
02003         if (idi->dbinfo.connected == IDO_FALSE)
02004                 return IDO_ERROR;
02005 
02006 #ifdef USE_LIBDBI /* everything else will be libdbi */
02007         switch (idi->dbinfo.server_type) {
02008                 case IDO2DB_DBSERVER_MYSQL:
02009                         dummy=asprintf(&query1, "INSERT INTO %s (entry_time, entry_time_usec, instance_id, comment_type, entry_type, object_id, comment_time, internal_comment_id, author_name, comment_data, is_persistent, comment_source, expires, expiration_time) VALUES (%s, %lu, %lu, %d, %d, %lu, %s, %lu, '%s', '%s', %d, %d, %d, %s) ON DUPLICATE KEY UPDATE comment_type=%d, entry_type=%d, object_id=%lu, author_name='%s', comment_data='%s', is_persistent=%d, comment_source=%d, expires=%d, expiration_time=%s",
02010                                         ido2db_db_tablenames[IDO2DB_DBTABLE_COMMENTHISTORY],
02011                                         *(char **) data[0],             /* insert start */
02012                                         *(unsigned long *) data[1],
02013                                         *(unsigned long *) data[2],
02014                                         *(int *) data[3],
02015                                         *(int *) data[4],
02016                                         *(unsigned long *) data[5],
02017                                         *(char **) data[6],
02018                                         *(unsigned long *) data[7],
02019                                         *(char **) data[8],
02020                                         *(char **) data[9],
02021                                         *(int *) data[10],
02022                                         *(int *) data[11],
02023                                         *(int *) data[12],
02024                                         *(char **) data[13],            /* insert end */
02025                                         *(int *) data[3],               /* update start */
02026                                         *(int *) data[4],
02027                                         *(unsigned long *) data[5],
02028                                         *(char **) data[8],
02029                                         *(char **) data[9],
02030                                         *(int *) data[10],
02031                                         *(int *) data[11],
02032                                         *(int *) data[12],
02033                                         *(char **) data[13]             /* end end */
02034                         );
02035                         /* send query to db */
02036                         result = ido2db_db_query(idi, query1);
02037                         free(query1);
02038                         break;
02039                 case IDO2DB_DBSERVER_PGSQL:
02040                         dummy=asprintf(&query1, "UPDATE %s SET comment_type=%d, entry_type=%d, object_id=%lu, author_name='%s', comment_data='%s', is_persistent=%d, comment_source=%d, expires=%d, expiration_time=%s WHERE instance_id=%lu AND comment_time=%s AND internal_comment_id=%lu",
02041                                         ido2db_db_tablenames[IDO2DB_DBTABLE_COMMENTHISTORY],
02042                                         *(int *) data[3],               /* update start */
02043                                         *(int *) data[4],
02044                                         *(unsigned long *) data[5],
02045                                         *(char **) data[8],
02046                                         *(char **) data[9],
02047                                         *(int *) data[10],
02048                                         *(int *) data[11],
02049                                         *(int *) data[12],
02050                                         *(char **) data[13],            /* end end */
02051                                         *(unsigned long *) data[2],     /* unique constraint start */
02052                                         *(char **) data[6],
02053                                         *(unsigned long *) data[7]      /* unique constraint end */
02054                         );
02055                         /* send query to db */
02056                         result = ido2db_db_query(idi, query1);
02057                         free(query1);
02058 
02059                         /* check result if update was ok */
02060                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
02061                                 /* try insert instead */
02062                                 dummy=asprintf(&query2, "INSERT INTO %s (entry_time, entry_time_usec, instance_id, comment_type, entry_type, object_id, comment_time, internal_comment_id, author_name, comment_data, is_persistent, comment_source, expires, expiration_time) VALUES (%s, %lu, %lu, %d, %d, %lu, %s, %lu, '%s', '%s', %d, %d, %d, %s)",
02063                                         ido2db_db_tablenames[IDO2DB_DBTABLE_COMMENTHISTORY],
02064                                         *(char **) data[0],             /* insert start */
02065                                         *(unsigned long *) data[1],
02066                                         *(unsigned long *) data[2],
02067                                         *(int *) data[3],
02068                                         *(int *) data[4],
02069                                         *(unsigned long *) data[5],
02070                                         *(char **) data[6],
02071                                         *(unsigned long *) data[7],
02072                                         *(char **) data[8],
02073                                         *(char **) data[9],
02074                                         *(int *) data[10],
02075                                         *(int *) data[11],
02076                                         *(int *) data[12],
02077                                         *(char **) data[13]            /* insert end */
02078                                 );
02079                                 /* send query to db */
02080                                 result = ido2db_db_query(idi, query2);
02081                                 free(query2);
02082                         }
02083                         break;
02084                 case IDO2DB_DBSERVER_DB2:
02085                         break;
02086                 case IDO2DB_DBSERVER_FIREBIRD:
02087                         break;
02088                 case IDO2DB_DBSERVER_FREETDS:
02089                         break;
02090                 case IDO2DB_DBSERVER_INGRES:
02091                         break;
02092                 case IDO2DB_DBSERVER_MSQL:
02093                         break;
02094                 case IDO2DB_DBSERVER_ORACLE:
02095                         break;
02096                 case IDO2DB_DBSERVER_SQLITE:
02097                         break;
02098                 case IDO2DB_DBSERVER_SQLITE3:
02099                         break;
02100                 default:
02101                         break;
02102         }
02103 #endif
02104 
02105 #ifdef USE_PGSQL /* pgsql */
02106 
02107 #endif
02108 
02109 #ifdef USE_ORACLE /* Oracle ocilib specific */
02110 
02111         /* check if we lost connection, and reconnect */
02112         if(ido2db_db_reconnect(idi)==IDO_ERROR)
02113                 return IDO_ERROR;
02114 
02115                         /* use prepared statements and ocilib */
02116                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_commentdata_history, MT(":X1"), (big_uint *) data[14])) { /* unixtimestamp instead of time2sql */
02117                                 return IDO_ERROR;
02118                         }
02119                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_commentdata_history, MT(":X2"), (big_uint *) data[1])) {
02120                                 return IDO_ERROR;
02121                         }
02122                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_commentdata_history, MT(":X3"), (big_uint *) data[2])) {
02123                                 return IDO_ERROR;
02124                         }
02125                         if(!OCI_BindInt(idi->dbinfo.oci_statement_commentdata_history, MT(":X4"), (int *) data[3])) {
02126                                 return IDO_ERROR;
02127                         }
02128                         if(!OCI_BindInt(idi->dbinfo.oci_statement_commentdata_history, MT(":X5"), (int *) data[4])) {
02129                                 return IDO_ERROR;
02130                         }
02131                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_commentdata_history, MT(":X6"), (big_uint *) data[5])) {
02132                                 return IDO_ERROR;
02133                         }
02134                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_commentdata_history, MT(":X7"), (big_uint *) data[15])) { /* unixtimestamp instead of time2sql */
02135                                 return IDO_ERROR;
02136                         }
02137                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_commentdata_history, MT(":X8"), (big_uint *) data[7])) {
02138                                 return IDO_ERROR;
02139                         }
02140         if(*(char **) data[8]==NULL) {
02141                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_commentdata_history, ":X9")==IDO_ERROR) {
02142                         return IDO_ERROR;
02143                 }
02144         } else {
02145                         if(!OCI_BindString(idi->dbinfo.oci_statement_commentdata_history, MT(":X9"), *(char **) data[8], 0)) {
02146                                 return IDO_ERROR;
02147                         }
02148         }
02149         if(*(char **) data[9]==NULL) {
02150                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_commentdata_history, ":X10")==IDO_ERROR) {
02151                         return IDO_ERROR;
02152                 }
02153         } else {
02154                         if(!OCI_BindString(idi->dbinfo.oci_statement_commentdata_history, MT(":X10"), *(char **) data[9], 0)) {
02155                                 return IDO_ERROR;
02156                         }
02157         }
02158                         if(!OCI_BindInt(idi->dbinfo.oci_statement_commentdata_history, MT(":X11"), (int *) data[10])) {
02159                                 return IDO_ERROR;
02160                         }
02161                         if(!OCI_BindInt(idi->dbinfo.oci_statement_commentdata_history, MT(":X12"), (int *) data[11])) {
02162                                 return IDO_ERROR;
02163                         }
02164                         if(!OCI_BindInt(idi->dbinfo.oci_statement_commentdata_history, MT(":X13"), (int *) data[12])) {
02165                                 return IDO_ERROR;
02166                         }
02167                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_commentdata_history, MT(":X14"), (big_uint *) data[16])) { /* unixtimestamp instead of time2sql */
02168                                 return IDO_ERROR;
02169                         }
02170 
02171                         /* execute statement */
02172                         if(!OCI_Execute(idi->dbinfo.oci_statement_commentdata_history)) {
02173                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_commentdata_history() execute error\n");
02174                                 return IDO_ERROR;
02175                         }
02176 
02177                         /* commit statement */
02178                         OCI_Commit(idi->dbinfo.oci_connection);
02179 
02180                         /* do not free statement yet! */
02181 #endif
02182         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_commentdata_history_add() end\n");
02183 
02184         return result;
02185 }
02186 
02187 
02188 /************************************/
02189 /* DOWNTIME                         */
02190 /************************************/
02191 
02192 int ido2db_query_insert_or_update_downtimedata_scheduled_downtime_add(ido2db_idi *idi, void **data) {
02193         int result = IDO_OK;
02194 #ifdef USE_LIBDBI
02195         char * query1 = NULL;
02196         char * query2 = NULL;
02197 #endif
02198         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_downtimedata_scheduled_downtime_add() start\n");
02199 
02200         if (idi == NULL)
02201                 return IDO_ERROR;
02202 
02203         if (idi->dbinfo.connected == IDO_FALSE)
02204                 return IDO_ERROR;
02205 
02206 #ifdef USE_LIBDBI /* everything else will be libdbi */
02207         switch (idi->dbinfo.server_type) {
02208                 case IDO2DB_DBSERVER_MYSQL:
02209                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, downtime_type, object_id, entry_time, author_name, comment_data, internal_downtime_id, triggered_by_id, is_fixed, duration, scheduled_start_time, scheduled_end_time) VALUES (%lu, %d, %lu, %s, '%s', '%s', %lu, %lu, %d, %lu, %s, %s) ON DUPLICATE KEY UPDATE downtime_type=%d, author_name='%s', comment_data='%s', triggered_by_id=%lu, is_fixed=%d, duration=%lu, scheduled_start_time=%s, scheduled_end_time=%s ",
02210                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SCHEDULEDDOWNTIME],
02211                                         *(unsigned long *) data[0],     /* insert start */
02212                                         *(int *) data[1],
02213                                         *(unsigned long *) data[2],
02214                                         *(char **) data[3],
02215                                         *(char **) data[4],
02216                                         *(char **) data[5],
02217                                         *(unsigned long *) data[6],
02218                                         *(unsigned long *) data[7],
02219                                         *(int *) data[8],
02220                                         *(unsigned long *) data[9],
02221                                         *(char **) data[10],
02222                                         *(char **) data[11],            /* insert end */
02223                                         *(int *) data[1],               /* update start */
02224                                         *(char **) data[4],
02225                                         *(char **) data[5],
02226                                         *(unsigned long *) data[7],
02227                                         *(int *) data[8],
02228                                         *(unsigned long *) data[9],
02229                                         *(char **) data[10],
02230                                         *(char **) data[11]             /* update end */
02231                         );
02232                         /* send query to db */
02233                         result = ido2db_db_query(idi, query1);
02234                         free(query1);
02235                         break;
02236                 case IDO2DB_DBSERVER_PGSQL:
02237                         dummy=asprintf(&query1, "UPDATE %s SET downtime_type=%d, author_name='%s', comment_data='%s', triggered_by_id=%lu, is_fixed=%d, duration=%lu, scheduled_start_time=%s, scheduled_end_time=%s WHERE instance_id=%lu AND object_id=%lu AND entry_time=%s AND internal_downtime_id=%lu",
02238                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SCHEDULEDDOWNTIME],
02239                                         *(int *) data[1],               /* update start */
02240                                         *(char **) data[4],
02241                                         *(char **) data[5],
02242                                         *(unsigned long *) data[7],
02243                                         *(int *) data[8],
02244                                         *(unsigned long *) data[9],
02245                                         *(char **) data[10],
02246                                         *(char **) data[11],            /* update end */
02247                                         *(unsigned long *) data[0],     /* unique constraint start */
02248                                         *(unsigned long *) data[2],
02249                                         *(char **) data[3],
02250                                         *(unsigned long *) data[6]      /* unique constraint end */
02251                         );
02252                         /* send query to db */
02253                         result = ido2db_db_query(idi, query1);
02254                         free(query1);
02255 
02256                         /* check result if update was ok */
02257                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
02258                                 /* try insert instead */
02259                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, downtime_type, object_id, entry_time, author_name, comment_data, internal_downtime_id, triggered_by_id, is_fixed, duration, scheduled_start_time, scheduled_end_time) VALUES (%lu, %d, %lu, %s, '%s', '%s', %lu, %lu, %d, %lu, %s, %s)",
02260                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SCHEDULEDDOWNTIME],
02261                                         *(unsigned long *) data[0],     /* insert start */
02262                                         *(int *) data[1],
02263                                         *(unsigned long *) data[2],
02264                                         *(char **) data[3],
02265                                         *(char **) data[4],
02266                                         *(char **) data[5],
02267                                         *(unsigned long *) data[6],
02268                                         *(unsigned long *) data[7],
02269                                         *(int *) data[8],
02270                                         *(unsigned long *) data[9],
02271                                         *(char **) data[10],
02272                                         *(char **) data[11]             /* insert end */
02273                                 );
02274                                 /* send query to db */
02275                                 result = ido2db_db_query(idi, query2);
02276                                 free(query2);
02277                         }
02278                         break;
02279                 case IDO2DB_DBSERVER_DB2:
02280                         break;
02281                 case IDO2DB_DBSERVER_FIREBIRD:
02282                         break;
02283                 case IDO2DB_DBSERVER_FREETDS:
02284                         break;
02285                 case IDO2DB_DBSERVER_INGRES:
02286                         break;
02287                 case IDO2DB_DBSERVER_MSQL:
02288                         break;
02289                 case IDO2DB_DBSERVER_ORACLE:
02290                         break;
02291                 case IDO2DB_DBSERVER_SQLITE:
02292                         break;
02293                 case IDO2DB_DBSERVER_SQLITE3:
02294                         break;
02295                 default:
02296                         break;
02297         }
02298 #endif
02299 
02300 #ifdef USE_PGSQL /* pgsql */
02301 
02302 #endif
02303 
02304 #ifdef USE_ORACLE /* Oracle ocilib specific */
02305 
02306         /* check if we lost connection, and reconnect */
02307         if(ido2db_db_reconnect(idi)==IDO_ERROR)
02308                 return IDO_ERROR;
02309 
02310                         /* use prepared statements and ocilib */
02311                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimedata_scheduled_downtime, MT(":X1"), (big_uint *) data[0])) {
02312                                 return IDO_ERROR;
02313                         }
02314                         if(!OCI_BindInt(idi->dbinfo.oci_statement_downtimedata_scheduled_downtime, MT(":X2"), (int *) data[1])) {
02315                                 return IDO_ERROR;
02316                         }
02317                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimedata_scheduled_downtime, MT(":X3"), (big_uint *) data[2])) {
02318                                 return IDO_ERROR;
02319                         }
02320                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimedata_scheduled_downtime, MT(":X4"), (big_uint *) data[12])) { /* unixtimestamp instead of time2sql */
02321                                 return IDO_ERROR;
02322                         }
02323         if(*(char **) data[4]==NULL) {
02324                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_downtimedata_scheduled_downtime, ":X5")==IDO_ERROR) {
02325                         return IDO_ERROR;
02326                 }
02327         } else {
02328                         if(!OCI_BindString(idi->dbinfo.oci_statement_downtimedata_scheduled_downtime, MT(":X5"), *(char **) data[4], 0)) {
02329                                 return IDO_ERROR;
02330                         }
02331         }
02332         if(*(char **) data[5]==NULL) {
02333                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_downtimedata_scheduled_downtime, ":X6")==IDO_ERROR) {
02334                         return IDO_ERROR;
02335                 }
02336         } else {
02337                         if(!OCI_BindString(idi->dbinfo.oci_statement_downtimedata_scheduled_downtime, MT(":X6"), *(char **) data[5], 0)) {
02338                                 return IDO_ERROR;
02339                         }
02340         }
02341                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimedata_scheduled_downtime, MT(":X7"), (big_uint *) data[6])) {
02342                                 return IDO_ERROR;
02343                         }
02344                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimedata_scheduled_downtime, MT(":X8"), (big_uint *) data[7])) {
02345                                 return IDO_ERROR;
02346                         }
02347                         if(!OCI_BindInt(idi->dbinfo.oci_statement_downtimedata_scheduled_downtime, MT(":X9"), (int *) data[8])) {
02348                                 return IDO_ERROR;
02349                         }
02350                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimedata_scheduled_downtime, MT(":X10"), (big_uint *) data[9])) {
02351                                 return IDO_ERROR;
02352                         }
02353                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimedata_scheduled_downtime, MT(":X11"), (big_uint *) data[13])) { /* unixtimestamp instead of time2sql */
02354                                 return IDO_ERROR;
02355                         }
02356                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimedata_scheduled_downtime, MT(":X12"), (big_uint *) data[14])) { /* unixtimestamp instead of time2sql */
02357                                 return IDO_ERROR;
02358                         }
02359 
02360                         /* execute statement */
02361                         if(!OCI_Execute(idi->dbinfo.oci_statement_downtimedata_scheduled_downtime)) {
02362                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_downtimedata_scheduled_downtime() execute error\n");
02363                                 return IDO_ERROR;
02364                         }
02365 
02366                         /* commit statement */
02367                         OCI_Commit(idi->dbinfo.oci_connection);
02368 
02369                         /* do not free statement yet! */
02370 #endif
02371         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_downtimedata_scheduled_downtime_add() end\n");
02372 
02373         return result;
02374 }
02375 
02376 int ido2db_query_insert_or_update_downtimedata_downtime_history_add(ido2db_idi *idi, void **data) {
02377         int result = IDO_OK;
02378 #ifdef USE_LIBDBI
02379         char * query1 = NULL;
02380         char * query2 = NULL;
02381 #endif
02382         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_downtimedata_downtime_history_add() start\n");
02383 
02384         if (idi == NULL)
02385                 return IDO_ERROR;
02386 
02387         if (idi->dbinfo.connected == IDO_FALSE)
02388                 return IDO_ERROR;
02389 
02390 #ifdef USE_LIBDBI /* everything else will be libdbi */
02391         switch (idi->dbinfo.server_type) {
02392                 case IDO2DB_DBSERVER_MYSQL:
02393                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, downtime_type, object_id, entry_time, author_name, comment_data, internal_downtime_id, triggered_by_id, is_fixed, duration, scheduled_start_time, scheduled_end_time) VALUES (%lu, %d, %lu, %s, '%s', '%s', %lu, %lu, %d, %lu, %s, %s) ON DUPLICATE KEY UPDATE downtime_type=%d, author_name='%s', comment_data='%s', triggered_by_id=%lu, is_fixed=%d, duration=%lu, scheduled_start_time=%s, scheduled_end_time=%s ",
02394                                         ido2db_db_tablenames[IDO2DB_DBTABLE_DOWNTIMEHISTORY],
02395                                         *(unsigned long *) data[0],     /* insert start */
02396                                         *(int *) data[1],
02397                                         *(unsigned long *) data[2],
02398                                         *(char **) data[3],
02399                                         *(char **) data[4],
02400                                         *(char **) data[5],
02401                                         *(unsigned long *) data[6],
02402                                         *(unsigned long *) data[7],
02403                                         *(int *) data[8],
02404                                         *(unsigned long *) data[9],
02405                                         *(char **) data[10],
02406                                         *(char **) data[11],            /* insert end */
02407                                         *(int *) data[1],               /* update start */
02408                                         *(char **) data[4],
02409                                         *(char **) data[5],
02410                                         *(unsigned long *) data[7],
02411                                         *(int *) data[8],
02412                                         *(unsigned long *) data[9],
02413                                         *(char **) data[10],
02414                                         *(char **) data[11]             /* update end */
02415                         );
02416                         /* send query to db */
02417                         result = ido2db_db_query(idi, query1);
02418                         free(query1);   
02419                         break;
02420                 case IDO2DB_DBSERVER_PGSQL:
02421                         dummy=asprintf(&query1, "UPDATE %s SET downtime_type=%d, author_name='%s', comment_data='%s', triggered_by_id=%lu, is_fixed=%d, duration=%lu, scheduled_start_time=%s, scheduled_end_time=%s WHERE instance_id=%lu AND object_id=%lu AND entry_time=%s AND internal_downtime_id=%lu",
02422                                         ido2db_db_tablenames[IDO2DB_DBTABLE_DOWNTIMEHISTORY],
02423                                         *(int *) data[1],               /* update start */
02424                                         *(char **) data[4],
02425                                         *(char **) data[5],
02426                                         *(unsigned long *) data[7],
02427                                         *(int *) data[8],
02428                                         *(unsigned long *) data[9],
02429                                         *(char **) data[10],
02430                                         *(char **) data[11],            /* update end */
02431                                         *(unsigned long *) data[0],     /* unique constraint start */
02432                                         *(unsigned long *) data[2],
02433                                         *(char **) data[3],
02434                                         *(unsigned long *) data[6]      /* unique constraint end */
02435                         );
02436 
02437                         /* send query to db */
02438                         result = ido2db_db_query(idi, query1);
02439                         free(query1);
02440 
02441                         /* check result if update was ok */
02442                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
02443                                 /* try insert instead */
02444                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, downtime_type, object_id, entry_time, author_name, comment_data, internal_downtime_id, triggered_by_id, is_fixed, duration, scheduled_start_time, scheduled_end_time) VALUES (%lu, %d, %lu, %s, '%s', '%s', %lu, %lu, %d, %lu, %s, %s)",
02445                                         ido2db_db_tablenames[IDO2DB_DBTABLE_DOWNTIMEHISTORY],
02446                                         *(unsigned long *) data[0],     /* insert start */
02447                                         *(int *) data[1],
02448                                         *(unsigned long *) data[2],
02449                                         *(char **) data[3],
02450                                         *(char **) data[4],
02451                                         *(char **) data[5],
02452                                         *(unsigned long *) data[6],
02453                                         *(unsigned long *) data[7],
02454                                         *(int *) data[8],
02455                                         *(unsigned long *) data[9],
02456                                         *(char **) data[10],
02457                                         *(char **) data[11]             /* insert end */
02458                                 );
02459                                 /* send query to db */
02460                                 result = ido2db_db_query(idi, query2);
02461                                 free(query2);
02462                         }
02463                         break;
02464                 case IDO2DB_DBSERVER_DB2:
02465                         break;
02466                 case IDO2DB_DBSERVER_FIREBIRD:
02467                         break;
02468                 case IDO2DB_DBSERVER_FREETDS:
02469                         break;
02470                 case IDO2DB_DBSERVER_INGRES:
02471                         break;
02472                 case IDO2DB_DBSERVER_MSQL:
02473                         break;
02474                 case IDO2DB_DBSERVER_ORACLE:
02475                         break;
02476                 case IDO2DB_DBSERVER_SQLITE:
02477                         break;
02478                 case IDO2DB_DBSERVER_SQLITE3:
02479                         break;
02480                 default:
02481                         break;
02482         }
02483 #endif
02484 
02485 #ifdef USE_PGSQL /* pgsql */
02486 
02487 #endif
02488 
02489 #ifdef USE_ORACLE /* Oracle ocilib specific */
02490 
02491         /* check if we lost connection, and reconnect */
02492         if(ido2db_db_reconnect(idi)==IDO_ERROR)
02493                 return IDO_ERROR;
02494 
02495                         /* use prepared statements and ocilib */
02496                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimedata_downtime_history, MT(":X1"), (big_uint *) data[0])) {
02497                                 return IDO_ERROR;
02498                         }
02499                         if(!OCI_BindInt(idi->dbinfo.oci_statement_downtimedata_downtime_history, MT(":X2"), (int *) data[1])) {
02500                                 return IDO_ERROR;
02501                         }
02502                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimedata_downtime_history, MT(":X3"), (big_uint *) data[2])) {
02503                                 return IDO_ERROR;
02504                         }
02505                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimedata_downtime_history, MT(":X4"), (big_uint *) data[12])) { /* unixtimestamp instead of time2sql */
02506                                 return IDO_ERROR;
02507                         }
02508         if(*(char **) data[4]==NULL) {
02509                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_downtimedata_downtime_history, ":X5")==IDO_ERROR) {
02510                         return IDO_ERROR;
02511                 }
02512         } else {
02513                         if(!OCI_BindString(idi->dbinfo.oci_statement_downtimedata_downtime_history, MT(":X5"), *(char **) data[4], 0)) {
02514                                 return IDO_ERROR;
02515                         }
02516         }
02517         if(*(char **) data[5]==NULL) {
02518                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_downtimedata_downtime_history, ":X6")==IDO_ERROR) {
02519                         return IDO_ERROR;
02520                 }
02521         } else {
02522                         if(!OCI_BindString(idi->dbinfo.oci_statement_downtimedata_downtime_history, MT(":X6"), *(char **) data[5], 0)) {
02523                                 return IDO_ERROR;
02524                         }
02525         }
02526                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimedata_downtime_history, MT(":X7"), (big_uint *) data[6])) {
02527                                 return IDO_ERROR;
02528                         }
02529                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimedata_downtime_history, MT(":X8"), (big_uint *) data[7])) {
02530                                 return IDO_ERROR;
02531                         }
02532                         if(!OCI_BindInt(idi->dbinfo.oci_statement_downtimedata_downtime_history, MT(":X9"), (int *) data[8])) {
02533                                 return IDO_ERROR;
02534                         }
02535                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimedata_downtime_history, MT(":X10"), (big_uint *) data[9])) {
02536                                 return IDO_ERROR;
02537                         }
02538                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimedata_downtime_history, MT(":X11"), (big_uint *) data[13])) { /* unixtimestamp instead of time2sql */
02539                                 return IDO_ERROR;
02540                         }
02541                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_downtimedata_downtime_history, MT(":X12"), (big_uint *) data[14])) { /* unixtimestamp instead of time2sql */
02542                                 return IDO_ERROR;
02543                         }
02544 
02545                         /* execute statement */
02546                         if(!OCI_Execute(idi->dbinfo.oci_statement_downtimedata_downtime_history)) {
02547                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_downtimedata_downtime_history() execute error\n");
02548                                 return IDO_ERROR;
02549                         }
02550 
02551                         /* commit statement */
02552                         OCI_Commit(idi->dbinfo.oci_connection);
02553 
02554                         /* do not free statement yet! */
02555 #endif
02556         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_downtimedata_downtime_history_add() end\n");
02557 
02558         return result;
02559 }
02560 
02561 
02562 
02563 /************************************/
02564 /* PROGRAMSTATUS                    */
02565 /************************************/
02566 
02567 int ido2db_query_insert_or_update_programstatusdata_add(ido2db_idi *idi, void **data) {
02568         int result = IDO_OK;
02569 #ifdef USE_LIBDBI
02570         char * query1 = NULL;
02571         char * query2 = NULL;
02572 #endif
02573         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_programstatusdata_add() start\n");
02574 
02575         if (idi == NULL)
02576                 return IDO_ERROR;
02577 
02578         if (idi->dbinfo.connected == IDO_FALSE)
02579                 return IDO_ERROR;
02580 
02581 #ifdef USE_LIBDBI /* everything else will be libdbi */
02582         switch (idi->dbinfo.server_type) {
02583                 case IDO2DB_DBSERVER_MYSQL:
02584                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, status_update_time, program_start_time, is_currently_running, process_id, daemon_mode, last_command_check, last_log_rotation, notifications_enabled, active_service_checks_enabled, passive_service_checks_enabled, active_host_checks_enabled, passive_host_checks_enabled, event_handlers_enabled, flap_detection_enabled, failure_prediction_enabled, process_performance_data, obsess_over_hosts, obsess_over_services, modified_host_attributes, modified_service_attributes, global_host_event_handler, global_service_event_handler) VALUES (%lu, %s, %s, '1', %lu, %d, %s, %s, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %lu, %lu, '%s', '%s') ON DUPLICATE KEY UPDATE status_update_time=%s, program_start_time=%s, is_currently_running=1, process_id=%lu, daemon_mode=%d, last_command_check=%s, last_log_rotation=%s, notifications_enabled=%d, active_service_checks_enabled=%d, passive_service_checks_enabled=%d, active_host_checks_enabled=%d, passive_host_checks_enabled=%d, event_handlers_enabled=%d, flap_detection_enabled=%d, failure_prediction_enabled=%d, process_performance_data=%d, obsess_over_hosts=%d, obsess_over_services=%d, modified_host_attributes=%lu, modified_service_attributes=%lu, global_host_event_handler='%s', global_service_event_handler='%s'",
02585                                         ido2db_db_tablenames[IDO2DB_DBTABLE_PROGRAMSTATUS],
02586                                         *(unsigned long *) data[0],     /* insert start */
02587                                         *(char **) data[1],
02588                                         *(char **) data[2],
02589                                         *(unsigned long *) data[3],
02590                                         *(int *) data[4],
02591                                         *(char **) data[5],
02592                                         *(char **) data[6],
02593                                         *(int *) data[7],
02594                                         *(int *) data[8],
02595                                         *(int *) data[9],
02596                                         *(int *) data[10],
02597                                         *(int *) data[11],
02598                                         *(int *) data[12],
02599                                         *(int *) data[13],
02600                                         *(int *) data[14],
02601                                         *(int *) data[15],
02602                                         *(int *) data[16],
02603                                         *(int *) data[17],
02604                                         *(unsigned long *) data[18],
02605                                         *(unsigned long *) data[19],
02606                                         *(char **) data[20],
02607                                         *(char **) data[21],            /* insert end */
02608                                         *(char **) data[1],             /* update start */
02609                                         *(char **) data[2], 
02610                                         *(unsigned long *) data[3],
02611                                         *(int *) data[4],
02612                                         *(char **) data[5],
02613                                         *(char **) data[6],
02614                                         *(int *) data[7],
02615                                         *(int *) data[8],
02616                                         *(int *) data[9],
02617                                         *(int *) data[10],
02618                                         *(int *) data[11],
02619                                         *(int *) data[12],
02620                                         *(int *) data[13],
02621                                         *(int *) data[14],
02622                                         *(int *) data[15],
02623                                         *(int *) data[16],
02624                                         *(int *) data[17],
02625                                         *(unsigned long *) data[18],
02626                                         *(unsigned long *) data[19],
02627                                         *(char **) data[20],
02628                                         *(char **) data[21]            /* update end */
02629                         );
02630                         /* send query to db */
02631                         result = ido2db_db_query(idi, query1);
02632                         free(query1);
02633                         break;
02634                 case IDO2DB_DBSERVER_PGSQL:
02635                         dummy=asprintf(&query1, "UPDATE %s SET status_update_time=%s, program_start_time=%s, is_currently_running=1, process_id=%lu, daemon_mode=%d, last_command_check=%s, last_log_rotation=%s, notifications_enabled=%d, active_service_checks_enabled=%d, passive_service_checks_enabled=%d, active_host_checks_enabled=%d, passive_host_checks_enabled=%d, event_handlers_enabled=%d, flap_detection_enabled=%d, failure_prediction_enabled=%d, process_performance_data=%d, obsess_over_hosts=%d, obsess_over_services=%d, modified_host_attributes=%lu, modified_service_attributes=%lu, global_host_event_handler='%s', global_service_event_handler='%s' WHERE instance_id=%lu",
02636                                         ido2db_db_tablenames[IDO2DB_DBTABLE_PROGRAMSTATUS],
02637                                         *(char **) data[1],             /* update start */
02638                                         *(char **) data[2],
02639                                         *(unsigned long *) data[3],
02640                                         *(int *) data[4],
02641                                         *(char **) data[5],
02642                                         *(char **) data[6],
02643                                         *(int *) data[7],
02644                                         *(int *) data[8],
02645                                         *(int *) data[9],
02646                                         *(int *) data[10],
02647                                         *(int *) data[11],
02648                                         *(int *) data[12],
02649                                         *(int *) data[13],
02650                                         *(int *) data[14],
02651                                         *(int *) data[15],
02652                                         *(int *) data[16],
02653                                         *(int *) data[17],
02654                                         *(unsigned long *) data[18],
02655                                         *(unsigned long *) data[19],
02656                                         *(char **) data[20],
02657                                         *(char **) data[21],            /* update end */
02658                                         *(unsigned long *) data[0]      /* unique constraint start/end */
02659                         );
02660                         /* send query to db */
02661                         result = ido2db_db_query(idi, query1);
02662                         free(query1);
02663 
02664                         /* check result if update was ok */
02665                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
02666                                 /* try insert instead */
02667                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, status_update_time, program_start_time, is_currently_running, process_id, daemon_mode, last_command_check, last_log_rotation, notifications_enabled, active_service_checks_enabled, passive_service_checks_enabled, active_host_checks_enabled, passive_host_checks_enabled, event_handlers_enabled, flap_detection_enabled, failure_prediction_enabled, process_performance_data, obsess_over_hosts, obsess_over_services, modified_host_attributes, modified_service_attributes, global_host_event_handler, global_service_event_handler) VALUES (%lu, %s, %s, '1', %lu, %d, %s, %s, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %lu, %lu, '%s', '%s')",
02668                                         ido2db_db_tablenames[IDO2DB_DBTABLE_PROGRAMSTATUS],
02669                                         *(unsigned long *) data[0],     /* insert start */
02670                                         *(char **) data[1],
02671                                         *(char **) data[2],
02672                                         *(unsigned long *) data[3],
02673                                         *(int *) data[4],
02674                                         *(char **) data[5],
02675                                         *(char **) data[6],
02676                                         *(int *) data[7],
02677                                         *(int *) data[8],
02678                                         *(int *) data[9],
02679                                         *(int *) data[10],
02680                                         *(int *) data[11],
02681                                         *(int *) data[12],
02682                                         *(int *) data[13],
02683                                         *(int *) data[14],
02684                                         *(int *) data[15],
02685                                         *(int *) data[16],
02686                                         *(int *) data[17],
02687                                         *(unsigned long *) data[18],
02688                                         *(unsigned long *) data[19],
02689                                         *(char **) data[20],
02690                                         *(char **) data[21]             /* insert end */
02691                                 );
02692                                 /* send query to db */
02693                                 result = ido2db_db_query(idi, query2);
02694                                 free(query2);
02695                         }
02696                         break;
02697                 case IDO2DB_DBSERVER_DB2:
02698                         break;
02699                 case IDO2DB_DBSERVER_FIREBIRD:
02700                         break;
02701                 case IDO2DB_DBSERVER_FREETDS:
02702                         break;
02703                 case IDO2DB_DBSERVER_INGRES:
02704                         break;
02705                 case IDO2DB_DBSERVER_MSQL:
02706                         break;
02707                 case IDO2DB_DBSERVER_ORACLE:
02708                         break;
02709                 case IDO2DB_DBSERVER_SQLITE:
02710                         break;
02711                 case IDO2DB_DBSERVER_SQLITE3:
02712                         break;
02713                 default:
02714                         break;
02715         }
02716 #endif
02717 
02718 #ifdef USE_PGSQL /* pgsql */
02719 
02720 #endif
02721 
02722 #ifdef USE_ORACLE /* Oracle ocilib specific */
02723 
02724         /* check if we lost connection, and reconnect */
02725         if(ido2db_db_reconnect(idi)==IDO_ERROR)
02726                 return IDO_ERROR;
02727 
02728                         /* bind params to prepared statement */
02729                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_programstatus, MT(":X1"), (big_uint *) data[0])) {
02730                                 return IDO_ERROR;
02731                         }
02732                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_programstatus, MT(":X2"), (big_uint *) data[22])) { /* unixtimestamp instead of time2sql */
02733                                 return IDO_ERROR;
02734                         }
02735                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_programstatus, MT(":X3"), (big_uint *) data[23])) { /* unixtimestamp instead of time2sql */
02736                                 return IDO_ERROR;
02737                         }
02738                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_programstatus, MT(":X4"), (big_uint *) data[3])) {
02739                                 return IDO_ERROR;
02740                         }
02741                         if(!OCI_BindInt(idi->dbinfo.oci_statement_programstatus, MT(":X5"), (int *) data[4])) {
02742                                 return IDO_ERROR;
02743                         }
02744                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_programstatus, MT(":X6"), (big_uint *) data[24])) { /* unixtimestamp instead of time2sql */
02745                                 return IDO_ERROR;
02746                         }
02747                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_programstatus, MT(":X7"), (big_uint *) data[25])) { /* unixtimestamp instead of time2sql */
02748                                 return IDO_ERROR;
02749                         }
02750                         if(!OCI_BindInt(idi->dbinfo.oci_statement_programstatus, MT(":X8"), (int *) data[7])) {
02751                                 return IDO_ERROR;
02752                         }
02753                         if(!OCI_BindInt(idi->dbinfo.oci_statement_programstatus, MT(":X9"), (int *) data[8])) {
02754                                 return IDO_ERROR;
02755                         }
02756                         if(!OCI_BindInt(idi->dbinfo.oci_statement_programstatus, MT(":X10"), (int *) data[9])) {
02757                                 return IDO_ERROR;
02758                         }
02759                         if(!OCI_BindInt(idi->dbinfo.oci_statement_programstatus, MT(":X11"), (int *) data[10])) {
02760                                 return IDO_ERROR;
02761                         }
02762                         if(!OCI_BindInt(idi->dbinfo.oci_statement_programstatus, MT(":X12"), (int *) data[11])) {
02763                                 return IDO_ERROR;
02764                         }
02765                         if(!OCI_BindInt(idi->dbinfo.oci_statement_programstatus, MT(":X13"), (int *) data[12])) {
02766                                 return IDO_ERROR;
02767                         }
02768                         if(!OCI_BindInt(idi->dbinfo.oci_statement_programstatus, MT(":X14"), (int *) data[13])) {
02769                                 return IDO_ERROR;
02770                         }
02771                         if(!OCI_BindInt(idi->dbinfo.oci_statement_programstatus, MT(":X15"), (int *) data[14])) {
02772                                 return IDO_ERROR;
02773                         }
02774                         if(!OCI_BindInt(idi->dbinfo.oci_statement_programstatus, MT(":X16"), (int *) data[15])) {
02775                                 return IDO_ERROR;
02776                         }
02777                         if(!OCI_BindInt(idi->dbinfo.oci_statement_programstatus, MT(":X17"), (int *) data[16])) {
02778                                 return IDO_ERROR;
02779                         }
02780                         if(!OCI_BindInt(idi->dbinfo.oci_statement_programstatus, MT(":X18"), (int *) data[17])) {
02781                                 return IDO_ERROR;
02782                         }
02783                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_programstatus, MT(":X19"), (big_uint *) data[18])) {
02784                                 return IDO_ERROR;
02785                         }
02786                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_programstatus, MT(":X20"), (big_uint *) data[19])) {
02787                                 return IDO_ERROR;
02788                         }
02789         if(*(char **) data[20]==NULL) {
02790                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_programstatus, ":X21")==IDO_ERROR) {
02791                         return IDO_ERROR;
02792                 }
02793         } else {
02794                         if(!OCI_BindString(idi->dbinfo.oci_statement_programstatus, MT(":X21"), *(char **) data[20], 0)) {
02795                                 return IDO_ERROR;
02796                         }
02797         }
02798         if(*(char **) data[21]==NULL) {
02799                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_programstatus, ":X22")==IDO_ERROR) {
02800                         return IDO_ERROR;
02801                 }
02802         } else {
02803                         if(!OCI_BindString(idi->dbinfo.oci_statement_programstatus, MT(":X22"), *(char **) data[21], 0)) {
02804                                 return IDO_ERROR;
02805                         }
02806         }
02807 
02808                         /* execute statement */
02809                         if(!OCI_Execute(idi->dbinfo.oci_statement_programstatus)) {
02810                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_programstatus() execute error\n");
02811                                 return IDO_ERROR;
02812                         }
02813 
02814                         /* commit statement */
02815                         OCI_Commit(idi->dbinfo.oci_connection);
02816 
02817                         /* do not free statement yet! */
02818 #endif
02819         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_programstatusdata_add() end\n");
02820 
02821         return result;
02822 }
02823 
02824 
02825 /************************************/
02826 /* HOSTSTATUS                       */
02827 /************************************/
02828 
02829 int ido2db_query_insert_or_update_hoststatusdata_add(ido2db_idi *idi, void **data) {
02830         int result = IDO_OK;
02831 #ifdef USE_LIBDBI
02832         char * query1 = NULL;
02833         char * query2 = NULL;
02834 #endif
02835         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hoststatusdata_add() start\n");
02836 
02837         if (idi == NULL)
02838                 return IDO_ERROR;
02839 
02840         if (idi->dbinfo.connected == IDO_FALSE)
02841                 return IDO_ERROR;
02842 
02843 #ifdef USE_LIBDBI /* everything else will be libdbi */
02844         switch (idi->dbinfo.server_type) {
02845                 case IDO2DB_DBSERVER_MYSQL:
02846                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, host_object_id, status_update_time, output, long_output, perfdata, current_state, has_been_checked, should_be_scheduled, current_check_attempt, max_check_attempts, last_check, next_check, check_type, last_state_change, last_hard_state_change, last_hard_state, last_time_up, last_time_down, last_time_unreachable, state_type, last_notification, next_notification, no_more_notifications, notifications_enabled, problem_has_been_acknowledged, acknowledgement_type, current_notification_number, passive_checks_enabled, active_checks_enabled, event_handler_enabled, flap_detection_enabled, is_flapping, percent_state_change, latency, execution_time, scheduled_downtime_depth, failure_prediction_enabled, process_performance_data, obsess_over_host, modified_host_attributes, event_handler, check_command, normal_check_interval, retry_check_interval, check_timeperiod_object_id) VALUES (%lu, %lu, %s, '%s', '%s', '%s', %d, %d, %d, %d, %d, %s, %s, %d, %s, %s, %d, %s, %s, %s, %d, %s, %s, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %lf, %lf, %lf, %d, %d, %d, %d, %lu, '%s', '%s', %lf, %lf, %lu) ON DUPLICATE KEY UPDATE instance_id='%lu', host_object_id='%lu', status_update_time=%s, output='%s', long_output='%s', perfdata='%s', current_state='%d', has_been_checked='%d', should_be_scheduled='%d', current_check_attempt='%d', max_check_attempts='%d', last_check=%s, next_check=%s, check_type='%d', last_state_change=%s, last_hard_state_change=%s, last_hard_state='%d', last_time_up=%s, last_time_down=%s, last_time_unreachable=%s, state_type='%d', last_notification=%s, next_notification=%s, no_more_notifications='%d', notifications_enabled='%d', problem_has_been_acknowledged='%d', acknowledgement_type='%d', current_notification_number='%d', passive_checks_enabled='%d', active_checks_enabled='%d', event_handler_enabled='%d', flap_detection_enabled='%d', is_flapping='%d', percent_state_change='%lf', latency='%lf', execution_time='%lf', scheduled_downtime_depth='%d', failure_prediction_enabled='%d', process_performance_data='%d', obsess_over_host='%d', modified_host_attributes='%lu', event_handler='%s', check_command='%s', normal_check_interval='%lf', retry_check_interval='%lf', check_timeperiod_object_id='%lu'",
02847                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTSTATUS],
02848                                         *(unsigned long *) data[0],     /* insert start */
02849                                         *(unsigned long *) data[1],
02850                                         *(char **) data[2],
02851                                         *(char **) data[3],
02852                                         *(char **) data[4],
02853                                         *(char **) data[5],
02854                                         *(int *) data[6],
02855                                         *(int *) data[7],
02856                                         *(int *) data[8],
02857                                         *(int *) data[9],
02858                                         *(int *) data[10],
02859                                         *(char **) data[11],
02860                                         *(char **) data[12],
02861                                         *(int *) data[13],
02862                                         *(char **) data[14],
02863                                         *(char **) data[15],
02864                                         *(int *) data[16],
02865                                         *(char **) data[17],
02866                                         *(char **) data[18],
02867                                         *(char **) data[19],
02868                                         *(int *) data[20],
02869                                         *(char **) data[21],
02870                                         *(char **) data[22],
02871                                         *(int *) data[23],
02872                                         *(int *) data[24],
02873                                         *(int *) data[25],
02874                                         *(int *) data[26],
02875                                         *(int *) data[27],
02876                                         *(int *) data[28],
02877                                         *(int *) data[29],
02878                                         *(int *) data[30],
02879                                         *(int *) data[31],
02880                                         *(int *) data[32],
02881                                         *(double *) data[33],
02882                                         *(double *) data[34],
02883                                         *(double *) data[35],
02884                                         *(int *) data[36],
02885                                         *(int *) data[37],
02886                                         *(int *) data[38],
02887                                         *(int *) data[39],
02888                                         *(unsigned long *) data[40],
02889                                         *(char **) data[41],
02890                                         *(char **) data[42],
02891                                         *(double *) data[43],
02892                                         *(double *) data[44],
02893                                         *(unsigned long *) data[45],     /* insert end */
02894                                         *(unsigned long *) data[0],     /* update start */
02895                                         *(unsigned long *) data[1],
02896                                         *(char **) data[2],
02897                                         *(char **) data[3],
02898                                         *(char **) data[4],
02899                                         *(char **) data[5],
02900                                         *(int *) data[6],
02901                                         *(int *) data[7],
02902                                         *(int *) data[8],
02903                                         *(int *) data[9],
02904                                         *(int *) data[10],
02905                                         *(char **) data[11],
02906                                         *(char **) data[12],
02907                                         *(int *) data[13],
02908                                         *(char **) data[14],
02909                                         *(char **) data[15],
02910                                         *(int *) data[16],
02911                                         *(char **) data[17],
02912                                         *(char **) data[18],
02913                                         *(char **) data[19],
02914                                         *(int *) data[20],
02915                                         *(char **) data[21],
02916                                         *(char **) data[22],
02917                                         *(int *) data[23],
02918                                         *(int *) data[24],
02919                                         *(int *) data[25],
02920                                         *(int *) data[26],
02921                                         *(int *) data[27],
02922                                         *(int *) data[28],
02923                                         *(int *) data[29],
02924                                         *(int *) data[30],
02925                                         *(int *) data[31],
02926                                         *(int *) data[32],
02927                                         *(double *) data[33],
02928                                         *(double *) data[34],
02929                                         *(double *) data[35],
02930                                         *(int *) data[36],
02931                                         *(int *) data[37],
02932                                         *(int *) data[38],
02933                                         *(int *) data[39],
02934                                         *(unsigned long *) data[40],
02935                                         *(char **) data[41],
02936                                         *(char **) data[42],
02937                                         *(double *) data[43],
02938                                         *(double *) data[44],
02939                                         *(unsigned long *) data[45]     /* update end */
02940                         );
02941                         /* send query to db */
02942                         result = ido2db_db_query(idi, query1);
02943                         free(query1);
02944                         break;
02945                 case IDO2DB_DBSERVER_PGSQL:
02946                         dummy=asprintf(&query1, "UPDATE %s SET instance_id='%lu', host_object_id='%lu', status_update_time=%s, output='%s', long_output='%s', perfdata='%s', current_state='%d', has_been_checked='%d', should_be_scheduled='%d', current_check_attempt='%d', max_check_attempts='%d', last_check=%s, next_check=%s, check_type='%d', last_state_change=%s, last_hard_state_change=%s, last_hard_state='%d', last_time_up=%s, last_time_down=%s, last_time_unreachable=%s, state_type='%d', last_notification=%s, next_notification=%s, no_more_notifications='%d', notifications_enabled='%d', problem_has_been_acknowledged='%d', acknowledgement_type='%d', current_notification_number='%d', passive_checks_enabled='%d', active_checks_enabled='%d', event_handler_enabled='%d', flap_detection_enabled='%d', is_flapping='%d', percent_state_change='%lf', latency='%lf', execution_time='%lf', scheduled_downtime_depth='%d', failure_prediction_enabled='%d', process_performance_data='%d', obsess_over_host='%d', modified_host_attributes='%lu', event_handler='%s', check_command='%s', normal_check_interval='%lf', retry_check_interval='%lf', check_timeperiod_object_id='%lu' WHERE host_object_id=%lu",
02947                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTSTATUS],
02948                                         *(unsigned long *) data[0],     /* update start */
02949                                         *(unsigned long *) data[1],
02950                                         *(char **) data[2],
02951                                         *(char **) data[3],
02952                                         *(char **) data[4],
02953                                         *(char **) data[5],
02954                                         *(int *) data[6],
02955                                         *(int *) data[7],
02956                                         *(int *) data[8],
02957                                         *(int *) data[9],
02958                                         *(int *) data[10],
02959                                         *(char **) data[11],
02960                                         *(char **) data[12],
02961                                         *(int *) data[13],
02962                                         *(char **) data[14],
02963                                         *(char **) data[15],
02964                                         *(int *) data[16],
02965                                         *(char **) data[17],
02966                                         *(char **) data[18],
02967                                         *(char **) data[19],
02968                                         *(int *) data[20],
02969                                         *(char **) data[21],
02970                                         *(char **) data[22],
02971                                         *(int *) data[23],
02972                                         *(int *) data[24],
02973                                         *(int *) data[25],
02974                                         *(int *) data[26],
02975                                         *(int *) data[27],
02976                                         *(int *) data[28],
02977                                         *(int *) data[29],
02978                                         *(int *) data[30],
02979                                         *(int *) data[31],
02980                                         *(int *) data[32],
02981                                         *(double *) data[33],
02982                                         *(double *) data[34],
02983                                         *(double *) data[35],
02984                                         *(int *) data[36],
02985                                         *(int *) data[37],
02986                                         *(int *) data[38],
02987                                         *(int *) data[39],
02988                                         *(unsigned long *) data[40],
02989                                         *(char **) data[41],
02990                                         *(char **) data[42],
02991                                         *(double *) data[43],
02992                                         *(double *) data[44],
02993                                         *(unsigned long *) data[45],     /* update end */
02994                                         *(unsigned long *) data[1]     /* unique constraint start/end */
02995                         );
02996                         /* send query to db */
02997                         result = ido2db_db_query(idi, query1);
02998                         free(query1);
02999 
03000                         /* check result if update was ok */
03001                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
03002                                 /* try insert instead */
03003                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, host_object_id, status_update_time, output, long_output, perfdata, current_state, has_been_checked, should_be_scheduled, current_check_attempt, max_check_attempts, last_check, next_check, check_type, last_state_change, last_hard_state_change, last_hard_state, last_time_up, last_time_down, last_time_unreachable, state_type, last_notification, next_notification, no_more_notifications, notifications_enabled, problem_has_been_acknowledged, acknowledgement_type, current_notification_number, passive_checks_enabled, active_checks_enabled, event_handler_enabled, flap_detection_enabled, is_flapping, percent_state_change, latency, execution_time, scheduled_downtime_depth, failure_prediction_enabled, process_performance_data, obsess_over_host, modified_host_attributes, event_handler, check_command, normal_check_interval, retry_check_interval, check_timeperiod_object_id) VALUES (%lu, %lu, %s, '%s', '%s', '%s', %d, %d, %d, %d, %d, %s, %s, %d, %s, %s, %d, %s, %s, %s, %d, %s, %s, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %lf, %lf, %lf, %d, %d, %d, %d, %lu, '%s', '%s', %lf, %lf, %lu)",
03004                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTSTATUS],
03005                                         *(unsigned long *) data[0],     /* insert start */
03006                                         *(unsigned long *) data[1],
03007                                         *(char **) data[2],
03008                                         *(char **) data[3],
03009                                         *(char **) data[4],
03010                                         *(char **) data[5],
03011                                         *(int *) data[6],
03012                                         *(int *) data[7],
03013                                         *(int *) data[8],
03014                                         *(int *) data[9],
03015                                         *(int *) data[10],
03016                                         *(char **) data[11],
03017                                         *(char **) data[12],
03018                                         *(int *) data[13],
03019                                         *(char **) data[14],
03020                                         *(char **) data[15],
03021                                         *(int *) data[16],
03022                                         *(char **) data[17],
03023                                         *(char **) data[18],
03024                                         *(char **) data[19],
03025                                         *(int *) data[20],
03026                                         *(char **) data[21],
03027                                         *(char **) data[22],
03028                                         *(int *) data[23],
03029                                         *(int *) data[24],
03030                                         *(int *) data[25],
03031                                         *(int *) data[26],
03032                                         *(int *) data[27],
03033                                         *(int *) data[28],
03034                                         *(int *) data[29],
03035                                         *(int *) data[30],
03036                                         *(int *) data[31],
03037                                         *(int *) data[32],
03038                                         *(double *) data[33],
03039                                         *(double *) data[34],
03040                                         *(double *) data[35],
03041                                         *(int *) data[36],
03042                                         *(int *) data[37],
03043                                         *(int *) data[38],
03044                                         *(int *) data[39],
03045                                         *(unsigned long *) data[40],
03046                                         *(char **) data[41],
03047                                         *(char **) data[42],
03048                                         *(double *) data[43],
03049                                         *(double *) data[44],
03050                                         *(unsigned long *) data[45]     /* insert end */
03051                                 );
03052                                 /* send query to db */
03053                                 result = ido2db_db_query(idi, query2);
03054                                 free(query2);
03055                         }
03056                         break;
03057                 case IDO2DB_DBSERVER_DB2:
03058                         break;
03059                 case IDO2DB_DBSERVER_FIREBIRD:
03060                         break;
03061                 case IDO2DB_DBSERVER_FREETDS:
03062                         break;
03063                 case IDO2DB_DBSERVER_INGRES:
03064                         break;
03065                 case IDO2DB_DBSERVER_MSQL:
03066                         break;
03067                 case IDO2DB_DBSERVER_ORACLE:
03068                         break;
03069                 case IDO2DB_DBSERVER_SQLITE:
03070                         break;
03071                 case IDO2DB_DBSERVER_SQLITE3:
03072                         break;
03073                 default:
03074                         break;
03075         }
03076 #endif
03077 
03078 #ifdef USE_PGSQL /* pgsql */
03079 
03080 #endif
03081 
03082 #ifdef USE_ORACLE /* Oracle ocilib specific */
03083 
03084         /* check if we lost connection, and reconnect */
03085         if(ido2db_db_reconnect(idi)==IDO_ERROR)
03086                 return IDO_ERROR;
03087 
03088                         /* bind params to prepared statement */ 
03089                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hoststatus, MT(":X1"), (big_uint *) data[0])) {
03090                                 return IDO_ERROR;
03091                         }
03092                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hoststatus, MT(":X2"), (big_uint *) data[1])) {
03093                                 return IDO_ERROR;
03094                         }
03095                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hoststatus, MT(":X3"), (big_uint *) data[46])) { /* unixtimestamp instead of time2sql */
03096                                 return IDO_ERROR;
03097                         }
03098         if(*(char **) data[3]==NULL) {
03099                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hoststatus, ":X4")==IDO_ERROR) {
03100                         return IDO_ERROR;
03101                 }
03102         } else {
03103                         if(!OCI_BindString(idi->dbinfo.oci_statement_hoststatus, MT(":X4"), *(char **) data[3], 0)) {
03104                                 return IDO_ERROR;
03105                         }
03106         }
03107         if(*(char **) data[4]==NULL) {
03108                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hoststatus, ":X5")==IDO_ERROR) {
03109                         return IDO_ERROR;
03110                 }
03111         } else {
03112                         if(!OCI_BindString(idi->dbinfo.oci_statement_hoststatus, MT(":X5"), *(char **) data[4], 0)) {
03113                                 return IDO_ERROR;
03114                         }
03115         }
03116         if(*(char **) data[5]==NULL) {
03117                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hoststatus, ":X6")==IDO_ERROR) {
03118                         return IDO_ERROR;
03119                 }
03120         } else {
03121                         if(!OCI_BindString(idi->dbinfo.oci_statement_hoststatus, MT(":X6"), *(char **) data[5], 0)) {
03122                                 return IDO_ERROR;
03123                         }
03124         }
03125                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X7"), (int *) data[6])) {
03126                                 return IDO_ERROR;
03127                         }
03128                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X8"), (int *) data[7])) {
03129                                 return IDO_ERROR;
03130                         }
03131                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X9"), (int *) data[8])) {
03132                                 return IDO_ERROR;
03133                         }
03134                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X10"), (int *) data[9])) {
03135                                 return IDO_ERROR;
03136                         }
03137                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X11"), (int *) data[10])) {
03138                                 return IDO_ERROR;
03139                         }
03140                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hoststatus, MT(":X12"), (big_uint *) data[47])) { /* unixtimestamp instead of time2sql */
03141                                 return IDO_ERROR;
03142                         }
03143                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hoststatus, MT(":X13"), (big_uint *) data[48])) { /* unixtimestamp instead of time2sql */
03144                                 return IDO_ERROR;
03145                         }
03146                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X14"), (int *) data[13])) {
03147                                 return IDO_ERROR;
03148                         }
03149                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hoststatus, MT(":X15"), (big_uint *) data[49])) { /* unixtimestamp instead of time2sql */
03150                                 return IDO_ERROR;
03151                         }
03152                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hoststatus, MT(":X16"), (big_uint *) data[50])) { /* unixtimestamp instead of time2sql */
03153                                 return IDO_ERROR;
03154                         }
03155                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X17"), (int *) data[16])) {
03156                                 return IDO_ERROR;
03157                         }
03158                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hoststatus, MT(":X18"), (big_uint *) data[51])) { /* unixtimestamp instead of time2sql */
03159                                 return IDO_ERROR;
03160                         }
03161                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hoststatus, MT(":X19"), (big_uint *) data[52])) { /* unixtimestamp instead of time2sql */
03162                                 return IDO_ERROR;
03163                         }
03164                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hoststatus, MT(":X20"), (big_uint *) data[53])) { /* unixtimestamp instead of time2sql */
03165                                 return IDO_ERROR;
03166                         }
03167                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X21"), (int *) data[20])) {
03168                                 return IDO_ERROR;
03169                         }
03170                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hoststatus, MT(":X22"), (big_uint *) data[54])) { /* unixtimestamp instead of time2sql */
03171                                 return IDO_ERROR;
03172                         }
03173                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hoststatus, MT(":X23"), (big_uint *) data[55])) { /* unixtimestamp instead of time2sql */
03174                                 return IDO_ERROR;
03175                         }
03176                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X24"), (int *) data[23])) {
03177                                 return IDO_ERROR;
03178                         }
03179                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X25"), (int *) data[24])) {
03180                                 return IDO_ERROR;
03181                         }
03182                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X26"), (int *) data[25])) {
03183                                 return IDO_ERROR;
03184                         }
03185                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X27"), (int *) data[26])) {
03186                                 return IDO_ERROR;
03187                         }
03188                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X28"), (int *) data[27])) {
03189                                 return IDO_ERROR;
03190                         }
03191                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X29"), (int *) data[28])) {
03192                                 return IDO_ERROR;
03193                         }
03194                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X30"), (int *) data[29])) {
03195                                 return IDO_ERROR;
03196                         }
03197                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X31"), (int *) data[30])) {
03198                                 return IDO_ERROR;
03199                         }
03200                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X32"), (int *) data[31])) {
03201                                 return IDO_ERROR;
03202                         }
03203                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X33"), (int *) data[32])) {
03204                                 return IDO_ERROR;
03205                         }
03206                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_hoststatus, MT(":X34"), (double *) data[33])) {
03207                                 return IDO_ERROR;
03208                         }
03209                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_hoststatus, MT(":X35"), (double *) data[34])) {
03210                                 return IDO_ERROR;
03211                         }
03212                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_hoststatus, MT(":X36"), (double *) data[35])) {
03213                                 return IDO_ERROR;
03214                         }
03215                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X37"), (int *) data[36])) {
03216                                 return IDO_ERROR;
03217                         }
03218                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X38"), (int *) data[37])) {
03219                                 return IDO_ERROR;
03220                         }
03221                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X39"), (int *) data[38])) {
03222                                 return IDO_ERROR;
03223                         }
03224                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hoststatus, MT(":X40"), (int *) data[39])) {
03225                                 return IDO_ERROR;
03226                         }
03227                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hoststatus, MT(":X41"), (big_uint *) data[40])) {
03228                                 return IDO_ERROR;
03229                         }
03230         if(*(char **) data[41]==NULL) {
03231                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hoststatus, ":X42")==IDO_ERROR) {
03232                         return IDO_ERROR;
03233                 }
03234         } else {
03235                         if(!OCI_BindString(idi->dbinfo.oci_statement_hoststatus, MT(":X42"), *(char **) data[41], 0)) {
03236                                 return IDO_ERROR;
03237                         }
03238         }
03239         if(*(char **) data[42]==NULL) {
03240                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hoststatus, ":X43")==IDO_ERROR) {
03241                         return IDO_ERROR;
03242                 }
03243         } else {
03244                         if(!OCI_BindString(idi->dbinfo.oci_statement_hoststatus, MT(":X43"), *(char **) data[42], 0)) {
03245                                 return IDO_ERROR;
03246                         }
03247         }
03248                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_hoststatus, MT(":X44"), (double *) data[43])) {
03249                                 return IDO_ERROR;
03250                         }
03251                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_hoststatus, MT(":X45"), (double *) data[44])) {
03252                                 return IDO_ERROR;
03253                         }
03254                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hoststatus, MT(":X46"), (big_uint *) data[45])) {
03255                                 return IDO_ERROR;
03256                         }
03257 
03258                         /* execute statement */
03259                         if(!OCI_Execute(idi->dbinfo.oci_statement_hoststatus)) {
03260                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hoststatus() execute error\n");
03261                                 return IDO_ERROR;
03262                         }
03263 
03264                         /* commit statement */
03265                         OCI_Commit(idi->dbinfo.oci_connection);
03266 
03267                         /* do not free statement yet! */
03268 #endif
03269         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hoststatusdata_add() end\n");
03270 
03271         return result;
03272 }
03273 
03274 /************************************/
03275 /* SERVICESTATUS                    */
03276 /************************************/
03277 
03278 int ido2db_query_insert_or_update_servicestatusdata_add(ido2db_idi *idi, void **data) {
03279         int result = IDO_OK;
03280 #ifdef USE_LIBDBI
03281         char * query1 = NULL;
03282         char * query2 = NULL;
03283 #endif
03284         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_servicestatusdata_add() start\n");
03285 
03286         if (idi == NULL)
03287                 return IDO_ERROR;
03288 
03289         if (idi->dbinfo.connected == IDO_FALSE)
03290                 return IDO_ERROR;
03291 
03292 #ifdef USE_LIBDBI /* everything else will be libdbi */
03293         switch (idi->dbinfo.server_type) {
03294                 case IDO2DB_DBSERVER_MYSQL:
03295                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, service_object_id, status_update_time, output, long_output, perfdata, current_state, has_been_checked, should_be_scheduled, current_check_attempt, max_check_attempts, last_check, next_check, check_type, last_state_change, last_hard_state_change, last_hard_state, last_time_ok, last_time_warning, last_time_unknown, last_time_critical, state_type, last_notification, next_notification, no_more_notifications, notifications_enabled, problem_has_been_acknowledged, acknowledgement_type, current_notification_number, passive_checks_enabled, active_checks_enabled, event_handler_enabled, flap_detection_enabled, is_flapping, percent_state_change, latency, execution_time, scheduled_downtime_depth, failure_prediction_enabled, process_performance_data, obsess_over_service, modified_service_attributes, event_handler, check_command, normal_check_interval, retry_check_interval, check_timeperiod_object_id) VALUES ('%lu', '%lu', %s, '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d', %s, %s, '%d', %s, %s, '%d', %s, %s, %s, %s, '%d', %s, %s, '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%lf', '%lf', '%lf', '%d', '%d', '%d', '%d', '%lu', '%s', '%s', '%lf', '%lf', '%lu') ON DUPLICATE KEY UPDATE instance_id='%lu', service_object_id='%lu', status_update_time=%s, output='%s', long_output='%s', perfdata='%s', current_state='%d', has_been_checked='%d', should_be_scheduled='%d', current_check_attempt='%d', max_check_attempts='%d', last_check=%s, next_check=%s, check_type=%d, last_state_change=%s, last_hard_state_change=%s, last_hard_state='%d', last_time_ok=%s, last_time_warning=%s, last_time_unknown=%s, last_time_critical=%s, state_type='%d', last_notification=%s, next_notification=%s, no_more_notifications='%d', notifications_enabled='%d', problem_has_been_acknowledged='%d', acknowledgement_type='%d', current_notification_number='%d', passive_checks_enabled='%d', active_checks_enabled='%d', event_handler_enabled='%d', flap_detection_enabled='%d', is_flapping='%d', percent_state_change='%lf', latency='%lf', execution_time='%lf', scheduled_downtime_depth='%d', failure_prediction_enabled='%d', process_performance_data='%d', obsess_over_service='%d', modified_service_attributes='%lu', event_handler='%s', check_command='%s', normal_check_interval='%lf', retry_check_interval='%lf', check_timeperiod_object_id='%lu'",
03296                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICESTATUS],
03297                                         *(unsigned long *) data[0],     /* insert start */
03298                                         *(unsigned long *) data[1],
03299                                         *(char **) data[2],
03300                                         *(char **) data[3],
03301                                         *(char **) data[4],
03302                                         *(char **) data[5],
03303                                         *(int *) data[6],
03304                                         *(int *) data[7],
03305                                         *(int *) data[8],
03306                                         *(int *) data[9],
03307                                         *(int *) data[10],
03308                                         *(char **) data[11],
03309                                         *(char **) data[12],
03310                                         *(int *) data[13],
03311                                         *(char **) data[14],
03312                                         *(char **) data[15],
03313                                         *(int *) data[16],
03314                                         *(char **) data[17],
03315                                         *(char **) data[18],
03316                                         *(char **) data[19],
03317                                         *(char **) data[20],
03318                                         *(int *) data[21],
03319                                         *(char **) data[22],
03320                                         *(char **) data[23],
03321                                         *(int *) data[24],
03322                                         *(int *) data[25],
03323                                         *(int *) data[26],
03324                                         *(int *) data[27],
03325                                         *(int *) data[28],
03326                                         *(int *) data[29],
03327                                         *(int *) data[30],
03328                                         *(int *) data[31],
03329                                         *(int *) data[32],
03330                                         *(int *) data[33],
03331                                         *(double *) data[34],
03332                                         *(double *) data[35],
03333                                         *(double *) data[36],
03334                                         *(int *) data[37],
03335                                         *(int *) data[38],
03336                                         *(int *) data[39],
03337                                         *(int *) data[40],
03338                                         *(unsigned long *) data[41],
03339                                         *(char **) data[42],
03340                                         *(char **) data[43],
03341                                         *(double *) data[44],
03342                                         *(double *) data[45],
03343                                         *(unsigned long *) data[46],     /* insert end */
03344                                         *(unsigned long *) data[0],     /* update start */
03345                                         *(unsigned long *) data[1],
03346                                         *(char **) data[2],
03347                                         *(char **) data[3],
03348                                         *(char **) data[4],
03349                                         *(char **) data[5],
03350                                         *(int *) data[6],
03351                                         *(int *) data[7],
03352                                         *(int *) data[8],
03353                                         *(int *) data[9],
03354                                         *(int *) data[10],
03355                                         *(char **) data[11],
03356                                         *(char **) data[12],
03357                                         *(int *) data[13],
03358                                         *(char **) data[14],
03359                                         *(char **) data[15],
03360                                         *(int *) data[16],
03361                                         *(char **) data[17],
03362                                         *(char **) data[18],
03363                                         *(char **) data[19],
03364                                         *(char **) data[20],
03365                                         *(int *) data[21],
03366                                         *(char **) data[22],
03367                                         *(char **) data[23],
03368                                         *(int *) data[24],
03369                                         *(int *) data[25],
03370                                         *(int *) data[26],
03371                                         *(int *) data[27],
03372                                         *(int *) data[28],
03373                                         *(int *) data[29],
03374                                         *(int *) data[30],
03375                                         *(int *) data[31],
03376                                         *(int *) data[32],
03377                                         *(int *) data[33],
03378                                         *(double *) data[34],
03379                                         *(double *) data[35],
03380                                         *(double *) data[36],
03381                                         *(int *) data[37],
03382                                         *(int *) data[38],
03383                                         *(int *) data[39],
03384                                         *(int *) data[40],
03385                                         *(unsigned long *) data[41],
03386                                         *(char **) data[42],   
03387                                         *(char **) data[43],
03388                                         *(double *) data[44],
03389                                         *(double *) data[45],
03390                                         *(unsigned long *) data[46]     /* update end */                       
03391                         );
03392                         /* send query to db */
03393                         result = ido2db_db_query(idi, query1);
03394                         free(query1);
03395                         break;
03396                 case IDO2DB_DBSERVER_PGSQL:
03397                         dummy=asprintf(&query1, "UPDATE %s SET instance_id='%lu', service_object_id='%lu', status_update_time=%s, output='%s', long_output='%s', perfdata='%s', current_state='%d', has_been_checked='%d', should_be_scheduled='%d', current_check_attempt='%d', max_check_attempts='%d', last_check=%s, next_check=%s, check_type='%d', last_state_change=%s, last_hard_state_change=%s, last_hard_state='%d', last_time_ok=%s, last_time_warning=%s, last_time_unknown=%s, last_time_critical=%s, state_type='%d', last_notification=%s, next_notification=%s, no_more_notifications='%d', notifications_enabled='%d', problem_has_been_acknowledged='%d', acknowledgement_type='%d', current_notification_number='%d', passive_checks_enabled='%d', active_checks_enabled='%d', event_handler_enabled='%d', flap_detection_enabled='%d', is_flapping='%d', percent_state_change='%lf', latency='%lf', execution_time='%lf', scheduled_downtime_depth='%d', failure_prediction_enabled='%d', process_performance_data='%d', obsess_over_service='%d', modified_service_attributes='%lu', event_handler='%s', check_command='%s', normal_check_interval='%lf', retry_check_interval='%lf', check_timeperiod_object_id='%lu' WHERE service_object_id='%lu'",
03398                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICESTATUS],
03399                                         *(unsigned long *) data[0],     /* update start */
03400                                         *(unsigned long *) data[1],
03401                                         *(char **) data[2],
03402                                         *(char **) data[3],
03403                                         *(char **) data[4],
03404                                         *(char **) data[5],
03405                                         *(int *) data[6],
03406                                         *(int *) data[7],
03407                                         *(int *) data[8],
03408                                         *(int *) data[9],
03409                                         *(int *) data[10],
03410                                         *(char **) data[11],
03411                                         *(char **) data[12],
03412                                         *(int *) data[13],
03413                                         *(char **) data[14],
03414                                         *(char **) data[15],
03415                                         *(int *) data[16],
03416                                         *(char **) data[17],
03417                                         *(char **) data[18],
03418                                         *(char **) data[19],
03419                                         *(char **) data[20],
03420                                         *(int *) data[21],
03421                                         *(char **) data[22],
03422                                         *(char **) data[23],
03423                                         *(int *) data[24],
03424                                         *(int *) data[25],
03425                                         *(int *) data[26],
03426                                         *(int *) data[27],
03427                                         *(int *) data[28],
03428                                         *(int *) data[29],
03429                                         *(int *) data[30],
03430                                         *(int *) data[31],
03431                                         *(int *) data[32],
03432                                         *(int *) data[33],
03433                                         *(double *) data[34],
03434                                         *(double *) data[35],
03435                                         *(double *) data[36],
03436                                         *(int *) data[37],
03437                                         *(int *) data[38],
03438                                         *(int *) data[39],
03439                                         *(int *) data[40],
03440                                         *(unsigned long *) data[41],
03441                                         *(char **) data[42],   
03442                                         *(char **) data[43],
03443                                         *(double *) data[44],
03444                                         *(double *) data[45],
03445                                         *(unsigned long *) data[46],     /* update end */
03446                                         *(unsigned long *) data[1]     /* unique constraint start/end */
03447                         );
03448 
03449                         /* send query to db */
03450                         result = ido2db_db_query(idi, query1);
03451                         free(query1);
03452 
03453                         /* check result if update was ok */
03454                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
03455                                 /* try insert instead */
03456                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, service_object_id, status_update_time, output, long_output, perfdata, current_state, has_been_checked, should_be_scheduled, current_check_attempt, max_check_attempts, last_check, next_check, check_type, last_state_change, last_hard_state_change, last_hard_state, last_time_ok, last_time_warning, last_time_unknown, last_time_critical, state_type, last_notification, next_notification, no_more_notifications, notifications_enabled, problem_has_been_acknowledged, acknowledgement_type, current_notification_number, passive_checks_enabled, active_checks_enabled, event_handler_enabled, flap_detection_enabled, is_flapping, percent_state_change, latency, execution_time, scheduled_downtime_depth, failure_prediction_enabled, process_performance_data, obsess_over_service, modified_service_attributes, event_handler, check_command, normal_check_interval, retry_check_interval, check_timeperiod_object_id) VALUES ('%lu', '%lu', %s, '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d', %s, %s, '%d', %s, %s, '%d', %s, %s, %s, %s, '%d', %s, %s, '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%lf', '%lf', '%lf', '%d', '%d', '%d', '%d', '%lu', '%s', '%s', '%lf', '%lf', '%lu')",
03457                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICESTATUS],
03458                                         *(unsigned long *) data[0],     /* insert start */
03459                                         *(unsigned long *) data[1],
03460                                         *(char **) data[2],
03461                                         *(char **) data[3],
03462                                         *(char **) data[4],
03463                                         *(char **) data[5],
03464                                         *(int *) data[6],
03465                                         *(int *) data[7],
03466                                         *(int *) data[8],
03467                                         *(int *) data[9],
03468                                         *(int *) data[10],
03469                                         *(char **) data[11],
03470                                         *(char **) data[12],
03471                                         *(int *) data[13],
03472                                         *(char **) data[14],
03473                                         *(char **) data[15],
03474                                         *(int *) data[16],
03475                                         *(char **) data[17],
03476                                         *(char **) data[18],
03477                                         *(char **) data[19],
03478                                         *(char **) data[20],
03479                                         *(int *) data[21],
03480                                         *(char **) data[22],
03481                                         *(char **) data[23],
03482                                         *(int *) data[24],
03483                                         *(int *) data[25],
03484                                         *(int *) data[26],
03485                                         *(int *) data[27],
03486                                         *(int *) data[28],
03487                                         *(int *) data[29],
03488                                         *(int *) data[30],
03489                                         *(int *) data[31],
03490                                         *(int *) data[32],
03491                                         *(int *) data[33],
03492                                         *(double *) data[34],
03493                                         *(double *) data[35],
03494                                         *(double *) data[36],
03495                                         *(int *) data[37],
03496                                         *(int *) data[38],
03497                                         *(int *) data[39],
03498                                         *(int *) data[40],
03499                                         *(unsigned long *) data[41],
03500                                         *(char **) data[42],   
03501                                         *(char **) data[43],
03502                                         *(double *) data[44],
03503                                         *(double *) data[45],
03504                                         *(unsigned long *) data[46]     /* insert end */
03505                                 );
03506                                 /* send query to db */
03507                                 result = ido2db_db_query(idi, query2);
03508                                 free(query2);
03509                         }
03510                         break;
03511                 case IDO2DB_DBSERVER_DB2:
03512                         break;
03513                 case IDO2DB_DBSERVER_FIREBIRD:
03514                         break;
03515                 case IDO2DB_DBSERVER_FREETDS:
03516                         break;
03517                 case IDO2DB_DBSERVER_INGRES:
03518                         break;
03519                 case IDO2DB_DBSERVER_MSQL:
03520                         break;
03521                 case IDO2DB_DBSERVER_ORACLE:
03522                         break;
03523                 case IDO2DB_DBSERVER_SQLITE:
03524                         break;
03525                 case IDO2DB_DBSERVER_SQLITE3:
03526                         break;
03527                 default:
03528                         break;
03529         }
03530 #endif
03531 
03532 #ifdef USE_PGSQL /* pgsql */
03533 
03534 #endif
03535 
03536 #ifdef USE_ORACLE /* Oracle ocilib specific */
03537 
03538         /* check if we lost connection, and reconnect */
03539         if(ido2db_db_reconnect(idi)==IDO_ERROR)
03540                 return IDO_ERROR;
03541 
03542                         /* bind params to prepared statement */
03543                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicestatus, MT(":X1"), (big_uint *) data[0])) {
03544                                 return IDO_ERROR;
03545                         }
03546                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicestatus, MT(":X2"), (big_uint *) data[1])) {
03547                                 return IDO_ERROR;
03548                         }
03549                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicestatus, MT(":X3"), (big_uint *) data[47])) { /* unixtimestamp instead of time2sql */
03550                                 return IDO_ERROR;
03551                         }
03552         if(*(char **) data[3]==NULL) {
03553                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_servicestatus, ":X4")==IDO_ERROR) {
03554                         return IDO_ERROR;
03555                 }
03556         } else {
03557                         if(!OCI_BindString(idi->dbinfo.oci_statement_servicestatus, MT(":X4"), *(char **) data[3], 0)) {
03558                                 return IDO_ERROR;
03559                         }
03560         }
03561         if(*(char **) data[4]==NULL) {
03562                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_servicestatus, ":X5")==IDO_ERROR) {
03563                         return IDO_ERROR;
03564                 }
03565         } else {
03566                         if(!OCI_BindString(idi->dbinfo.oci_statement_servicestatus, MT(":X5"), *(char **) data[4], 0)) {
03567                                 return IDO_ERROR;
03568                         }
03569         }
03570         if(*(char **) data[5]==NULL) {
03571                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_servicestatus, ":X6")==IDO_ERROR) {
03572                         return IDO_ERROR;
03573                 }
03574         } else {
03575                         if(!OCI_BindString(idi->dbinfo.oci_statement_servicestatus, MT(":X6"), *(char **) data[5], 0)) {
03576                                 return IDO_ERROR;
03577                         }
03578         }
03579                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X7"), (int *) data[6])) {
03580                                 return IDO_ERROR;
03581                         }
03582                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X8"), (int *) data[7])) {
03583                                 return IDO_ERROR;
03584                         }
03585                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X9"), (int *) data[8])) {
03586                                 return IDO_ERROR;
03587                         }
03588                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X10"), (int *) data[9])) {
03589                                 return IDO_ERROR;
03590                         }
03591                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X11"), (int *) data[10])) {
03592                                 return IDO_ERROR;
03593                         }
03594                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicestatus, MT(":X12"), (big_uint *) data[48])) { /* unixtimestamp instead of time2sql */
03595                                 return IDO_ERROR;
03596                         }
03597                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicestatus, MT(":X13"), (big_uint *) data[49])) { /* unixtimestamp instead of time2sql */
03598                                 return IDO_ERROR;
03599                         }
03600                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X14"), (int *) data[13])) {
03601                                 return IDO_ERROR;
03602                         }
03603                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicestatus, MT(":X15"), (big_uint *) data[50])) { /* unixtimestamp instead of time2sql */
03604                                 return IDO_ERROR;
03605                         }
03606                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicestatus, MT(":X16"), (big_uint *) data[51])) { /* unixtimestamp instead of time2sql */
03607                                 return IDO_ERROR;
03608                         }
03609                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X17"), (int *) data[16])) {
03610                                 return IDO_ERROR;
03611                         }
03612                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicestatus, MT(":X18"), (big_uint *) data[52])) { /* unixtimestamp instead of time2sql */
03613                                 return IDO_ERROR;
03614                         }
03615                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicestatus, MT(":X19"), (big_uint *) data[53])) { /* unixtimestamp instead of time2sql */
03616                                 return IDO_ERROR;
03617                         }
03618                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicestatus, MT(":X20"), (big_uint *) data[54])) { /* unixtimestamp instead of time2sql */
03619                                 return IDO_ERROR;
03620                         }
03621                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicestatus, MT(":X21"), (big_uint *) data[55])) { /* unixtimestamp instead of time2sql */
03622                                 return IDO_ERROR;
03623                         }
03624                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X22"), (int *) data[21])) {
03625                                 return IDO_ERROR;
03626                         }
03627                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicestatus, MT(":X23"), (big_uint *) data[56])) { /* unixtimestamp instead of time2sql */
03628                                 return IDO_ERROR;
03629                         }
03630                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicestatus, MT(":X24"), (big_uint *) data[57])) { /* unixtimestamp instead of time2sql */
03631                                 return IDO_ERROR;
03632                         }
03633                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X25"), (int *) data[24])) {
03634                                 return IDO_ERROR;
03635                         }
03636                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X26"), (int *) data[25])) {
03637                                 return IDO_ERROR;
03638                         }
03639                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X27"), (int *) data[26])) {
03640                                 return IDO_ERROR;
03641                         }
03642                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X28"), (int *) data[27])) {
03643                                 return IDO_ERROR;
03644                         }
03645                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X29"), (int *) data[28])) {
03646                                 return IDO_ERROR;
03647                         }
03648                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X30"), (int *) data[29])) {
03649                                 return IDO_ERROR;
03650                         }
03651                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X31"), (int *) data[30])) {
03652                                 return IDO_ERROR;
03653                         }
03654                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X32"), (int *) data[31])) {
03655                                 return IDO_ERROR;
03656                         }
03657                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X33"), (int *) data[32])) {
03658                                 return IDO_ERROR;
03659                         }
03660                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X34"), (int *) data[33])) {
03661                                 return IDO_ERROR;
03662                         }
03663                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_servicestatus, MT(":X35"), (double *) data[34])) {
03664                                 return IDO_ERROR;
03665                         }
03666                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_servicestatus, MT(":X36"), (double *) data[35])) {
03667                                 return IDO_ERROR;
03668                         }
03669                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_servicestatus, MT(":X37"), (double *) data[36])) {
03670                                 return IDO_ERROR;
03671                         }
03672                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X38"), (int *) data[37])) {
03673                                 return IDO_ERROR;
03674                         }
03675                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X39"), (int *) data[38])) {
03676                                 return IDO_ERROR;
03677                         }
03678                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X40"), (int *) data[39])) {
03679                                 return IDO_ERROR;
03680                         }
03681                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicestatus, MT(":X41"), (int *) data[40])) {
03682                                 return IDO_ERROR;
03683                         }
03684                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicestatus, MT(":X42"), (big_uint *) data[41])) {
03685                                 return IDO_ERROR;
03686                         }
03687         if(*(char **) data[42]==NULL) {
03688                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_servicestatus, ":X43")==IDO_ERROR) {
03689                         return IDO_ERROR;
03690                 }
03691         } else {
03692                         if(!OCI_BindString(idi->dbinfo.oci_statement_servicestatus, MT(":X43"), *(char **) data[42], 0)) {
03693                                 return IDO_ERROR;
03694                         }
03695         }
03696         if(*(char **) data[43]==NULL) {
03697                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_servicestatus, ":X44")==IDO_ERROR) {
03698                         return IDO_ERROR;
03699                 }
03700         } else {
03701                         if(!OCI_BindString(idi->dbinfo.oci_statement_servicestatus, MT(":X44"), *(char **) data[43], 0)) {
03702                                 return IDO_ERROR;
03703                         }
03704         }
03705                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_servicestatus, MT(":X45"), (double *) data[44])) {
03706                                 return IDO_ERROR;
03707                         }
03708                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_servicestatus, MT(":X46"), (double *) data[45])) {
03709                                 return IDO_ERROR;
03710                         }
03711                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicestatus, MT(":X47"), (big_uint *) data[46])) {
03712                                 return IDO_ERROR;
03713                         }
03714 
03715                         /* execute statement */
03716                         if(!OCI_Execute(idi->dbinfo.oci_statement_servicestatus)) {
03717                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_servicestatus() execute error\n");
03718                                 return IDO_ERROR;
03719                         }
03720 
03721                         /* commit statement */
03722                         OCI_Commit(idi->dbinfo.oci_connection);
03723 
03724                         /* do not free statement yet! */
03725 #endif
03726         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_servicestatusdata_add() end\n");
03727 
03728         return result;
03729 }
03730 
03731 
03732 /************************************/
03733 /* CONTACTSTATUS                    */
03734 /************************************/
03735 
03736 int ido2db_query_insert_or_update_contactstatusdata_add(ido2db_idi *idi, void **data) {
03737         int result = IDO_OK;
03738 #ifdef USE_LIBDBI
03739         char * query1 = NULL;
03740         char * query2 = NULL;
03741 #endif
03742         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_contactstatusdata_add() start\n");
03743 
03744         if (idi == NULL)
03745                 return IDO_ERROR;
03746 
03747         if (idi->dbinfo.connected == IDO_FALSE)
03748                 return IDO_ERROR;
03749 
03750 #ifdef USE_LIBDBI /* everything else will be libdbi */
03751         switch (idi->dbinfo.server_type) {
03752                 case IDO2DB_DBSERVER_MYSQL:
03753                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, contact_object_id, status_update_time, host_notifications_enabled, service_notifications_enabled, last_host_notification, last_service_notification, modified_attributes, modified_host_attributes, modified_service_attributes) VALUES (%lu, %lu, %s, %d, %d, %s, %s, %lu, %lu, %lu) ON DUPLICATE KEY UPDATE instance_id=%lu, status_update_time=%s, host_notifications_enabled=%d, service_notifications_enabled=%d, last_host_notification=%s, last_service_notification=%s, modified_attributes=%lu, modified_host_attributes=%lu, modified_service_attributes=%lu",
03754                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTSTATUS],
03755                                         *(unsigned long *) data[0],     /* insert start */
03756                                         *(unsigned long *) data[1],
03757                                         *(char **) data[2],
03758                                         *(int *) data[3],
03759                                         *(int *) data[4],
03760                                         *(char **) data[5],
03761                                         *(char **) data[6],
03762                                         *(unsigned long *) data[7],
03763                                         *(unsigned long *) data[8],
03764                                         *(unsigned long *) data[9],     /* insert end */
03765                                         *(unsigned long *) data[0],     /* update start */
03766                                         *(char **) data[2],
03767                                         *(int *) data[3],
03768                                         *(int *) data[4],
03769                                         *(char **) data[5],
03770                                         *(char **) data[6],
03771                                         *(unsigned long *) data[7],
03772                                         *(unsigned long *) data[8],
03773                                         *(unsigned long *) data[9]     /* update end */
03774                         );
03775                         /* send query to db */
03776                         result = ido2db_db_query(idi, query1);
03777                         free(query1);
03778                         break;
03779                 case IDO2DB_DBSERVER_PGSQL:
03780                         dummy=asprintf(&query1, "UPDATE %s SET instance_id=%lu, status_update_time=%s, host_notifications_enabled=%d, service_notifications_enabled=%d, last_host_notification=%s, last_service_notification=%s, modified_attributes=%lu, modified_host_attributes=%lu, modified_service_attributes=%lu WHERE contact_object_id=%lu",
03781                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTSTATUS],
03782                                         *(unsigned long *) data[0],     /* update start */
03783                                         *(char **) data[2],
03784                                         *(int *) data[3],
03785                                         *(int *) data[4],
03786                                         *(char **) data[5],
03787                                         *(char **) data[6],
03788                                         *(unsigned long *) data[7],
03789                                         *(unsigned long *) data[8],
03790                                         *(unsigned long *) data[9],     /* update end */
03791                                         *(unsigned long *) data[1]     /* unique constraint start/end */
03792                         );
03793                         /* send query to db */
03794                         result = ido2db_db_query(idi, query1);
03795                         free(query1);
03796 
03797                         /* check result if update was ok */
03798                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
03799                                 /* try insert instead */
03800                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, contact_object_id, status_update_time, host_notifications_enabled, service_notifications_enabled, last_host_notification, last_service_notification, modified_attributes, modified_host_attributes, modified_service_attributes) VALUES (%lu, %lu, %s, %d, %d, %s, %s, %lu, %lu, %lu)",
03801                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTSTATUS],
03802                                         *(unsigned long *) data[0],     /* insert start */
03803                                         *(unsigned long *) data[1],
03804                                         *(char **) data[2],
03805                                         *(int *) data[3],
03806                                         *(int *) data[4],
03807                                         *(char **) data[5],
03808                                         *(char **) data[6],
03809                                         *(unsigned long *) data[7],
03810                                         *(unsigned long *) data[8],
03811                                         *(unsigned long *) data[9]     /* insert end */
03812                                 );
03813                                 /* send query to db */
03814                                 result = ido2db_db_query(idi, query2);
03815                                 free(query2);
03816                         }
03817                         break;
03818                 case IDO2DB_DBSERVER_DB2:
03819                         break;
03820                 case IDO2DB_DBSERVER_FIREBIRD:
03821                         break;
03822                 case IDO2DB_DBSERVER_FREETDS:
03823                         break;
03824                 case IDO2DB_DBSERVER_INGRES:
03825                         break;
03826                 case IDO2DB_DBSERVER_MSQL:
03827                         break;
03828                 case IDO2DB_DBSERVER_ORACLE:
03829                         break;
03830                 case IDO2DB_DBSERVER_SQLITE:
03831                         break;
03832                 case IDO2DB_DBSERVER_SQLITE3:
03833                         break;
03834                 default:
03835                         break;
03836         }
03837 #endif
03838 
03839 #ifdef USE_PGSQL /* pgsql */
03840 
03841 #endif
03842 
03843 #ifdef USE_ORACLE /* Oracle ocilib specific */
03844 
03845         /* check if we lost connection, and reconnect */
03846         if(ido2db_db_reconnect(idi)==IDO_ERROR)
03847                 return IDO_ERROR;
03848 
03849                         /* use prepared statements and ocilib */
03850                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactstatusdata, MT(":X1"), (big_uint *) data[0])) {
03851                                 return IDO_ERROR;
03852                         }
03853                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactstatusdata, MT(":X2"), (big_uint *) data[1])) {
03854                                 return IDO_ERROR;
03855                         }
03856                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactstatusdata, MT(":X3"), (big_uint *) data[10])) { /* unixtimestamp instead of time2sql */
03857                                 return IDO_ERROR;
03858                         }
03859                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contactstatusdata, MT(":X4"), (int *) data[3])) {
03860                                 return IDO_ERROR;
03861                         }
03862                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contactstatusdata, MT(":X5"), (int *) data[4])) {
03863                                 return IDO_ERROR;
03864                         }
03865                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactstatusdata, MT(":X6"), (big_uint *) data[11])) { /* unixtimestamp instead of time2sql */
03866                                 return IDO_ERROR;
03867                         }
03868                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactstatusdata, MT(":X7"), (big_uint *) data[12])) { /* unixtimestamp instead of time2sql */
03869                                 return IDO_ERROR;
03870                         }
03871                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactstatusdata, MT(":X8"), (big_uint *) data[7])) {
03872                                 return IDO_ERROR;
03873                         }
03874                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactstatusdata, MT(":X9"), (big_uint *) data[8])) {
03875                                 return IDO_ERROR;
03876                         }
03877                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactstatusdata, MT(":X10"), (big_uint *) data[9])) {
03878                                 return IDO_ERROR;
03879                         }
03880 
03881 
03882                         /* execute statement */
03883                         if(!OCI_Execute(idi->dbinfo.oci_statement_contactstatusdata)) {
03884                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_contactstatusdata() execute error\n");
03885                                 return IDO_ERROR;
03886                         }
03887 
03888                         /* commit statement */
03889                         OCI_Commit(idi->dbinfo.oci_connection);
03890 
03891                         /* do not free statement yet! */
03892 #endif
03893         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_contactstatusdata_add() end\n");
03894 
03895         return result;
03896 }
03897 
03898 
03899 /************************************/
03900 /* CONFIGFILEVARIABLES              */
03901 /************************************/
03902 
03903 int ido2db_query_insert_or_update_configfilevariables_add(ido2db_idi *idi, void **data) {
03904         int result = IDO_OK;
03905 #ifdef USE_LIBDBI
03906         char * query1 = NULL;
03907         char * query2 = NULL;
03908 #endif
03909         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_configfilevariables_add() start\n");
03910 
03911         if (idi == NULL)
03912                 return IDO_ERROR;
03913 
03914         if (idi->dbinfo.connected == IDO_FALSE)
03915                 return IDO_ERROR;
03916 
03917 #ifdef USE_LIBDBI /* everything else will be libdbi */
03918         switch (idi->dbinfo.server_type) {
03919                 case IDO2DB_DBSERVER_MYSQL:
03920                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, configfile_type, configfile_path) VALUES (%lu, %d, '%s') ON DUPLICATE KEY UPDATE instance_id='%lu', configfile_type='%d', configfile_path='%s'",
03921                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONFIGFILES],
03922                                         *(unsigned long *) data[0],     /* insert start */
03923                                         *(int *) data[1],
03924                                         *(char **) data[2],             /* insert end */
03925                                         *(unsigned long *) data[0],     /* update start */
03926                                         *(int *) data[1],
03927                                         *(char **) data[2]              /* update end */
03928                         );
03929                         /* send query to db */
03930                         result = ido2db_db_query(idi, query1);
03931                         free(query1);
03932                         break;
03933                 case IDO2DB_DBSERVER_PGSQL:
03934                         dummy=asprintf(&query1, "UPDATE %s SET instance_id='%lu', configfile_type='%d', configfile_path='%s' WHERE instance_id=%lu AND configfile_type=%d AND configfile_path='%s'",
03935                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONFIGFILES],
03936                                         *(unsigned long *) data[0],     /* update start */
03937                                         *(int *) data[1],
03938                                         *(char **) data[2],              /* update end */
03939                                         *(unsigned long *) data[0],     /* unique constraint start */
03940                                         *(int *) data[1],
03941                                         *(char **) data[2]             /* unique constraint end */
03942                         );
03943                         /* send query to db */
03944                         result = ido2db_db_query(idi, query1);
03945                         free(query1);
03946                         
03947                         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_configfilevariables_add(%lu) update rows affected\n", dbi_result_get_numrows_affected(idi->dbinfo.dbi_result));
03948 
03949                         /* check result if update was ok */
03950                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
03951                                 /* try insert instead */
03952                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, configfile_type, configfile_path) VALUES (%lu, %d, '%s')",
03953                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONFIGFILES],
03954                                         *(unsigned long *) data[0],     /* insert start */
03955                                         *(int *) data[1],
03956                                         *(char **) data[2]             /* insert end */
03957                                 );
03958                                 /* send query to db */
03959                                 result = ido2db_db_query(idi, query2);
03960                                 free(query2);
03961                         }
03962                         break;
03963                 case IDO2DB_DBSERVER_DB2:
03964                         break;
03965                 case IDO2DB_DBSERVER_FIREBIRD:
03966                         break;
03967                 case IDO2DB_DBSERVER_FREETDS:
03968                         break;
03969                 case IDO2DB_DBSERVER_INGRES:
03970                         break;
03971                 case IDO2DB_DBSERVER_MSQL:
03972                         break;
03973                 case IDO2DB_DBSERVER_ORACLE:
03974                         break;
03975                 case IDO2DB_DBSERVER_SQLITE:
03976                         break;
03977                 case IDO2DB_DBSERVER_SQLITE3:
03978                         break;
03979                 default:
03980                         break;
03981         }
03982 #endif
03983 
03984 #ifdef USE_PGSQL /* pgsql */
03985 
03986 #endif
03987 
03988 #ifdef USE_ORACLE /* Oracle ocilib specific */
03989 
03990         /* check if we lost connection, and reconnect */
03991         if(ido2db_db_reconnect(idi)==IDO_ERROR)
03992                 return IDO_ERROR;
03993 
03994                         /* use prepared statements and ocilib */
03995                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_configfilevariables, MT(":X1"), (big_uint *) data[0])) {
03996                                 return IDO_ERROR;
03997                         }
03998                         if(!OCI_BindInt(idi->dbinfo.oci_statement_configfilevariables, MT(":X2"), (int *) data[1])) {
03999                                 return IDO_ERROR;
04000                         }
04001         if(*(char **) data[2]==NULL) {
04002                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_configfilevariables, ":X3")==IDO_ERROR) {
04003                         return IDO_ERROR;
04004                 }
04005         } else {
04006                         if(!OCI_BindString(idi->dbinfo.oci_statement_configfilevariables, MT(":X3"), *(char **) data[2], 0)) {
04007                                 return IDO_ERROR;
04008                         }
04009         }
04010 
04011                         /* execute statement */
04012                         if(!OCI_Execute(idi->dbinfo.oci_statement_configfilevariables)) {
04013                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_configfilevariables() execute error\n");
04014                                 return IDO_ERROR;
04015                         }
04016 
04017                         /* commit statement */
04018                         OCI_Commit(idi->dbinfo.oci_connection);
04019 
04020                         /* do not free statement yet! */
04021 #endif
04022         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_configfilevariables_add() end\n");
04023 
04024         return result;
04025 }
04026 
04027 
04028 /************************************/
04029 /* RUNTIMEVARIABLES                 */
04030 /************************************/
04031 
04032 int ido2db_query_insert_or_update_runtimevariables_add(ido2db_idi *idi, void **data) {
04033         int result = IDO_OK;
04034 #ifdef USE_LIBDBI
04035         char * query1 = NULL;
04036         char * query2 = NULL;
04037 #endif
04038         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_runtimevariables_add() start\n");
04039 
04040         if (idi == NULL)
04041                 return IDO_ERROR;
04042 
04043         if (idi->dbinfo.connected == IDO_FALSE)
04044                 return IDO_ERROR;
04045 
04046 #ifdef USE_LIBDBI /* everything else will be libdbi */
04047         switch (idi->dbinfo.server_type) {
04048                 case IDO2DB_DBSERVER_MYSQL:
04049                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, varname, varvalue) VALUES (%lu, '%s', '%s') ON DUPLICATE KEY UPDATE varvalue='%s'",
04050                                         ido2db_db_tablenames[IDO2DB_DBTABLE_RUNTIMEVARIABLES],
04051                                         *(unsigned long *) data[0],     /* insert start */
04052                                         *(char **) data[1],
04053                                         *(char **) data[2],             /* insert end */
04054                                         *(char **) data[2]             /* update start/end */
04055                         );
04056                         /* send query to db */
04057                         result = ido2db_db_query(idi, query1);
04058                         free(query1);
04059                         break;
04060                 case IDO2DB_DBSERVER_PGSQL:
04061                         dummy=asprintf(&query1, "UPDATE %s SET varvalue='%s' WHERE instance_id=%lu AND varname='%s'",
04062                                         ido2db_db_tablenames[IDO2DB_DBTABLE_RUNTIMEVARIABLES],
04063                                         *(char **) data[2],             /* update start/end */
04064                                         *(unsigned long *) data[0],     /* unique constraint start */
04065                                         *(char **) data[1]              /* unique constraint end */
04066                         );
04067                         /* send query to db */
04068                         result = ido2db_db_query(idi, query1);
04069                         free(query1);
04070 
04071                         /* check result if update was ok */
04072                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
04073                                 /* try insert instead */
04074                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, varname, varvalue) VALUES (%lu, '%s', '%s')",
04075                                         ido2db_db_tablenames[IDO2DB_DBTABLE_RUNTIMEVARIABLES],
04076                                         *(unsigned long *) data[0],     /* insert start */
04077                                         *(char **) data[1],
04078                                         *(char **) data[2]             /* insert end */
04079                                 );
04080                                 /* send query to db */
04081                                 result = ido2db_db_query(idi, query2);
04082                                 free(query2);
04083                         }
04084                         break;
04085                 case IDO2DB_DBSERVER_DB2:
04086                         break;
04087                 case IDO2DB_DBSERVER_FIREBIRD:
04088                         break;
04089                 case IDO2DB_DBSERVER_FREETDS:
04090                         break;
04091                 case IDO2DB_DBSERVER_INGRES:
04092                         break;
04093                 case IDO2DB_DBSERVER_MSQL:
04094                         break;
04095                 case IDO2DB_DBSERVER_ORACLE:
04096                         break;
04097                 case IDO2DB_DBSERVER_SQLITE:
04098                         break;
04099                 case IDO2DB_DBSERVER_SQLITE3:
04100                         break;
04101                 default:
04102                         break;
04103         }
04104 #endif
04105 
04106 #ifdef USE_PGSQL /* pgsql */
04107 
04108 #endif
04109 
04110 #ifdef USE_ORACLE /* Oracle ocilib specific */
04111 
04112         /* check if we lost connection, and reconnect */
04113         if(ido2db_db_reconnect(idi)==IDO_ERROR)
04114                 return IDO_ERROR;
04115 
04116                         /* use prepared statements and ocilib */
04117                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_runtimevariables, MT(":X1"), (big_uint *) data[0])) {
04118                                 return IDO_ERROR;
04119                         }
04120         if(*(char **) data[1]==NULL) {
04121                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_runtimevariables, ":X2")==IDO_ERROR) {
04122                         return IDO_ERROR;
04123                 }
04124         } else {
04125                         if(!OCI_BindString(idi->dbinfo.oci_statement_runtimevariables, MT(":X2"), *(char **) data[1], 0)) {
04126                                 return IDO_ERROR;
04127                         }
04128         }
04129         if(*(char **) data[2]==NULL) {
04130                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_runtimevariables, ":X3")==IDO_ERROR) {
04131                         return IDO_ERROR;
04132                 }
04133         } else {
04134                         if(!OCI_BindString(idi->dbinfo.oci_statement_runtimevariables, MT(":X3"), *(char **) data[2], 0)) {
04135                                 return IDO_ERROR;
04136                         }
04137         }
04138 
04139                         /* execute statement */
04140                         if(!OCI_Execute(idi->dbinfo.oci_statement_runtimevariables)) {
04141                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_runtimevariables() execute error\n");
04142                                 return IDO_ERROR;
04143                         }
04144 
04145                         /* commit statement */
04146                         OCI_Commit(idi->dbinfo.oci_connection);
04147 
04148                         /* do not free statement yet! */
04149 #endif
04150         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_runtimevariables_add() end\n");
04151 
04152         return result;
04153 }
04154 
04155 
04156 /************************************/
04157 /* HOSTDEFINITION                   */
04158 /************************************/
04159 
04160 int ido2db_query_insert_or_update_hostdefinition_definition_add(ido2db_idi *idi, void **data) {
04161         int result = IDO_OK;
04162 #ifdef USE_LIBDBI
04163         char * query1 = NULL;
04164         char * query2 = NULL;
04165 #endif
04166         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hostdefinition_definition_add() start\n");
04167 
04168         if (idi == NULL)
04169                 return IDO_ERROR;
04170 
04171         if (idi->dbinfo.connected == IDO_FALSE)
04172                 return IDO_ERROR;
04173 
04174 #ifdef USE_LIBDBI /* everything else will be libdbi */
04175         switch (idi->dbinfo.server_type) {
04176                 case IDO2DB_DBSERVER_MYSQL:
04177                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, config_type, host_object_id, alias, display_name, address, check_command_object_id, check_command_args, eventhandler_command_object_id, eventhandler_command_args, check_timeperiod_object_id, notification_timeperiod_object_id, failure_prediction_options, check_interval, retry_interval, max_check_attempts, first_notification_delay, notification_interval, notify_on_down, notify_on_unreachable, notify_on_recovery, notify_on_flapping, notify_on_downtime, stalk_on_up, stalk_on_down, stalk_on_unreachable, flap_detection_enabled, flap_detection_on_up, flap_detection_on_down, flap_detection_on_unreachable, low_flap_threshold, high_flap_threshold, process_performance_data, freshness_checks_enabled, freshness_threshold, passive_checks_enabled, event_handler_enabled, active_checks_enabled, retain_status_information, retain_nonstatus_information, notifications_enabled, obsess_over_host, failure_prediction_enabled, notes, notes_url, action_url, icon_image, icon_image_alt, vrml_image, statusmap_image, have_2d_coords, x_2d, y_2d, have_3d_coords, x_3d, y_3d, z_3d, address6) VALUES (%lu, %d, %lu, '%s', '%s', '%s', %lu, '%s', %lu, '%s', %lu, %lu, '%s', %lf, %lf, %d, %lf, %lf, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %lf, %lf, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %lf, %lf, %lf, '%s') ON DUPLICATE KEY UPDATE alias='%s', display_name='%s', address='%s', check_command_object_id=%lu, check_command_args='%s', eventhandler_command_object_id=%lu, eventhandler_command_args='%s', check_timeperiod_object_id=%lu, notification_timeperiod_object_id=%lu, failure_prediction_options='%s', check_interval=%lf, retry_interval=%lf, max_check_attempts=%d, first_notification_delay=%lf, notification_interval=%lf, notify_on_down=%d, notify_on_unreachable=%d, notify_on_recovery=%d, notify_on_flapping=%d, notify_on_downtime=%d, stalk_on_up=%d, stalk_on_down=%d, stalk_on_unreachable=%d, flap_detection_enabled=%d, flap_detection_on_up=%d, flap_detection_on_down=%d, flap_detection_on_unreachable=%d, low_flap_threshold=%lf, high_flap_threshold=%lf, process_performance_data=%d, freshness_checks_enabled=%d, freshness_threshold=%d, passive_checks_enabled=%d, event_handler_enabled=%d, active_checks_enabled=%d, retain_status_information=%d, retain_nonstatus_information=%d, notifications_enabled=%d, obsess_over_host=%d, failure_prediction_enabled=%d, notes='%s', notes_url='%s', action_url='%s', icon_image='%s', icon_image_alt='%s', vrml_image='%s', statusmap_image='%s', have_2d_coords=%d, x_2d=%d, y_2d=%d, have_3d_coords=%d, x_3d=%lf, y_3d=%lf, z_3d=%lf, address6='%s'",
04178                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTS],
04179                                         *(unsigned long *) data[0],     /* insert start */
04180                                         *(int *) data[1],
04181                                         *(unsigned long *) data[2],
04182                                         *(char **) data[3],
04183                                         *(char **) data[4],
04184                                         *(char **) data[5],
04185                                         *(unsigned long *) data[6],
04186                                         (*(char **) data[7]==NULL)?"":*(char **) data[7],
04187                                         *(unsigned long *) data[8],
04188                                         (*(char **) data[9]==NULL)?"":*(char **) data[9],
04189                                         *(unsigned long *) data[10],
04190                                         *(unsigned long *) data[11],
04191                                         *(char **) data[12],
04192                                         *(double *) data[13],
04193                                         *(double *) data[14],
04194                                         *(int *) data[15],
04195                                         *(double *) data[16],
04196                                         *(double *) data[17],
04197                                         *(int *) data[18],
04198                                         *(int *) data[19],
04199                                         *(int *) data[20],
04200                                         *(int *) data[21],
04201                                         *(int *) data[22],
04202                                         *(int *) data[23],
04203                                         *(int *) data[24],
04204                                         *(int *) data[25],
04205                                         *(int *) data[26],
04206                                         *(int *) data[27],
04207                                         *(int *) data[28],
04208                                         *(int *) data[29],
04209                                         *(double *) data[30],
04210                                         *(double *) data[31],
04211                                         *(int *) data[32],
04212                                         *(int *) data[33],
04213                                         *(int *) data[34],
04214                                         *(int *) data[35],
04215                                         *(int *) data[36],
04216                                         *(int *) data[37],
04217                                         *(int *) data[38],
04218                                         *(int *) data[39],
04219                                         *(int *) data[40],
04220                                         *(int *) data[41],
04221                                         *(int *) data[42],
04222                                         *(char **) data[43],
04223                                         *(char **) data[44],
04224                                         *(char **) data[45],
04225                                         *(char **) data[46],
04226                                         *(char **) data[47],
04227                                         *(char **) data[48],
04228                                         *(char **) data[49],
04229                                         *(int *) data[50],
04230                                         *(int *) data[51],
04231                                         *(int *) data[52],
04232                                         *(int *) data[53],
04233                                         *(double *) data[54],
04234                                         *(double *) data[55],
04235                                         *(double *) data[56],
04236                                         *(char **) data[57],            /* insert end */
04237                                         *(char **) data[3],             /* update start */
04238                                         *(char **) data[4],
04239                                         *(char **) data[5],
04240                                         *(unsigned long *) data[6],
04241                                         (*(char **) data[7]==NULL)?"":*(char **) data[7],
04242                                         *(unsigned long *) data[8],
04243                                         (*(char **) data[9]==NULL)?"":*(char **) data[9],
04244                                         *(unsigned long *) data[10],
04245                                         *(unsigned long *) data[11],
04246                                         *(char **) data[12],
04247                                         *(double *) data[13],
04248                                         *(double *) data[14],
04249                                         *(int *) data[15],
04250                                         *(double *) data[16],
04251                                         *(double *) data[17],
04252                                         *(int *) data[18],
04253                                         *(int *) data[19],
04254                                         *(int *) data[20],
04255                                         *(int *) data[21],
04256                                         *(int *) data[22],
04257                                         *(int *) data[23],
04258                                         *(int *) data[24],
04259                                         *(int *) data[25],
04260                                         *(int *) data[26],
04261                                         *(int *) data[27],
04262                                         *(int *) data[28],
04263                                         *(int *) data[29],
04264                                         *(double *) data[30],
04265                                         *(double *) data[31],
04266                                         *(int *) data[32],
04267                                         *(int *) data[33],
04268                                         *(int *) data[34],
04269                                         *(int *) data[35],
04270                                         *(int *) data[36],
04271                                         *(int *) data[37],
04272                                         *(int *) data[38],
04273                                         *(int *) data[39],
04274                                         *(int *) data[40],
04275                                         *(int *) data[41],
04276                                         *(int *) data[42],
04277                                         *(char **) data[43],
04278                                         *(char **) data[44],
04279                                         *(char **) data[45],
04280                                         *(char **) data[46],
04281                                         *(char **) data[47],
04282                                         *(char **) data[48],
04283                                         *(char **) data[49],
04284                                         *(int *) data[50],
04285                                         *(int *) data[51],
04286                                         *(int *) data[52],
04287                                         *(int *) data[53],
04288                                         *(double *) data[54],
04289                                         *(double *) data[55],
04290                                         *(double *) data[56],
04291                                         *(char **) data[57]           /* update end */
04292                         );
04293                         /* send query to db */
04294                         result = ido2db_db_query(idi, query1);
04295                         free(query1);
04296                         break;
04297                 case IDO2DB_DBSERVER_PGSQL:
04298                         dummy=asprintf(&query1, "UPDATE %s SET alias='%s', display_name='%s', address='%s', check_command_object_id=%lu, check_command_args='%s', eventhandler_command_object_id=%lu, eventhandler_command_args='%s', check_timeperiod_object_id=%lu, notification_timeperiod_object_id=%lu, failure_prediction_options='%s', check_interval=%lf, retry_interval=%lf, max_check_attempts=%d, first_notification_delay=%lf, notification_interval=%lf, notify_on_down=%d, notify_on_unreachable=%d, notify_on_recovery=%d, notify_on_flapping=%d, notify_on_downtime=%d, stalk_on_up=%d, stalk_on_down=%d, stalk_on_unreachable=%d, flap_detection_enabled=%d, flap_detection_on_up=%d, flap_detection_on_down=%d, flap_detection_on_unreachable=%d, low_flap_threshold=%lf, high_flap_threshold=%lf, process_performance_data=%d, freshness_checks_enabled=%d, freshness_threshold=%d, passive_checks_enabled=%d, event_handler_enabled=%d, active_checks_enabled=%d, retain_status_information=%d, retain_nonstatus_information=%d, notifications_enabled=%d, obsess_over_host=%d, failure_prediction_enabled=%d, notes='%s', notes_url='%s', action_url='%s', icon_image='%s', icon_image_alt='%s', vrml_image='%s', statusmap_image='%s', have_2d_coords=%d, x_2d=%d, y_2d=%d, have_3d_coords=%d, x_3d=%lf, y_3d=%lf, z_3d=%lf, address6='%s' WHERE instance_id=%lu AND config_type=%d AND host_object_id=%lu",
04299                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTS],
04300                                         *(char **) data[3],             /* update start */
04301                                         *(char **) data[4],
04302                                         *(char **) data[5],
04303                                         *(unsigned long *) data[6],
04304                                         (*(char **) data[7]==NULL)?"":*(char **) data[7],
04305                                         *(unsigned long *) data[8],
04306                                         (*(char **) data[9]==NULL)?"":*(char **) data[9],
04307                                         *(unsigned long *) data[10],
04308                                         *(unsigned long *) data[11],
04309                                         *(char **) data[12],
04310                                         *(double *) data[13],
04311                                         *(double *) data[14],
04312                                         *(int *) data[15],
04313                                         *(double *) data[16],
04314                                         *(double *) data[17],
04315                                         *(int *) data[18],
04316                                         *(int *) data[19],
04317                                         *(int *) data[20],
04318                                         *(int *) data[21],
04319                                         *(int *) data[22],
04320                                         *(int *) data[23],
04321                                         *(int *) data[24],
04322                                         *(int *) data[25],
04323                                         *(int *) data[26],
04324                                         *(int *) data[27],
04325                                         *(int *) data[28],
04326                                         *(int *) data[29],
04327                                         *(double *) data[30],
04328                                         *(double *) data[31],
04329                                         *(int *) data[32],
04330                                         *(int *) data[33],
04331                                         *(int *) data[34],
04332                                         *(int *) data[35],
04333                                         *(int *) data[36],
04334                                         *(int *) data[37],
04335                                         *(int *) data[38],
04336                                         *(int *) data[39],
04337                                         *(int *) data[40],
04338                                         *(int *) data[41],
04339                                         *(int *) data[42],
04340                                         *(char **) data[43],
04341                                         *(char **) data[44],
04342                                         *(char **) data[45],
04343                                         *(char **) data[46],
04344                                         *(char **) data[47],
04345                                         *(char **) data[48],
04346                                         *(char **) data[49],
04347                                         *(int *) data[50],
04348                                         *(int *) data[51],
04349                                         *(int *) data[52],
04350                                         *(int *) data[53],
04351                                         *(double *) data[54],
04352                                         *(double *) data[55],
04353                                         *(double *) data[56],
04354                                         *(char **) data[57],           /* update end */
04355                                         *(unsigned long *) data[0],     /* unique constraint start */
04356                                         *(int *) data[1],
04357                                         *(unsigned long *) data[2]      /* unique constraint end */
04358                         );
04359                         /* send query to db */
04360                         result = ido2db_db_query(idi, query1);
04361                         free(query1);
04362 
04363                         /* check result if update was ok */
04364                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
04365                                 /* try insert instead */
04366                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, config_type, host_object_id, alias, display_name, address, check_command_object_id, check_command_args, eventhandler_command_object_id, eventhandler_command_args, check_timeperiod_object_id, notification_timeperiod_object_id, failure_prediction_options, check_interval, retry_interval, max_check_attempts, first_notification_delay, notification_interval, notify_on_down, notify_on_unreachable, notify_on_recovery, notify_on_flapping, notify_on_downtime, stalk_on_up, stalk_on_down, stalk_on_unreachable, flap_detection_enabled, flap_detection_on_up, flap_detection_on_down, flap_detection_on_unreachable, low_flap_threshold, high_flap_threshold, process_performance_data, freshness_checks_enabled, freshness_threshold, passive_checks_enabled, event_handler_enabled, active_checks_enabled, retain_status_information, retain_nonstatus_information, notifications_enabled, obsess_over_host, failure_prediction_enabled, notes, notes_url, action_url, icon_image, icon_image_alt, vrml_image, statusmap_image, have_2d_coords, x_2d, y_2d, have_3d_coords, x_3d, y_3d, z_3d, address6) VALUES (%lu, %d, %lu, '%s', '%s', '%s', %lu, '%s', %lu, '%s', %lu, %lu, '%s', %lf, %lf, %d, %lf, %lf, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %lf, %lf, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %lf, %lf, %lf, '%s')",
04367                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTS],
04368                                         *(unsigned long *) data[0],     /* insert start */
04369                                         *(int *) data[1],
04370                                         *(unsigned long *) data[2],
04371                                         *(char **) data[3],
04372                                         *(char **) data[4],
04373                                         *(char **) data[5],
04374                                         *(unsigned long *) data[6],
04375                                         (*(char **) data[7]==NULL)?"":*(char **) data[7],
04376                                         *(unsigned long *) data[8],
04377                                         (*(char **) data[9]==NULL)?"":*(char **) data[9],
04378                                         *(unsigned long *) data[10],
04379                                         *(unsigned long *) data[11],
04380                                         *(char **) data[12],
04381                                         *(double *) data[13],
04382                                         *(double *) data[14],
04383                                         *(int *) data[15],
04384                                         *(double *) data[16],
04385                                         *(double *) data[17],
04386                                         *(int *) data[18],
04387                                         *(int *) data[19],
04388                                         *(int *) data[20],
04389                                         *(int *) data[21],
04390                                         *(int *) data[22],
04391                                         *(int *) data[23],
04392                                         *(int *) data[24],
04393                                         *(int *) data[25],
04394                                         *(int *) data[26],
04395                                         *(int *) data[27],
04396                                         *(int *) data[28],
04397                                         *(int *) data[29],
04398                                         *(double *) data[30],
04399                                         *(double *) data[31],
04400                                         *(int *) data[32],
04401                                         *(int *) data[33],
04402                                         *(int *) data[34],
04403                                         *(int *) data[35],
04404                                         *(int *) data[36],
04405                                         *(int *) data[37],
04406                                         *(int *) data[38],
04407                                         *(int *) data[39],
04408                                         *(int *) data[40],
04409                                         *(int *) data[41],
04410                                         *(int *) data[42],
04411                                         *(char **) data[43],
04412                                         *(char **) data[44],
04413                                         *(char **) data[45],
04414                                         *(char **) data[46],
04415                                         *(char **) data[47],
04416                                         *(char **) data[48],
04417                                         *(char **) data[49],
04418                                         *(int *) data[50],
04419                                         *(int *) data[51],
04420                                         *(int *) data[52],
04421                                         *(int *) data[53],
04422                                         *(double *) data[54],
04423                                         *(double *) data[55],
04424                                         *(double *) data[56],
04425                                         *(char **) data[57]           /* insert end */
04426                                 );
04427                                 /* send query to db */
04428                                 result = ido2db_db_query(idi, query2);
04429                                 free(query2);
04430                         }
04431                         break;
04432                 case IDO2DB_DBSERVER_DB2:
04433                         break;
04434                 case IDO2DB_DBSERVER_FIREBIRD:
04435                         break;
04436                 case IDO2DB_DBSERVER_FREETDS:
04437                         break;
04438                 case IDO2DB_DBSERVER_INGRES:
04439                         break;
04440                 case IDO2DB_DBSERVER_MSQL:
04441                         break;
04442                 case IDO2DB_DBSERVER_ORACLE:
04443                         break;
04444                 case IDO2DB_DBSERVER_SQLITE:
04445                         break;
04446                 case IDO2DB_DBSERVER_SQLITE3:
04447                         break;
04448                 default:
04449                         break;
04450         }
04451 #endif
04452 
04453 #ifdef USE_PGSQL /* pgsql */
04454 
04455 #endif
04456 
04457 #ifdef USE_ORACLE /* Oracle ocilib specific */
04458 
04459         /* check if we lost connection, and reconnect */
04460         if(ido2db_db_reconnect(idi)==IDO_ERROR)
04461                 return IDO_ERROR;
04462 
04463                         /* use prepared statements and ocilib */
04464                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X1"), (big_uint *) data[0])) {
04465                                 return IDO_ERROR;
04466                         }
04467                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X2"), (int *) data[1])) {
04468                                 return IDO_ERROR;
04469                         }
04470                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X3"), (big_uint *) data[2])) {
04471                                 return IDO_ERROR;
04472                         }
04473         if(*(char **) data[3]==NULL) {
04474                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hostdefinition_definition, ":X4")==IDO_ERROR) {
04475                         return IDO_ERROR;
04476                 }
04477         } else {
04478                         if(!OCI_BindString(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X4"), *(char **) data[3], 0)) {
04479                                 return IDO_ERROR;
04480                         }
04481         }
04482         if(*(char **) data[4]==NULL) {
04483                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hostdefinition_definition, ":X5")==IDO_ERROR) {
04484                         return IDO_ERROR;
04485                 }
04486         } else {
04487                         if(!OCI_BindString(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X5"), *(char **) data[4], 0)) {
04488                                 return IDO_ERROR;
04489                         }
04490         }
04491         if(*(char **) data[5]==NULL) {
04492                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hostdefinition_definition, ":X6")==IDO_ERROR) {
04493                         return IDO_ERROR;
04494                 }
04495         } else {
04496                         if(!OCI_BindString(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X6"), *(char **) data[5], 0)) {
04497                                 return IDO_ERROR;
04498                         }
04499         }
04500                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X7"), (big_uint *) data[6])) {
04501                                 return IDO_ERROR;
04502                         }
04503         if(*(char **) data[7]==NULL) {
04504                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hostdefinition_definition, ":X8")==IDO_ERROR) {
04505                         return IDO_ERROR;
04506                 }
04507         } else {
04508                         if(!OCI_BindString(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X8"), *(char **) data[7], 0)) {
04509                                 return IDO_ERROR;
04510                         }
04511         }
04512                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X9"), (big_uint *) data[8])) {
04513                                 return IDO_ERROR;
04514                         }
04515         if(*(char **) data[9]==NULL) {
04516                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hostdefinition_definition, ":X10")==IDO_ERROR) {
04517                         return IDO_ERROR;
04518                 }
04519         } else {
04520                         if(!OCI_BindString(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X10"), *(char **) data[9], 0)) {
04521                                 return IDO_ERROR;
04522                         }
04523         }
04524                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X11"), (big_uint *) data[10])) {
04525                                 return IDO_ERROR;
04526                         }
04527                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X12"), (big_uint *) data[11])) {
04528                                 return IDO_ERROR;
04529                         }
04530         if(*(char **) data[12]==NULL) {
04531                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hostdefinition_definition, ":X13")==IDO_ERROR) {
04532                         return IDO_ERROR;
04533                 }
04534         } else {
04535                         if(!OCI_BindString(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X13"), *(char **) data[12], 0)) {
04536                                 return IDO_ERROR;
04537                         }
04538         }
04539                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X14"), (double *) data[13])) {
04540                                 return IDO_ERROR;
04541                         }
04542                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X15"), (double *) data[14])) {
04543                                 return IDO_ERROR;
04544                         }
04545                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X16"), (int *) data[15])) {
04546                                 return IDO_ERROR;
04547                         }
04548                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X17"), (double *) data[16])) {
04549                                 return IDO_ERROR;
04550                         }
04551                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X18"), (double *) data[17])) {
04552                                 return IDO_ERROR;
04553                         }
04554                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X19"), (int *) data[18])) {
04555                                 return IDO_ERROR;
04556                         }
04557                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X20"), (int *) data[19])) {
04558                                 return IDO_ERROR;
04559                         }
04560                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X21"), (int *) data[20])) {
04561                                 return IDO_ERROR;
04562                         }
04563                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X22"), (int *) data[21])) {
04564                                 return IDO_ERROR;
04565                         }
04566                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X23"), (int *) data[22])) {
04567                                 return IDO_ERROR;
04568                         }
04569                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X24"), (int *) data[23])) {
04570                                 return IDO_ERROR;
04571                         }
04572                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X25"), (int *) data[24])) {
04573                                 return IDO_ERROR;
04574                         }
04575                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X26"), (int *) data[25])) {
04576                                 return IDO_ERROR;
04577                         }
04578                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X27"), (int *) data[26])) {
04579                                 return IDO_ERROR;
04580                         }
04581                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X28"), (int *) data[27])) {
04582                                 return IDO_ERROR;
04583                         }
04584                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X29"), (int *) data[28])) {
04585                                 return IDO_ERROR;
04586                         }
04587                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X30"), (int *) data[29])) {
04588                                 return IDO_ERROR;
04589                         }
04590                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X31"), (double *) data[30])) {
04591                                 return IDO_ERROR;
04592                         }
04593                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X32"), (double *) data[31])) {
04594                                 return IDO_ERROR;
04595                         }
04596                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X33"), (int *) data[32])) {
04597                                 return IDO_ERROR;
04598                         }
04599                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X34"), (int *) data[33])) {
04600                                 return IDO_ERROR;
04601                         }
04602                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X35"), (int *) data[34])) {
04603                                 return IDO_ERROR;
04604                         }
04605                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X36"), (int *) data[35])) {
04606                                 return IDO_ERROR;
04607                         }
04608                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X37"), (int *) data[36])) {
04609                                 return IDO_ERROR;
04610                         }
04611                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X38"), (int *) data[37])) {
04612                                 return IDO_ERROR;
04613                         }
04614                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X39"), (int *) data[38])) {
04615                                 return IDO_ERROR;
04616                         }
04617                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X40"), (int *) data[39])) {
04618                                 return IDO_ERROR;
04619                         }
04620                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X41"), (int *) data[40])) {
04621                                 return IDO_ERROR;
04622                         }
04623                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X42"), (int *) data[41])) {
04624                                 return IDO_ERROR;
04625                         }
04626                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X43"), (int *) data[42])) {
04627                                 return IDO_ERROR;
04628                         }
04629         if(*(char **) data[43]==NULL) {
04630                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hostdefinition_definition, ":X44")==IDO_ERROR) {
04631                         return IDO_ERROR;
04632                 }
04633         } else {
04634                         if(!OCI_BindString(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X44"), *(char **) data[43], 0)) {
04635                                 return IDO_ERROR;
04636                         }
04637         }
04638         if(*(char **) data[44]==NULL) {
04639                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hostdefinition_definition, ":X45")==IDO_ERROR) {
04640                         return IDO_ERROR;
04641                 }
04642         } else {
04643                         if(!OCI_BindString(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X45"), *(char **) data[44], 0)) {
04644                                 return IDO_ERROR;
04645                         }
04646         }
04647         if(*(char **) data[45]==NULL) {
04648                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hostdefinition_definition, ":X46")==IDO_ERROR) {
04649                         return IDO_ERROR;
04650                 }
04651         } else {
04652                         if(!OCI_BindString(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X46"), *(char **) data[45], 0)) {
04653                                 return IDO_ERROR;
04654                         }
04655         }
04656         if(*(char **) data[46]==NULL) {
04657                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hostdefinition_definition, ":X47")==IDO_ERROR) {
04658                         return IDO_ERROR;
04659                 }
04660         } else {
04661                         if(!OCI_BindString(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X47"), *(char **) data[46], 0)) {
04662                                 return IDO_ERROR;
04663                         }
04664         }
04665         if(*(char **) data[47]==NULL) {
04666                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hostdefinition_definition, ":X48")==IDO_ERROR) {
04667                         return IDO_ERROR;
04668                 }
04669         } else {
04670                         if(!OCI_BindString(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X48"), *(char **) data[47], 0)) {
04671                                 return IDO_ERROR;
04672                         }
04673         }
04674         if(*(char **) data[48]==NULL) {
04675                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hostdefinition_definition, ":X49")==IDO_ERROR) {
04676                         return IDO_ERROR;
04677                 }
04678         } else {
04679                         if(!OCI_BindString(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X49"), *(char **) data[48], 0)) {
04680                                 return IDO_ERROR;
04681                         }
04682         }
04683         if(*(char **) data[49]==NULL) {
04684                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hostdefinition_definition, ":X50")==IDO_ERROR) {
04685                         return IDO_ERROR;
04686                 }
04687         } else {
04688                         if(!OCI_BindString(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X50"), *(char **) data[49], 0)) {
04689                                 return IDO_ERROR;
04690                         }
04691         }
04692                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X51"), (int *) data[50])) {
04693                                 return IDO_ERROR;
04694                         }
04695                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X52"), (int *) data[51])) {
04696                                 return IDO_ERROR;
04697                         }
04698                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X53"), (int *) data[52])) {
04699                                 return IDO_ERROR;
04700                         }
04701                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X54"), (int *) data[53])) {
04702                                 return IDO_ERROR;
04703                         }
04704                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X55"), (double *) data[54])) {
04705                                 return IDO_ERROR;
04706                         }
04707                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X56"), (double *) data[55])) {
04708                                 return IDO_ERROR;
04709                         }
04710                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X57"), (double *) data[56])) {
04711                                 return IDO_ERROR;
04712                         }
04713         if(*(char **) data[57]==NULL) {
04714                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hostdefinition_definition, ":X58")==IDO_ERROR) {
04715                         return IDO_ERROR;
04716                 }
04717         } else {
04718                         if(!OCI_BindString(idi->dbinfo.oci_statement_hostdefinition_definition, MT(":X58"), *(char **) data[57], 0)) {
04719                                 return IDO_ERROR;
04720                         }
04721         }
04722 
04723                         /* execute statement */
04724                         if(!OCI_Execute(idi->dbinfo.oci_statement_hostdefinition_definition)) {
04725                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_hostdefinition_definition() execute error\n");
04726                                 return IDO_ERROR;
04727                         }
04728 
04729                         /* commit statement */
04730                         OCI_Commit(idi->dbinfo.oci_connection);
04731 
04732                         /* do not free statement yet! */
04733 #endif
04734         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hostdefinition_definition_add() end\n");
04735 
04736         return result;
04737 }
04738 
04739 
04740 int ido2db_query_insert_or_update_hostdefinition_parenthosts_add(ido2db_idi *idi, void **data) {
04741         int result = IDO_OK;
04742 #ifdef USE_LIBDBI
04743         char * query1 = NULL;
04744         char * query2 = NULL;
04745 #endif
04746         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hostdefinition_parenthosts_add() start\n");
04747 
04748         if (idi == NULL)
04749                 return IDO_ERROR;
04750 
04751         if (idi->dbinfo.connected == IDO_FALSE)
04752                 return IDO_ERROR;
04753 
04754 #ifdef USE_LIBDBI /* everything else will be libdbi */
04755         switch (idi->dbinfo.server_type) {
04756                 case IDO2DB_DBSERVER_MYSQL:
04757                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, host_id, parent_host_object_id) VALUES (%lu, %lu, %lu) ON DUPLICATE KEY UPDATE instance_id=%lu",
04758                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTPARENTHOSTS],
04759                                         *(unsigned long *) data[0],     /* insert start */
04760                                         *(unsigned long *) data[1],     
04761                                         *(unsigned long *) data[2],     /* insert end */
04762                                         *(unsigned long *) data[0]      /* update start/end */
04763                         );
04764                         /* send query to db */
04765                         result = ido2db_db_query(idi, query1);
04766                         free(query1);
04767                         break;
04768                 case IDO2DB_DBSERVER_PGSQL:
04769                         dummy=asprintf(&query1, "UPDATE %s SET instance_id=%lu WHERE host_id=%lu AND parent_host_object_id=%lu",
04770                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTPARENTHOSTS],
04771                                         *(unsigned long *) data[0],     /* update start/end */
04772                                         *(unsigned long *) data[1],     /* unique constraint start */
04773                                         *(unsigned long *) data[2]      /* unique constraint end */
04774                         );
04775                         /* send query to db */
04776                         result = ido2db_db_query(idi, query1);
04777                         free(query1);
04778 
04779                         /* check result if update was ok */
04780                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
04781                                 /* try insert instead */
04782                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, host_id, parent_host_object_id) VALUES (%lu, %lu, %lu)",
04783                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTPARENTHOSTS],
04784                                         *(unsigned long *) data[0],     /* insert start */
04785                                         *(unsigned long *) data[1],     
04786                                         *(unsigned long *) data[2]     /* insert end */
04787                                 );
04788                                 /* send query to db */
04789                                 result = ido2db_db_query(idi, query2);
04790                                 free(query2);
04791                         }
04792                         break;
04793                 case IDO2DB_DBSERVER_DB2:
04794                         break;
04795                 case IDO2DB_DBSERVER_FIREBIRD:
04796                         break;
04797                 case IDO2DB_DBSERVER_FREETDS:
04798                         break;
04799                 case IDO2DB_DBSERVER_INGRES:
04800                         break;
04801                 case IDO2DB_DBSERVER_MSQL:
04802                         break;
04803                 case IDO2DB_DBSERVER_ORACLE:
04804                         break;
04805                 case IDO2DB_DBSERVER_SQLITE:
04806                         break;
04807                 case IDO2DB_DBSERVER_SQLITE3:
04808                         break;
04809                 default:
04810                         break;
04811         }
04812 #endif
04813 
04814 #ifdef USE_PGSQL /* pgsql */
04815 
04816 #endif
04817 
04818 #ifdef USE_ORACLE /* Oracle ocilib specific */
04819 
04820         /* check if we lost connection, and reconnect */
04821         if(ido2db_db_reconnect(idi)==IDO_ERROR)
04822                 return IDO_ERROR;
04823 
04824                         /* use prepared statements and ocilib */
04825                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostdefinition_parenthosts, MT(":X1"), (big_uint *) data[0])) {
04826                                 return IDO_ERROR;
04827                         }
04828                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostdefinition_parenthosts, MT(":X2"), (big_uint *) data[1])) {
04829                                 return IDO_ERROR;
04830                         }
04831                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostdefinition_parenthosts, MT(":X3"), (big_uint *) data[2])) {
04832                                 return IDO_ERROR;
04833                         }
04834 
04835                         /* execute statement */
04836                         if(!OCI_Execute(idi->dbinfo.oci_statement_hostdefinition_parenthosts)) {
04837                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_hostdefinition_parenthosts() execute error\n");
04838                                 return IDO_ERROR;
04839                         }
04840 
04841                         /* commit statement */
04842                         OCI_Commit(idi->dbinfo.oci_connection);
04843 
04844                         /* do not free statement yet! */
04845 #endif
04846         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hostdefinition_parenthosts_add() end\n");
04847 
04848         return result;
04849 }
04850 
04851 
04852 int ido2db_query_insert_or_update_hostdefinition_contactgroups_add(ido2db_idi *idi, void **data) {
04853         int result = IDO_OK;
04854 #ifdef USE_LIBDBI
04855         char * query1 = NULL;
04856         char * query2 = NULL;
04857 #endif
04858         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hostdefinition_contactgroups_add() start\n");
04859 
04860         if (idi == NULL)
04861                 return IDO_ERROR;
04862 
04863         if (idi->dbinfo.connected == IDO_FALSE)
04864                 return IDO_ERROR;
04865 
04866 #ifdef USE_LIBDBI /* everything else will be libdbi */
04867         switch (idi->dbinfo.server_type) {
04868                 case IDO2DB_DBSERVER_MYSQL:
04869                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, host_id, contactgroup_object_id) VALUES ('%lu', '%lu', '%lu') ON DUPLICATE KEY UPDATE instance_id='%lu'",
04870                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTCONTACTGROUPS],
04871                                         *(unsigned long *) data[0],     /* insert start */
04872                                         *(unsigned long *) data[1],     
04873                                         *(unsigned long *) data[2],     /* insert end */
04874                                         *(unsigned long *) data[0]      /* update start/end */
04875                         );
04876                         /* send query to db */
04877                         result = ido2db_db_query(idi, query1);
04878                         free(query1);
04879                         break;
04880                 case IDO2DB_DBSERVER_PGSQL:
04881                         dummy=asprintf(&query1, "UPDATE %s SET instance_id='%lu' WHERE host_id='%lu' AND contactgroup_object_id='%lu'",
04882                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTCONTACTGROUPS],
04883                                         *(unsigned long *) data[0],     /* update start/end */
04884                                         *(unsigned long *) data[1],     /* unique constraint start */
04885                                         *(unsigned long *) data[2]     /* unique constraint end */
04886                         );
04887                         /* send query to db */
04888                         result = ido2db_db_query(idi, query1);
04889                         free(query1);
04890 
04891                         /* check result if update was ok */
04892                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
04893                                 /* try insert instead */
04894                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, host_id, contactgroup_object_id) VALUES ('%lu', '%lu', '%lu')",
04895                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTCONTACTGROUPS],
04896                                         *(unsigned long *) data[0],     /* insert start */
04897                                         *(unsigned long *) data[1],     
04898                                         *(unsigned long *) data[2]     /* insert end */
04899                                 );
04900                                 /* send query to db */
04901                                 result = ido2db_db_query(idi, query2);
04902                                 free(query2);
04903                         }
04904                         break;
04905                 case IDO2DB_DBSERVER_DB2:
04906                         break;
04907                 case IDO2DB_DBSERVER_FIREBIRD:
04908                         break;
04909                 case IDO2DB_DBSERVER_FREETDS:
04910                         break;
04911                 case IDO2DB_DBSERVER_INGRES:
04912                         break;
04913                 case IDO2DB_DBSERVER_MSQL:
04914                         break;
04915                 case IDO2DB_DBSERVER_ORACLE:
04916                         break;
04917                 case IDO2DB_DBSERVER_SQLITE:
04918                         break;
04919                 case IDO2DB_DBSERVER_SQLITE3:
04920                         break;
04921                 default:
04922                         break;
04923         }
04924 #endif
04925 
04926 #ifdef USE_PGSQL /* pgsql */
04927 
04928 #endif
04929 
04930 #ifdef USE_ORACLE /* Oracle ocilib specific */
04931 
04932         /* check if we lost connection, and reconnect */
04933         if(ido2db_db_reconnect(idi)==IDO_ERROR)
04934                 return IDO_ERROR;
04935 
04936                         /* use prepared statements and ocilib */
04937                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostdefinition_contactgroups, MT(":X1"), (big_uint *) data[0])) {
04938                                 return IDO_ERROR;
04939                         }
04940                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostdefinition_contactgroups, MT(":X2"), (big_uint *) data[1])) {
04941                                 return IDO_ERROR;
04942                         }
04943                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostdefinition_contactgroups, MT(":X3"), (big_uint *) data[2])) {
04944                                 return IDO_ERROR;
04945                         }
04946 
04947                         /* execute statement */
04948                         if(!OCI_Execute(idi->dbinfo.oci_statement_hostdefinition_contactgroups)) {
04949                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_hostdefinition_contactgroups() execute error\n");
04950                                 return IDO_ERROR;
04951                         }
04952 
04953                         /* commit statement */
04954                         OCI_Commit(idi->dbinfo.oci_connection);
04955 
04956                         /* do not free statement yet! */
04957 #endif
04958         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hostdefinition_contactgroups_add() end\n");
04959 
04960         return result;
04961 }
04962 
04963 
04964 /************************************/
04965 /* HOSTGROUPDEFINITION              */
04966 /************************************/
04967 
04968 int ido2db_query_insert_or_update_hostgroupdefinition_definition_add(ido2db_idi *idi, void **data) {
04969         int result = IDO_OK;
04970 #ifdef USE_LIBDBI
04971         char * query1 = NULL;
04972         char * query2 = NULL;
04973 #endif
04974         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hostgroupdefinition_definition_add() start\n");
04975 
04976         if (idi == NULL)
04977                 return IDO_ERROR;
04978 
04979         if (idi->dbinfo.connected == IDO_FALSE)
04980                 return IDO_ERROR;
04981 
04982 #ifdef USE_LIBDBI /* everything else will be libdbi */
04983         switch (idi->dbinfo.server_type) {
04984                 case IDO2DB_DBSERVER_MYSQL:
04985                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, config_type, hostgroup_object_id, alias) VALUES (%lu, %d, %lu, '%s') ON DUPLICATE KEY UPDATE config_type=%d, alias='%s'",
04986                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTGROUPS],
04987                                         *(unsigned long *) data[0],     /* insert start */
04988                                         *(int *) data[1],
04989                                         *(unsigned long *) data[2],
04990                                         *(char **) data[3],             /* insert end */
04991                                         *(int *) data[1],               /* update start */
04992                                         *(char **) data[3]             /* update end */
04993                         );
04994                         /* send query to db */
04995                         result = ido2db_db_query(idi, query1);
04996                         free(query1);
04997                         break;
04998                 case IDO2DB_DBSERVER_PGSQL:
04999                         dummy=asprintf(&query1, "UPDATE %s SET config_type=%d, alias='%s' WHERE instance_id=%lu AND hostgroup_object_id=%lu",
05000                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTGROUPS],
05001                                         *(int *) data[1],               /* update start */
05002                                         *(char **) data[3],             /* update end */
05003                                         *(unsigned long *) data[0],     /* unique constraint start */
05004                                         *(unsigned long *) data[2]      /* unique constraint end */
05005                         );
05006                         /* send query to db */
05007                         result = ido2db_db_query(idi, query1);
05008                         free(query1);
05009 
05010                         /* check result if update was ok */
05011                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
05012                                 /* try insert instead */
05013                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, config_type, hostgroup_object_id, alias) VALUES (%lu, %d, %lu, '%s')",
05014                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTGROUPS],
05015                                         *(unsigned long *) data[0],     /* insert start */
05016                                         *(int *) data[1],
05017                                         *(unsigned long *) data[2],
05018                                         *(char **) data[3]             /* insert end */
05019                                 );
05020                                 /* send query to db */
05021                                 result = ido2db_db_query(idi, query2);
05022                                 free(query2);
05023                         }
05024                         break;
05025                 case IDO2DB_DBSERVER_DB2:
05026                         break;
05027                 case IDO2DB_DBSERVER_FIREBIRD:
05028                         break;
05029                 case IDO2DB_DBSERVER_FREETDS:
05030                         break;
05031                 case IDO2DB_DBSERVER_INGRES:
05032                         break;
05033                 case IDO2DB_DBSERVER_MSQL:
05034                         break;
05035                 case IDO2DB_DBSERVER_ORACLE:
05036                         break;
05037                 case IDO2DB_DBSERVER_SQLITE:
05038                         break;
05039                 case IDO2DB_DBSERVER_SQLITE3:
05040                         break;
05041                 default:
05042                         break;
05043         }
05044 #endif
05045 
05046 #ifdef USE_PGSQL /* pgsql */
05047 
05048 #endif
05049 
05050 #ifdef USE_ORACLE /* Oracle ocilib specific */
05051 
05052         /* check if we lost connection, and reconnect */
05053         if(ido2db_db_reconnect(idi)==IDO_ERROR)
05054                 return IDO_ERROR;
05055 
05056                         /* use prepared statements and ocilib */
05057                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostgroupdefinition_definition, MT(":X1"), (big_uint *) data[0])) {
05058                                 return IDO_ERROR;
05059                         }
05060                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostgroupdefinition_definition, MT(":X2"), (int *) data[1])) {
05061                                 return IDO_ERROR;
05062                         }
05063                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostgroupdefinition_definition, MT(":X3"), (big_uint *) data[2])) {
05064                                 return IDO_ERROR;
05065                         }
05066         if(*(char **) data[3]==NULL) {
05067                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_hostgroupdefinition_definition, ":X4")==IDO_ERROR) {
05068                         return IDO_ERROR;
05069                 }
05070         } else {
05071                         if(!OCI_BindString(idi->dbinfo.oci_statement_hostgroupdefinition_definition, MT(":X4"), *(char **) data[3], 0)) {
05072                                 return IDO_ERROR;
05073                         }
05074         }
05075 
05076                         /* execute statement */
05077                         if(!OCI_Execute(idi->dbinfo.oci_statement_hostgroupdefinition_definition)) {
05078                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_hostgroupdefinition_definition() execute error\n");
05079                                 return IDO_ERROR;
05080                         }
05081 
05082                         /* commit statement */
05083                         OCI_Commit(idi->dbinfo.oci_connection);
05084 
05085                         /* do not free statement yet! */
05086 #endif
05087         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hostgroupdefinition_definition_add() end\n");
05088 
05089         return result;
05090 }
05091 
05092 
05093 int ido2db_query_insert_or_update_hostgroupdefinition_hostgroupmembers_add(ido2db_idi *idi, void **data) {
05094         int result = IDO_OK;
05095 #ifdef USE_LIBDBI
05096         char * query1 = NULL;
05097         char * query2 = NULL;
05098 #endif
05099         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hostgroupdefinition_hostgroupmembers_add() start\n");
05100 
05101         if (idi == NULL)
05102                 return IDO_ERROR;
05103 
05104         if (idi->dbinfo.connected == IDO_FALSE)
05105                 return IDO_ERROR;
05106 
05107 #ifdef USE_LIBDBI /* everything else will be libdbi */
05108         switch (idi->dbinfo.server_type) {
05109                 case IDO2DB_DBSERVER_MYSQL:
05110                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, hostgroup_id, host_object_id) VALUES (%lu, %lu, %lu) ON DUPLICATE KEY UPDATE instance_id=%lu",
05111                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTGROUPMEMBERS],
05112                                         *(unsigned long *) data[0],     /* insert start */
05113                                         *(unsigned long *) data[1],     
05114                                         *(unsigned long *) data[2],     /* insert end */
05115                                         *(unsigned long *) data[0]     /* update start/end */
05116                         );
05117                         /* send query to db */
05118                         result = ido2db_db_query(idi, query1);
05119                         free(query1);
05120                         break;
05121                 case IDO2DB_DBSERVER_PGSQL:
05122                         dummy=asprintf(&query1, "UPDATE %s SET instance_id=%lu WHERE hostgroup_id=%lu AND host_object_id=%lu",
05123                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTGROUPMEMBERS],
05124                                         *(unsigned long *) data[0],     /* update start/end */
05125                                         *(unsigned long *) data[1],     /* unique constraint start */
05126                                         *(unsigned long *) data[2]      /* unique constraint end */
05127                         );
05128                         /* send query to db */
05129                         result = ido2db_db_query(idi, query1);
05130                         free(query1);
05131 
05132                         /* check result if update was ok */
05133                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
05134                                 /* try insert instead */
05135                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, hostgroup_id, host_object_id) VALUES (%lu, %lu, %lu)",
05136                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTGROUPMEMBERS],
05137                                         *(unsigned long *) data[0],     /* insert start */
05138                                         *(unsigned long *) data[1],     
05139                                         *(unsigned long *) data[2]     /* insert end */
05140                                 );
05141                                 /* send query to db */
05142                                 result = ido2db_db_query(idi, query2);
05143                                 free(query2);
05144                         }
05145                         break;
05146                 case IDO2DB_DBSERVER_DB2:
05147                         break;
05148                 case IDO2DB_DBSERVER_FIREBIRD:
05149                         break;
05150                 case IDO2DB_DBSERVER_FREETDS:
05151                         break;
05152                 case IDO2DB_DBSERVER_INGRES:
05153                         break;
05154                 case IDO2DB_DBSERVER_MSQL:
05155                         break;
05156                 case IDO2DB_DBSERVER_ORACLE:
05157                         break;
05158                 case IDO2DB_DBSERVER_SQLITE:
05159                         break;
05160                 case IDO2DB_DBSERVER_SQLITE3:
05161                         break;
05162                 default:
05163                         break;
05164         }
05165 #endif
05166 
05167 #ifdef USE_PGSQL /* pgsql */
05168 
05169 #endif
05170 
05171 #ifdef USE_ORACLE /* Oracle ocilib specific */
05172                         /* use prepared statements and ocilib */
05173                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostgroupdefinition_hostgroupmembers, MT(":X1"), (big_uint *) data[0])) {
05174                                 return IDO_ERROR;
05175                         }
05176                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostgroupdefinition_hostgroupmembers, MT(":X2"), (big_uint *) data[1])) {
05177                                 return IDO_ERROR;
05178                         }
05179                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostgroupdefinition_hostgroupmembers, MT(":X3"), (big_uint *) data[2])) {
05180                                 return IDO_ERROR;
05181                         }
05182 
05183                         /* execute statement */
05184                         if(!OCI_Execute(idi->dbinfo.oci_statement_hostgroupdefinition_hostgroupmembers)) {
05185                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_hostgroupdefinition_hostgroupmembers() execute error\n");
05186                                 return IDO_ERROR;
05187                         }
05188 
05189                         /* commit statement */
05190                         OCI_Commit(idi->dbinfo.oci_connection);
05191 
05192                         /* do not free statement yet! */
05193 #endif
05194         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hostgroupdefinition_hostgroupmembers_add() end\n");
05195 
05196         return result;
05197 }
05198 
05199 
05200 /************************************/
05201 /* SERVICEDEFINITION                */
05202 /************************************/
05203 
05204 int ido2db_query_insert_or_update_servicedefinition_definition_add(ido2db_idi *idi, void **data) {
05205         int result = IDO_OK;
05206 #ifdef USE_LIBDBI
05207         char * query1 = NULL;
05208         char * query2 = NULL;
05209 #endif
05210         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_servicedefinition_definition_add() start\n");
05211 
05212         if (idi == NULL)
05213                 return IDO_ERROR;
05214 
05215         if (idi->dbinfo.connected == IDO_FALSE)
05216                 return IDO_ERROR;
05217 
05218 #ifdef USE_LIBDBI /* everything else will be libdbi */
05219         switch (idi->dbinfo.server_type) {
05220                 case IDO2DB_DBSERVER_MYSQL:
05221                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, config_type, host_object_id, service_object_id, display_name, check_command_object_id, check_command_args, eventhandler_command_object_id, eventhandler_command_args, check_timeperiod_object_id, notification_timeperiod_object_id, failure_prediction_options, check_interval, retry_interval, max_check_attempts, first_notification_delay, notification_interval, notify_on_warning, notify_on_unknown, notify_on_critical, notify_on_recovery, notify_on_flapping, notify_on_downtime, stalk_on_ok, stalk_on_warning, stalk_on_unknown, stalk_on_critical, is_volatile, flap_detection_enabled, flap_detection_on_ok, flap_detection_on_warning, flap_detection_on_unknown, flap_detection_on_critical, low_flap_threshold, high_flap_threshold, process_performance_data, freshness_checks_enabled, freshness_threshold, passive_checks_enabled, event_handler_enabled, active_checks_enabled, retain_status_information, retain_nonstatus_information, notifications_enabled, obsess_over_service, failure_prediction_enabled, notes, notes_url, action_url, icon_image, icon_image_alt) VALUES (%lu, %d, %lu, %lu, '%s', %lu, '%s', %lu, '%s', %lu, %lu, '%s', %lf, %lf, %d, %lf, %lf, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %lf, %lf, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s') ON DUPLICATE KEY UPDATE host_object_id=%lu, display_name='%s', check_command_object_id=%lu, check_command_args='%s', eventhandler_command_object_id=%lu, eventhandler_command_args='%s', check_timeperiod_object_id=%lu, notification_timeperiod_object_id=%lu, failure_prediction_options='%s', check_interval=%lf, retry_interval=%lf, max_check_attempts=%d, first_notification_delay=%lf, notification_interval=%lf, notify_on_warning=%d, notify_on_unknown=%d, notify_on_critical=%d, notify_on_recovery=%d, notify_on_flapping=%d, notify_on_downtime=%d, stalk_on_ok=%d, stalk_on_warning=%d, stalk_on_unknown=%d, stalk_on_critical=%d, is_volatile=%d, flap_detection_enabled=%d, flap_detection_on_ok=%d, flap_detection_on_warning=%d, flap_detection_on_unknown=%d, flap_detection_on_critical=%d, low_flap_threshold=%lf, high_flap_threshold=%lf, process_performance_data=%d, freshness_checks_enabled=%d, freshness_threshold=%d, passive_checks_enabled=%d, event_handler_enabled=%d, active_checks_enabled=%d, retain_status_information=%d, retain_nonstatus_information=%d, notifications_enabled=%d, obsess_over_service=%d, failure_prediction_enabled=%d, notes='%s', notes_url='%s', action_url='%s', icon_image='%s', icon_image_alt='%s'",
05222                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICES],
05223                                         *(unsigned long *) data[0],     /* insert start */
05224                                         *(int *) data[1],
05225                                         *(unsigned long *) data[2],
05226                                         *(unsigned long *) data[3],
05227                                         *(char **) data[4],
05228                                         *(unsigned long *) data[5],
05229                                         (*(char **) data[6]==NULL)?"":*(char **) data[6],
05230                                         *(unsigned long *) data[7],
05231                                         (*(char **) data[8]==NULL)?"":*(char **) data[8],
05232                                         *(unsigned long *) data[9],
05233                                         *(unsigned long *) data[10],
05234                                         *(char **) data[11],
05235                                         *(double *) data[12],
05236                                         *(double *) data[13],
05237                                         *(int *) data[14],
05238                                         *(double *) data[15],
05239                                         *(double *) data[16],
05240                                         *(int *) data[17],
05241                                         *(int *) data[18],
05242                                         *(int *) data[19],
05243                                         *(int *) data[20],
05244                                         *(int *) data[21],
05245                                         *(int *) data[22],
05246                                         *(int *) data[23],
05247                                         *(int *) data[24],
05248                                         *(int *) data[25],
05249                                         *(int *) data[26],
05250                                         *(int *) data[27],
05251                                         *(int *) data[28],
05252                                         *(int *) data[29],
05253                                         *(int *) data[30],
05254                                         *(int *) data[31],
05255                                         *(int *) data[32],
05256                                         *(double *) data[33],
05257                                         *(double *) data[34],
05258                                         *(int *) data[35],
05259                                         *(int *) data[36],
05260                                         *(int *) data[37],
05261                                         *(int *) data[38],
05262                                         *(int *) data[39],
05263                                         *(int *) data[40],
05264                                         *(int *) data[41],
05265                                         *(int *) data[42],
05266                                         *(int *) data[43],
05267                                         *(int *) data[44],
05268                                         *(int *) data[45],
05269                                         *(char **) data[46],
05270                                         *(char **) data[47],
05271                                         *(char **) data[48],
05272                                         *(char **) data[49],
05273                                         *(char **) data[50],            /* insert end */
05274                                         *(unsigned long *) data[2],     /* update start */
05275                                         *(char **) data[4],
05276                                         *(unsigned long *) data[5],
05277                                         (*(char **) data[6]==NULL)?"":*(char **) data[6],
05278                                         *(unsigned long *) data[7],
05279                                         (*(char **) data[8]==NULL)?"":*(char **) data[8],
05280                                         *(unsigned long *) data[9],
05281                                         *(unsigned long *) data[10],
05282                                         *(char **) data[11],
05283                                         *(double *) data[12],
05284                                         *(double *) data[13],
05285                                         *(int *) data[14],
05286                                         *(double *) data[15],
05287                                         *(double *) data[16],
05288                                         *(int *) data[17],
05289                                         *(int *) data[18],
05290                                         *(int *) data[19],
05291                                         *(int *) data[20],
05292                                         *(int *) data[21],
05293                                         *(int *) data[22],
05294                                         *(int *) data[23],
05295                                         *(int *) data[24],
05296                                         *(int *) data[25],
05297                                         *(int *) data[26],
05298                                         *(int *) data[27],
05299                                         *(int *) data[28],
05300                                         *(int *) data[29],
05301                                         *(int *) data[30],
05302                                         *(int *) data[31],
05303                                         *(int *) data[32],
05304                                         *(double *) data[33],
05305                                         *(double *) data[34],
05306                                         *(int *) data[35],
05307                                         *(int *) data[36],
05308                                         *(int *) data[37],
05309                                         *(int *) data[38],
05310                                         *(int *) data[39],
05311                                         *(int *) data[40],
05312                                         *(int *) data[41],
05313                                         *(int *) data[42],
05314                                         *(int *) data[43],
05315                                         *(int *) data[44],
05316                                         *(int *) data[45],
05317                                         *(char **) data[46],
05318                                         *(char **) data[47],
05319                                         *(char **) data[48],
05320                                         *(char **) data[49],
05321                                         *(char **) data[50]            /* update end */
05322 
05323                         );
05324                         /* send query to db */
05325                         result = ido2db_db_query(idi, query1);
05326                         free(query1);
05327                         break;
05328                 case IDO2DB_DBSERVER_PGSQL:
05329                         dummy=asprintf(&query1, "UPDATE %s SET host_object_id=%lu, display_name='%s', check_command_object_id=%lu, check_command_args='%s', eventhandler_command_object_id=%lu, eventhandler_command_args='%s', check_timeperiod_object_id=%lu, notification_timeperiod_object_id=%lu, failure_prediction_options='%s', check_interval=%lf, retry_interval=%lf, max_check_attempts=%d, first_notification_delay=%lf, notification_interval=%lf, notify_on_warning=%d, notify_on_unknown=%d, notify_on_critical=%d, notify_on_recovery=%d, notify_on_flapping=%d, notify_on_downtime=%d, stalk_on_ok=%d, stalk_on_warning=%d, stalk_on_unknown=%d, stalk_on_critical=%d, is_volatile=%d, flap_detection_enabled=%d, flap_detection_on_ok=%d, flap_detection_on_warning=%d, flap_detection_on_unknown=%d, flap_detection_on_critical=%d, low_flap_threshold=%lf, high_flap_threshold=%lf, process_performance_data=%d, freshness_checks_enabled=%d, freshness_threshold=%d, passive_checks_enabled=%d, event_handler_enabled=%d, active_checks_enabled=%d, retain_status_information=%d, retain_nonstatus_information=%d, notifications_enabled=%d, obsess_over_service=%d, failure_prediction_enabled=%d, notes='%s', notes_url='%s', action_url='%s', icon_image='%s', icon_image_alt='%s' WHERE instance_id=%lu AND config_type=%d AND service_object_id=%lu",
05330                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICES],
05331                                         *(unsigned long *) data[2],     /* update start */
05332                                         *(char **) data[4],
05333                                         *(unsigned long *) data[5],
05334                                         (*(char **) data[6]==NULL)?"":*(char **) data[6],
05335                                         *(unsigned long *) data[7],
05336                                         (*(char **) data[8]==NULL)?"":*(char **) data[8],
05337                                         *(unsigned long *) data[9],
05338                                         *(unsigned long *) data[10],
05339                                         *(char **) data[11],
05340                                         *(double *) data[12],
05341                                         *(double *) data[13],
05342                                         *(int *) data[14],
05343                                         *(double *) data[15],
05344                                         *(double *) data[16],
05345                                         *(int *) data[17],
05346                                         *(int *) data[18],
05347                                         *(int *) data[19],
05348                                         *(int *) data[20],
05349                                         *(int *) data[21],
05350                                         *(int *) data[22],
05351                                         *(int *) data[23],
05352                                         *(int *) data[24],
05353                                         *(int *) data[25],
05354                                         *(int *) data[26],
05355                                         *(int *) data[27],
05356                                         *(int *) data[28],
05357                                         *(int *) data[29],
05358                                         *(int *) data[30],
05359                                         *(int *) data[31],
05360                                         *(int *) data[32],
05361                                         *(double *) data[33],
05362                                         *(double *) data[34],
05363                                         *(int *) data[35],
05364                                         *(int *) data[36],
05365                                         *(int *) data[37],
05366                                         *(int *) data[38],
05367                                         *(int *) data[39],
05368                                         *(int *) data[40],
05369                                         *(int *) data[41],
05370                                         *(int *) data[42],
05371                                         *(int *) data[43],
05372                                         *(int *) data[44],
05373                                         *(int *) data[45],
05374                                         *(char **) data[46],
05375                                         *(char **) data[47],
05376                                         *(char **) data[48],
05377                                         *(char **) data[49],
05378                                         *(char **) data[50],            /* update end */
05379                                         *(unsigned long *) data[0],     /* unique constraint start */
05380                                         *(int *) data[1],
05381                                         *(unsigned long *) data[3]      /* unique constraint end */
05382                         );
05383                         /* send query to db */
05384                         result = ido2db_db_query(idi, query1);
05385                         free(query1);
05386 
05387                         /* check result if update was ok */
05388                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
05389                                 /* try insert instead */
05390                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, config_type, host_object_id, service_object_id, display_name, check_command_object_id, check_command_args, eventhandler_command_object_id, eventhandler_command_args, check_timeperiod_object_id, notification_timeperiod_object_id, failure_prediction_options, check_interval, retry_interval, max_check_attempts, first_notification_delay, notification_interval, notify_on_warning, notify_on_unknown, notify_on_critical, notify_on_recovery, notify_on_flapping, notify_on_downtime, stalk_on_ok, stalk_on_warning, stalk_on_unknown, stalk_on_critical, is_volatile, flap_detection_enabled, flap_detection_on_ok, flap_detection_on_warning, flap_detection_on_unknown, flap_detection_on_critical, low_flap_threshold, high_flap_threshold, process_performance_data, freshness_checks_enabled, freshness_threshold, passive_checks_enabled, event_handler_enabled, active_checks_enabled, retain_status_information, retain_nonstatus_information, notifications_enabled, obsess_over_service, failure_prediction_enabled, notes, notes_url, action_url, icon_image, icon_image_alt) VALUES (%lu, %d, %lu, %lu, '%s', %lu, '%s', %lu, '%s', %lu, %lu, '%s', %lf, %lf, %d, %lf, %lf, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %lf, %lf, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s')",
05391                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICES],
05392                                         *(unsigned long *) data[0],     /* insert start */
05393                                         *(int *) data[1],
05394                                         *(unsigned long *) data[2],
05395                                         *(unsigned long *) data[3],
05396                                         *(char **) data[4],
05397                                         *(unsigned long *) data[5],
05398                                         (*(char **) data[6]==NULL)?"":*(char **) data[6],
05399                                         *(unsigned long *) data[7],
05400                                         (*(char **) data[8]==NULL)?"":*(char **) data[8],
05401                                         *(unsigned long *) data[9],
05402                                         *(unsigned long *) data[10],
05403                                         *(char **) data[11],
05404                                         *(double *) data[12],
05405                                         *(double *) data[13],
05406                                         *(int *) data[14],
05407                                         *(double *) data[15],
05408                                         *(double *) data[16],
05409                                         *(int *) data[17],
05410                                         *(int *) data[18],
05411                                         *(int *) data[19],
05412                                         *(int *) data[20],
05413                                         *(int *) data[21],
05414                                         *(int *) data[22],
05415                                         *(int *) data[23],
05416                                         *(int *) data[24],
05417                                         *(int *) data[25],
05418                                         *(int *) data[26],
05419                                         *(int *) data[27],
05420                                         *(int *) data[28],
05421                                         *(int *) data[29],
05422                                         *(int *) data[30],
05423                                         *(int *) data[31],
05424                                         *(int *) data[32],
05425                                         *(double *) data[33],
05426                                         *(double *) data[34],
05427                                         *(int *) data[35],
05428                                         *(int *) data[36],
05429                                         *(int *) data[37],
05430                                         *(int *) data[38],
05431                                         *(int *) data[39],
05432                                         *(int *) data[40],
05433                                         *(int *) data[41],
05434                                         *(int *) data[42],
05435                                         *(int *) data[43],
05436                                         *(int *) data[44],
05437                                         *(int *) data[45],
05438                                         *(char **) data[46],
05439                                         *(char **) data[47],
05440                                         *(char **) data[48],
05441                                         *(char **) data[49],
05442                                         *(char **) data[50]            /* insert end */
05443                                 );
05444                                 /* send query to db */
05445                                 result = ido2db_db_query(idi, query2);
05446                                 free(query2);
05447                         }
05448                         break;
05449                 case IDO2DB_DBSERVER_DB2:
05450                         break;
05451                 case IDO2DB_DBSERVER_FIREBIRD:
05452                         break;
05453                 case IDO2DB_DBSERVER_FREETDS:
05454                         break;
05455                 case IDO2DB_DBSERVER_INGRES:
05456                         break;
05457                 case IDO2DB_DBSERVER_MSQL:
05458                         break;
05459                 case IDO2DB_DBSERVER_ORACLE:
05460                         break;
05461                 case IDO2DB_DBSERVER_SQLITE:
05462                         break;
05463                 case IDO2DB_DBSERVER_SQLITE3:
05464                         break;
05465                 default:
05466                         break;
05467         }
05468 #endif
05469 
05470 #ifdef USE_PGSQL /* pgsql */
05471 
05472 #endif
05473 
05474 #ifdef USE_ORACLE /* Oracle ocilib specific */
05475 
05476         /* check if we lost connection, and reconnect */
05477         if(ido2db_db_reconnect(idi)==IDO_ERROR)
05478                 return IDO_ERROR;
05479 
05480                         /* use prepared statements and ocilib */
05481                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X1"), (big_uint *) data[0])) {
05482                                 return IDO_ERROR;
05483                         }
05484                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X2"), (int *) data[1])) {
05485                                 return IDO_ERROR;
05486                         }
05487                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X3"), (big_uint *) data[2])) {
05488                                 return IDO_ERROR;
05489                         }
05490                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X4"), (big_uint *) data[3])) {
05491                                 return IDO_ERROR;
05492                         }
05493         if(*(char **) data[4]==NULL) {
05494                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_servicedefinition_definition, ":X5")==IDO_ERROR) {
05495                         return IDO_ERROR;
05496                 }
05497         } else {
05498                         if(!OCI_BindString(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X5"), *(char **) data[4], 0)) {
05499                                 return IDO_ERROR;
05500                         }
05501         }
05502                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X6"), (big_uint *) data[5])) {
05503                                 return IDO_ERROR;
05504                         }
05505         if(*(char **) data[6]==NULL) {
05506                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_servicedefinition_definition, ":X7")==IDO_ERROR) {
05507                         return IDO_ERROR;
05508                 }
05509         } else {
05510                         if(!OCI_BindString(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X7"), *(char **) data[6], 0)) {
05511                                 return IDO_ERROR;
05512                         }
05513         }
05514                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X8"), (big_uint *) data[7])) {
05515                                 return IDO_ERROR;
05516                         }
05517         if(*(char **) data[8]==NULL) {
05518                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_servicedefinition_definition, ":X9")==IDO_ERROR) {
05519                         return IDO_ERROR;
05520                 }
05521         } else {
05522                         if(!OCI_BindString(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X9"), *(char **) data[8], 0)) {
05523                                 return IDO_ERROR;
05524                         }
05525         }
05526                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X10"), (big_uint *) data[9])) {
05527                                 return IDO_ERROR;
05528                         }
05529                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X11"), (big_uint *) data[10])) {
05530                                 return IDO_ERROR;
05531                         }
05532         if(*(char **) data[11]==NULL) {
05533                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_servicedefinition_definition, ":X12")==IDO_ERROR) {
05534                         return IDO_ERROR;
05535                 }
05536         } else {
05537                         if(!OCI_BindString(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X12"), *(char **) data[11], 0)) {
05538                                 return IDO_ERROR;
05539                         }
05540         }
05541 
05542 
05543                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X13"), (double *) data[12])) {
05544                                 return IDO_ERROR;
05545                         }
05546                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X14"), (double *) data[13])) {
05547                                 return IDO_ERROR;
05548                         }
05549                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X15"), (big_uint *) data[14])) {
05550                                 return IDO_ERROR;
05551                         }
05552                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X16"), (double *) data[15])) {
05553                                 return IDO_ERROR;
05554                         }
05555                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X17"), (double *) data[16])) {
05556                                 return IDO_ERROR;
05557                         }
05558                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X18"), (int *) data[17])) {
05559                                 return IDO_ERROR;
05560                         }
05561                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X19"), (int *) data[18])) {
05562                                 return IDO_ERROR;
05563                         }
05564                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X20"), (int *) data[19])) {
05565                                 return IDO_ERROR;
05566                         }
05567                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X21"), (int *) data[20])) {
05568                                 return IDO_ERROR;
05569                         }
05570                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X22"), (int *) data[21])) {
05571                                 return IDO_ERROR;
05572                         }
05573                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X23"), (int *) data[22])) {
05574                                 return IDO_ERROR;
05575                         }
05576                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X24"), (int *) data[23])) {
05577                                 return IDO_ERROR;
05578                         }
05579                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X25"), (int *) data[24])) {
05580                                 return IDO_ERROR;
05581                         }
05582                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X26"), (int *) data[25])) {
05583                                 return IDO_ERROR;
05584                         }
05585                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X27"), (int *) data[26])) {
05586                                 return IDO_ERROR;
05587                         }
05588                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X28"), (int *) data[27])) {
05589                                 return IDO_ERROR;
05590                         }
05591                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X29"), (int *) data[28])) {
05592                                 return IDO_ERROR;
05593                         }
05594                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X30"), (int *) data[29])) {
05595                                 return IDO_ERROR;
05596                         }
05597                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X31"), (int *) data[30])) {
05598                                 return IDO_ERROR;
05599                         }
05600                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X32"), (int *) data[31])) {
05601                                 return IDO_ERROR;
05602                         }
05603                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X33"), (int *) data[32])) {
05604                                 return IDO_ERROR;
05605                         }
05606                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X34"), (double *) data[33])) {
05607                                 return IDO_ERROR;
05608                         }
05609                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X35"), (double *) data[34])) {
05610                                 return IDO_ERROR;
05611                         }
05612                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X36"), (int *) data[35])) {
05613                                 return IDO_ERROR;
05614                         }
05615                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X37"), (int *) data[36])) {
05616                                 return IDO_ERROR;
05617                         }
05618                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X38"), (int *) data[37])) {
05619                                 return IDO_ERROR;
05620                         }
05621                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X39"), (int *) data[38])) {
05622                                 return IDO_ERROR;
05623                         }
05624                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X40"), (int *) data[39])) {
05625                                 return IDO_ERROR;
05626                         }
05627                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X41"), (int *) data[40])) {
05628                                 return IDO_ERROR;
05629                         }
05630                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X42"), (int *) data[41])) {
05631                                 return IDO_ERROR;
05632                         }
05633                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X43"), (int *) data[42])) {
05634                                 return IDO_ERROR;
05635                         }
05636                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X44"), (int *) data[43])) {
05637                                 return IDO_ERROR;
05638                         }
05639                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X45"), (int *) data[44])) {
05640                                 return IDO_ERROR;
05641                         }
05642                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X46"), (int *) data[45])) {
05643                                 return IDO_ERROR;
05644                         }
05645         if(*(char **) data[46]==NULL) {
05646                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_servicedefinition_definition, ":X47")==IDO_ERROR) {
05647                         return IDO_ERROR;
05648                 }
05649         } else {
05650                         if(!OCI_BindString(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X47"), *(char **) data[46], 0)) {
05651                                 return IDO_ERROR;
05652                         }
05653         }
05654         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_servicedefinition_definition_add() here5\n");
05655         if(*(char **) data[47]==NULL) {
05656                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_servicedefinition_definition, ":X48")==IDO_ERROR) {
05657                         return IDO_ERROR;
05658                 }
05659         } else {
05660                         if(!OCI_BindString(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X48"), *(char **) data[47], 0)) {
05661                                 return IDO_ERROR;
05662                         }
05663         }
05664         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_servicedefinition_definition_add() here6\n");
05665         if(*(char **) data[48]==NULL) {
05666                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_servicedefinition_definition, ":X49")==IDO_ERROR) {
05667                         return IDO_ERROR;
05668                 }
05669         } else {
05670                         if(!OCI_BindString(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X49"), *(char **) data[48], 0)) {
05671                                 return IDO_ERROR;
05672                         }
05673         }
05674         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_servicedefinition_definition_add() here7\n");
05675         if(*(char **) data[49]==NULL) {
05676                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_servicedefinition_definition, ":X50")==IDO_ERROR) {
05677                         return IDO_ERROR;
05678                 }
05679         } else {
05680                         if(!OCI_BindString(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X50"), *(char **) data[49], 0)) {
05681                                 return IDO_ERROR;
05682                         }
05683         }
05684         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_servicedefinition_definition_add() here8\n");
05685         if(*(char **) data[50]==NULL) {
05686                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_servicedefinition_definition, ":X51")==IDO_ERROR) {
05687                         return IDO_ERROR;
05688                 }
05689         } else {
05690                         if(!OCI_BindString(idi->dbinfo.oci_statement_servicedefinition_definition, MT(":X51"), *(char **) data[50], 0)) {
05691                                 return IDO_ERROR;
05692                         }
05693         }
05694 
05695                         /* execute statement */
05696                         if(!OCI_Execute(idi->dbinfo.oci_statement_servicedefinition_definition)) {
05697                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_servicedefinition_definition() execute error\n");
05698                                 return IDO_ERROR;
05699                         }
05700 
05701                         /* commit statement */
05702                         OCI_Commit(idi->dbinfo.oci_connection);
05703 
05704                         /* do not free statement yet! */
05705 #endif
05706         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_servicedefinition_definition_add() end\n");
05707 
05708         return result;
05709 }
05710 
05711 
05712 int ido2db_query_insert_or_update_servicedefinition_contactgroups_add(ido2db_idi *idi, void **data) {
05713         int result = IDO_OK;
05714 #ifdef USE_LIBDBI
05715         char * query1 = NULL;
05716         char * query2 = NULL;
05717 #endif
05718         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_servicedefinition_contactgroups_add() start\n");
05719 
05720         if (idi == NULL)
05721                 return IDO_ERROR;
05722 
05723         if (idi->dbinfo.connected == IDO_FALSE)
05724                 return IDO_ERROR;
05725 
05726 #ifdef USE_LIBDBI /* everything else will be libdbi */
05727         switch (idi->dbinfo.server_type) {
05728                 case IDO2DB_DBSERVER_MYSQL:
05729                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, service_id, contactgroup_object_id) VALUES ('%lu', '%lu', '%lu') ON DUPLICATE KEY UPDATE instance_id='%lu'",
05730                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICECONTACTGROUPS],
05731                                         *(unsigned long *) data[0],     /* insert start */
05732                                         *(unsigned long *) data[1],     
05733                                         *(unsigned long *) data[2],     /* insert end */
05734                                         *(unsigned long *) data[0]     /* update start/end */
05735                         );
05736                         /* send query to db */
05737                         result = ido2db_db_query(idi, query1);
05738                         free(query1);
05739                         break;
05740                 case IDO2DB_DBSERVER_PGSQL:
05741                         dummy=asprintf(&query1, "UPDATE %s SET instance_id='%lu' WHERE service_id='%lu' AND contactgroup_object_id='%lu'",
05742                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICECONTACTGROUPS],
05743                                         *(unsigned long *) data[0],     /* update start/end */
05744                                         *(unsigned long *) data[1],     /* unique constraint start */
05745                                         *(unsigned long *) data[2]     /* unique constraint end */
05746                         );
05747                         /* send query to db */
05748                         result = ido2db_db_query(idi, query1);
05749                         free(query1);
05750 
05751                         /* check result if update was ok */
05752                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
05753                                 /* try insert instead */
05754                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, service_id, contactgroup_object_id) VALUES ('%lu', '%lu', '%lu')",
05755                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICECONTACTGROUPS],
05756                                         *(unsigned long *) data[0],     /* insert start */
05757                                         *(unsigned long *) data[1],     
05758                                         *(unsigned long *) data[2]     /* insert end */
05759                                 );
05760                                 /* send query to db */
05761                                 result = ido2db_db_query(idi, query2);
05762                                 free(query2);
05763                         }
05764                         break;
05765                 case IDO2DB_DBSERVER_DB2:
05766                         break;
05767                 case IDO2DB_DBSERVER_FIREBIRD:
05768                         break;
05769                 case IDO2DB_DBSERVER_FREETDS:
05770                         break;
05771                 case IDO2DB_DBSERVER_INGRES:
05772                         break;
05773                 case IDO2DB_DBSERVER_MSQL:
05774                         break;
05775                 case IDO2DB_DBSERVER_ORACLE:
05776                         break;
05777                 case IDO2DB_DBSERVER_SQLITE:
05778                         break;
05779                 case IDO2DB_DBSERVER_SQLITE3:
05780                         break;
05781                 default:
05782                         break;
05783         }
05784 #endif
05785 
05786 #ifdef USE_PGSQL /* pgsql */
05787 
05788 #endif
05789 
05790 #ifdef USE_ORACLE /* Oracle ocilib specific */
05791 
05792         /* check if we lost connection, and reconnect */
05793         if(ido2db_db_reconnect(idi)==IDO_ERROR)
05794                 return IDO_ERROR;
05795 
05796                         /* use prepared statements and ocilib */
05797                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicedefinition_contactgroups, MT(":X1"), (big_uint *) data[0])) {
05798                                 return IDO_ERROR;
05799                         }
05800                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicedefinition_contactgroups, MT(":X2"), (big_uint *) data[1])) {
05801                                 return IDO_ERROR;
05802                         }
05803                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicedefinition_contactgroups, MT(":X3"), (big_uint *) data[2])) {
05804                                 return IDO_ERROR;
05805                         }
05806 
05807                         /* execute statement */
05808                         if(!OCI_Execute(idi->dbinfo.oci_statement_servicedefinition_contactgroups)) {
05809                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_servicedefinition_contactgroups() execute error\n");
05810                                 return IDO_ERROR;
05811                         }
05812 
05813                         /* commit statement */
05814                         OCI_Commit(idi->dbinfo.oci_connection);
05815 
05816                         /* do not free statement yet! */
05817 #endif
05818         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_servicedefinition_contactgroups_add() end\n");
05819 
05820         return result;
05821 }
05822 
05823 
05824 /************************************/
05825 /* SERVICEGROUPDEFINITION           */
05826 /************************************/
05827 
05828 int ido2db_query_insert_or_update_servicegroupdefinition_definition_add(ido2db_idi *idi, void **data) {
05829         int result = IDO_OK;
05830 #ifdef USE_LIBDBI
05831         char * query1 = NULL;
05832         char * query2 = NULL;
05833 #endif
05834         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_servicegroupdefinition_definition_add() start\n");
05835 
05836         if (idi == NULL)
05837                 return IDO_ERROR;
05838 
05839         if (idi->dbinfo.connected == IDO_FALSE)
05840                 return IDO_ERROR;
05841 
05842 #ifdef USE_LIBDBI /* everything else will be libdbi */
05843         switch (idi->dbinfo.server_type) {
05844                 case IDO2DB_DBSERVER_MYSQL:
05845                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, config_type, servicegroup_object_id, alias) VALUES (%lu, %d, %lu, '%s') ON DUPLICATE KEY UPDATE alias='%s'",
05846                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEGROUPS],
05847                                         *(unsigned long *) data[0],     /* insert start */
05848                                         *(int *) data[1],
05849                                         *(unsigned long *) data[2],
05850                                         *(char **) data[3],             /* insert end */
05851                                         *(char **) data[3]              /* update start/end */
05852                         );
05853                         /* send query to db */
05854                         result = ido2db_db_query(idi, query1);
05855                         free(query1);
05856                         break;
05857                 case IDO2DB_DBSERVER_PGSQL:
05858                         dummy=asprintf(&query1, "UPDATE %s SET alias='%s' WHERE instance_id=%lu AND config_type=%d AND servicegroup_object_id=%lu",
05859                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEGROUPS],
05860                                         *(char **) data[3],             /* update start/end */
05861                                         *(unsigned long *) data[0],     /* unique constraint start */
05862                                         *(int *) data[1],
05863                                         *(unsigned long *) data[2]      /* unique constraint end */
05864                         );
05865                         /* send query to db */
05866                         result = ido2db_db_query(idi, query1);
05867                         free(query1);
05868 
05869                         /* check result if update was ok */
05870                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
05871                                 /* try insert instead */
05872                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, config_type, servicegroup_object_id, alias) VALUES (%lu, %d, %lu, '%s')",
05873                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEGROUPS],
05874                                         *(unsigned long *) data[0],     /* insert start */
05875                                         *(int *) data[1],
05876                                         *(unsigned long *) data[2],
05877                                         *(char **) data[3]              /* insert end */
05878                                 );
05879                                 /* send query to db */
05880                                 result = ido2db_db_query(idi, query2);
05881                                 free(query2);
05882                         }
05883                         break;
05884                 case IDO2DB_DBSERVER_DB2:
05885                         break;
05886                 case IDO2DB_DBSERVER_FIREBIRD:
05887                         break;
05888                 case IDO2DB_DBSERVER_FREETDS:
05889                         break;
05890                 case IDO2DB_DBSERVER_INGRES:
05891                         break;
05892                 case IDO2DB_DBSERVER_MSQL:
05893                         break;
05894                 case IDO2DB_DBSERVER_ORACLE:
05895                         break;
05896                 case IDO2DB_DBSERVER_SQLITE:
05897                         break;
05898                 case IDO2DB_DBSERVER_SQLITE3:
05899                         break;
05900                 default:
05901                         break;
05902         }
05903 #endif
05904 
05905 #ifdef USE_PGSQL /* pgsql */
05906 
05907 #endif
05908 
05909 #ifdef USE_ORACLE /* Oracle ocilib specific */
05910 
05911         /* check if we lost connection, and reconnect */
05912         if(ido2db_db_reconnect(idi)==IDO_ERROR)
05913                 return IDO_ERROR;
05914 
05915                         /* use prepared statements and ocilib */
05916                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicegroupdefinition_definition, MT(":X1"), (big_uint *) data[0])) {
05917                                 return IDO_ERROR;
05918                         }
05919                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicegroupdefinition_definition, MT(":X2"), (int *) data[1])) {
05920                                 return IDO_ERROR;
05921                         }
05922                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicegroupdefinition_definition, MT(":X3"), (big_uint *) data[2])) {
05923                                 return IDO_ERROR;
05924                         }
05925         if(*(char **) data[3]==NULL) {
05926                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_servicegroupdefinition_definition, ":X3")==IDO_ERROR) {
05927                         return IDO_ERROR;
05928                 }
05929         } else {
05930                         if(!OCI_BindString(idi->dbinfo.oci_statement_servicegroupdefinition_definition, MT(":X4"), *(char **) data[3], 0)) {
05931                                 return IDO_ERROR;
05932                         }
05933         }
05934 
05935                         /* execute statement */
05936                         if(!OCI_Execute(idi->dbinfo.oci_statement_servicegroupdefinition_definition)) {
05937                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_servicegroupdefinition_definition() execute error\n");
05938                                 return IDO_ERROR;
05939                         }
05940 
05941                         /* commit statement */
05942                         OCI_Commit(idi->dbinfo.oci_connection);
05943 
05944                         /* do not free statement yet! */
05945 #endif
05946         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_servicegroupdefinition_definition_add() end\n");
05947 
05948         return result;
05949 }
05950 
05951 
05952 int ido2db_query_insert_or_update_servicegroupdefinition_members_add(ido2db_idi *idi, void **data) {
05953         int result = IDO_OK;
05954 #ifdef USE_LIBDBI
05955         char * query1 = NULL;
05956         char * query2 = NULL;
05957 #endif
05958         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_servicegroupdefinition_members_add() start\n");
05959 
05960         if (idi == NULL)
05961                 return IDO_ERROR;
05962 
05963         if (idi->dbinfo.connected == IDO_FALSE)
05964                 return IDO_ERROR;
05965 
05966 #ifdef USE_LIBDBI /* everything else will be libdbi */
05967         switch (idi->dbinfo.server_type) {
05968                 case IDO2DB_DBSERVER_MYSQL:
05969                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, servicegroup_id, service_object_id) VALUES (%lu, %lu, %lu) ON DUPLICATE KEY UPDATE instance_id=%lu",
05970                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEGROUPMEMBERS],
05971                                         *(unsigned long *) data[0],     /* insert start */
05972                                         *(unsigned long *) data[1],     
05973                                         *(unsigned long *) data[2],     /* insert end */
05974                                         *(unsigned long *) data[0]     /* update start/end */
05975                         );
05976                         /* send query to db */
05977                         result = ido2db_db_query(idi, query1);
05978                         free(query1);
05979                         break;
05980                 case IDO2DB_DBSERVER_PGSQL:
05981                         dummy=asprintf(&query1, "UPDATE %s SET instance_id=%lu WHERE servicegroup_id=%lu AND service_object_id=%lu",
05982                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEGROUPMEMBERS],
05983                                         *(unsigned long *) data[0],     /* update start/end */
05984                                         *(unsigned long *) data[1],     /* unique constraint start */
05985                                         *(unsigned long *) data[2]     /* unique constraint end */
05986                         );
05987                         /* send query to db */
05988                         result = ido2db_db_query(idi, query1);
05989                         free(query1);
05990 
05991                         /* check result if update was ok */
05992                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
05993                                 /* try insert instead */
05994                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, servicegroup_id, service_object_id) VALUES (%lu, %lu, %lu)",
05995                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEGROUPMEMBERS],
05996                                         *(unsigned long *) data[0],     /* insert start */
05997                                         *(unsigned long *) data[1],     
05998                                         *(unsigned long *) data[2]     /* insert end */
05999 
06000                                 );
06001                                 /* send query to db */
06002                                 result = ido2db_db_query(idi, query2);
06003                                 free(query2);
06004                         }
06005                         break;
06006                 case IDO2DB_DBSERVER_DB2:
06007                         break;
06008                 case IDO2DB_DBSERVER_FIREBIRD:
06009                         break;
06010                 case IDO2DB_DBSERVER_FREETDS:
06011                         break;
06012                 case IDO2DB_DBSERVER_INGRES:
06013                         break;
06014                 case IDO2DB_DBSERVER_MSQL:
06015                         break;
06016                 case IDO2DB_DBSERVER_ORACLE:
06017                         break;
06018                 case IDO2DB_DBSERVER_SQLITE:
06019                         break;
06020                 case IDO2DB_DBSERVER_SQLITE3:
06021                         break;
06022                 default:
06023                         break;
06024         }
06025 #endif
06026 
06027 #ifdef USE_PGSQL /* pgsql */
06028 
06029 #endif
06030 
06031 #ifdef USE_ORACLE /* Oracle ocilib specific */
06032 
06033         /* check if we lost connection, and reconnect */
06034         if(ido2db_db_reconnect(idi)==IDO_ERROR)
06035                 return IDO_ERROR;
06036 
06037                         /* use prepared statements and ocilib */
06038                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicegroupdefinition_members, MT(":X1"), (big_uint *) data[0])) {
06039                                 return IDO_ERROR;
06040                         }
06041                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicegroupdefinition_members, MT(":X2"), (big_uint *) data[1])) {
06042                                 return IDO_ERROR;
06043                         }
06044                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicegroupdefinition_members, MT(":X3"), (big_uint *) data[2])) {
06045                                 return IDO_ERROR;
06046                         }
06047 
06048                         /* execute statement */
06049                         if(!OCI_Execute(idi->dbinfo.oci_statement_servicegroupdefinition_members)) {
06050                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_servicegroupdefinition_members() execute error\n");
06051                                 return IDO_ERROR;
06052                         }
06053 
06054                         /* commit statement */
06055                         OCI_Commit(idi->dbinfo.oci_connection);
06056 
06057                         /* do not free statement yet! */
06058 #endif
06059         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_servicegroupdefinition_members_add() end\n");
06060 
06061         return result;
06062 }
06063 
06064 
06065 /************************************/
06066 /* HOSTDEPENDENCIES                 */
06067 /************************************/
06068 
06069 int ido2db_query_insert_or_update_hostdependencydefinition_definition_add(ido2db_idi *idi, void **data) {
06070         int result = IDO_OK;
06071 #ifdef USE_LIBDBI
06072         char * query1 = NULL;
06073         char * query2 = NULL;
06074 #endif
06075         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hostdependencydefinition_definition_add() start\n");
06076 
06077         if (idi == NULL)
06078                 return IDO_ERROR;
06079 
06080         if (idi->dbinfo.connected == IDO_FALSE)
06081                 return IDO_ERROR;
06082 
06083 #ifdef USE_LIBDBI /* everything else will be libdbi */
06084         switch (idi->dbinfo.server_type) {
06085                 case IDO2DB_DBSERVER_MYSQL:
06086                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, config_type, host_object_id, dependent_host_object_id, dependency_type, inherits_parent, timeperiod_object_id, fail_on_up, fail_on_down, fail_on_unreachable) VALUES (%lu, %d, %lu, %lu, %d, %d, %lu, %d, %d, %d) ON DUPLICATE KEY UPDATE timeperiod_object_id=%lu",
06087                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTDEPENDENCIES],
06088                                         *(unsigned long *) data[0],     /* insert start */
06089                                         *(int *) data[1],
06090                                         *(unsigned long *) data[2],
06091                                         *(unsigned long *) data[3],
06092                                         *(int *) data[4],
06093                                         *(int *) data[5],
06094                                         *(unsigned long *) data[6],
06095                                         *(int *) data[7],
06096                                         *(int *) data[8],
06097                                         *(int *) data[9],               /* insert end */
06098                                         *(unsigned long *) data[6]      /* update start/end */
06099                         );
06100                         /* send query to db */
06101                         result = ido2db_db_query(idi, query1);
06102                         free(query1);
06103                         break;
06104                 case IDO2DB_DBSERVER_PGSQL:
06105                         dummy=asprintf(&query1, "UPDATE %s SET timeperiod_object_id=%lu WHERE instance_id=%lu AND config_type=%d AND host_object_id=%lu AND dependent_host_object_id=%lu AND dependency_type=%d AND inherits_parent=%d AND fail_on_up=%d AND fail_on_down=%d AND fail_on_unreachable=%d",
06106                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTDEPENDENCIES],
06107                                         *(unsigned long *) data[6],     /* update start/end */
06108                                         *(unsigned long *) data[0],     /* unique constraint start */
06109                                         *(int *) data[1],
06110                                         *(unsigned long *) data[2],
06111                                         *(unsigned long *) data[3],
06112                                         *(int *) data[4],
06113                                         *(int *) data[5],
06114                                         *(int *) data[7],
06115                                         *(int *) data[8],
06116                                         *(int *) data[9]               /* unique constraint end */
06117                         );
06118                         /* send query to db */
06119                         result = ido2db_db_query(idi, query1);
06120                         free(query1);
06121 
06122                         /* check result if update was ok */
06123                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
06124                                 /* try insert instead */
06125                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, config_type, host_object_id, dependent_host_object_id, dependency_type, inherits_parent, timeperiod_object_id, fail_on_up, fail_on_down, fail_on_unreachable) VALUES (%lu, %d, %lu, %lu, %d, %d, %lu, %d, %d, %d)",
06126                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTDEPENDENCIES],
06127                                         *(unsigned long *) data[0],     /* insert start */
06128                                         *(int *) data[1],
06129                                         *(unsigned long *) data[2],
06130                                         *(unsigned long *) data[3],
06131                                         *(int *) data[4],
06132                                         *(int *) data[5],
06133                                         *(unsigned long *) data[6],
06134                                         *(int *) data[7],
06135                                         *(int *) data[8],
06136                                         *(int *) data[9]               /* insert end */
06137                                 );
06138                                 /* send query to db */
06139                                 result = ido2db_db_query(idi, query2);
06140                                 free(query2);
06141                         }
06142                         break;
06143                 case IDO2DB_DBSERVER_DB2:
06144                         break;
06145                 case IDO2DB_DBSERVER_FIREBIRD:
06146                         break;
06147                 case IDO2DB_DBSERVER_FREETDS:
06148                         break;
06149                 case IDO2DB_DBSERVER_INGRES:
06150                         break;
06151                 case IDO2DB_DBSERVER_MSQL:
06152                         break;
06153                 case IDO2DB_DBSERVER_ORACLE:
06154                         break;
06155                 case IDO2DB_DBSERVER_SQLITE:
06156                         break;
06157                 case IDO2DB_DBSERVER_SQLITE3:
06158                         break;
06159                 default:
06160                         break;
06161         }
06162 #endif
06163 
06164 #ifdef USE_PGSQL /* pgsql */
06165 
06166 #endif
06167 
06168 #ifdef USE_ORACLE /* Oracle ocilib specific */
06169 
06170         /* check if we lost connection, and reconnect */
06171         if(ido2db_db_reconnect(idi)==IDO_ERROR)
06172                 return IDO_ERROR;
06173 
06174                         /* use prepared statements and ocilib */
06175                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostdependencydefinition_definition, MT(":X1"), (big_uint *) data[0])) {
06176                                 return IDO_ERROR;
06177                         }
06178                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdependencydefinition_definition, MT(":X2"), (int *) data[1])) {
06179                                 return IDO_ERROR;
06180                         }
06181                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostdependencydefinition_definition, MT(":X3"), (big_uint *) data[2])) {
06182                                 return IDO_ERROR;
06183                         }
06184                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostdependencydefinition_definition, MT(":X4"), (big_uint *) data[3])) {
06185                                 return IDO_ERROR;
06186                         }
06187                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdependencydefinition_definition, MT(":X5"), (int *) data[4])) {
06188                                 return IDO_ERROR;
06189                         }
06190                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdependencydefinition_definition, MT(":X6"), (int *) data[5])) {
06191                                 return IDO_ERROR;
06192                         }
06193                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostdependencydefinition_definition, MT(":X7"), (big_uint *) data[6])) {
06194                                 return IDO_ERROR;
06195                         }
06196                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdependencydefinition_definition, MT(":X8"), (int *) data[7])) {
06197                                 return IDO_ERROR;
06198                         }
06199                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdependencydefinition_definition, MT(":X9"), (int *) data[8])) {
06200                                 return IDO_ERROR;
06201                         }
06202                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostdependencydefinition_definition, MT(":X10"), (int *) data[9])) {
06203                                 return IDO_ERROR;
06204                         }
06205 
06206                         /* execute statement */
06207                         if(!OCI_Execute(idi->dbinfo.oci_statement_hostdependencydefinition_definition)) {
06208                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_hostdependencydefinition_definition() execute error\n");
06209                                 return IDO_ERROR;
06210                         }
06211 
06212                         /* commit statement */
06213                         OCI_Commit(idi->dbinfo.oci_connection);
06214 
06215                         /* do not free statement yet! */
06216 #endif
06217         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hostdependencydefinition_definition_add() end\n");
06218 
06219         return result;
06220 }
06221 
06222 
06223 /************************************/
06224 /* SERVICEDEPENDENCYDEFINITION      */
06225 /************************************/
06226 
06227 int ido2db_query_insert_or_update_servicedependencydefinition_definition_add(ido2db_idi *idi, void **data) {
06228         int result = IDO_OK;
06229 #ifdef USE_LIBDBI
06230         char * query1 = NULL;
06231         char * query2 = NULL;
06232 #endif
06233         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_servicedependencydefinition_definition_add() start\n");
06234 
06235         if (idi == NULL)
06236                 return IDO_ERROR;
06237 
06238         if (idi->dbinfo.connected == IDO_FALSE)
06239                 return IDO_ERROR;
06240 
06241 #ifdef USE_LIBDBI /* everything else will be libdbi */
06242         switch (idi->dbinfo.server_type) {
06243                 case IDO2DB_DBSERVER_MYSQL:
06244                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, config_type, service_object_id, dependent_service_object_id, dependency_type, inherits_parent, timeperiod_object_id, fail_on_ok, fail_on_warning, fail_on_unknown, fail_on_critical) VALUES (%lu, %d, %lu, %lu, %d, %d, %lu, %d, %d, %d, %d) ON DUPLICATE KEY UPDATE timeperiod_object_id=%lu",
06245                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEDEPENDENCIES],
06246                                         *(unsigned long *) data[0],     /* insert start */
06247                                         *(int *) data[1],
06248                                         *(unsigned long *) data[2],
06249                                         *(unsigned long *) data[3],
06250                                         *(int *) data[4],
06251                                         *(int *) data[5],
06252                                         *(unsigned long *) data[6],
06253                                         *(int *) data[7],
06254                                         *(int *) data[8],
06255                                         *(int *) data[9],
06256                                         *(int *) data[10],              /* insert end */
06257                                         *(unsigned long *) data[6]      /* update start/end*/
06258                         );
06259                         /* send query to db */
06260                         result = ido2db_db_query(idi, query1);
06261                         free(query1);
06262                         break;
06263                 case IDO2DB_DBSERVER_PGSQL:
06264                         dummy=asprintf(&query1, "UPDATE %s SET timeperiod_object_id=%lu WHERE instance_id=%lu AND config_type=%d AND service_object_id=%lu AND dependent_service_object_id=%lu AND dependency_type=%d AND inherits_parent=%d AND fail_on_ok=%d AND fail_on_warning=%d AND fail_on_unknown=%d AND fail_on_critical=%d",
06265                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEDEPENDENCIES],
06266                                         *(unsigned long *) data[6],     /* update start/end*/
06267                                         *(unsigned long *) data[0],     /* unique constraint start */
06268                                         *(int *) data[1],
06269                                         *(unsigned long *) data[2],
06270                                         *(unsigned long *) data[3],
06271                                         *(int *) data[4],
06272                                         *(int *) data[5],
06273                                         *(int *) data[7],
06274                                         *(int *) data[8],
06275                                         *(int *) data[9],
06276                                         *(int *) data[10]              /* unique constraint end */
06277                         );
06278                         /* send query to db */
06279                         result = ido2db_db_query(idi, query1);
06280                         free(query1);
06281 
06282                         /* check result if update was ok */
06283                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
06284                                 /* try insert instead */
06285                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, config_type, service_object_id, dependent_service_object_id, dependency_type, inherits_parent, timeperiod_object_id, fail_on_ok, fail_on_warning, fail_on_unknown, fail_on_critical) VALUES (%lu, %d, %lu, %lu, %d, %d, %lu, %d, %d, %d, %d)",
06286                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEDEPENDENCIES],
06287                                         *(unsigned long *) data[0],     /* insert start */
06288                                         *(int *) data[1],
06289                                         *(unsigned long *) data[2],
06290                                         *(unsigned long *) data[3],
06291                                         *(int *) data[4],
06292                                         *(int *) data[5],
06293                                         *(unsigned long *) data[6],
06294                                         *(int *) data[7],
06295                                         *(int *) data[8],
06296                                         *(int *) data[9],
06297                                         *(int *) data[10]              /* insert end */
06298                                 );
06299                                 /* send query to db */
06300                                 result = ido2db_db_query(idi, query2);
06301                                 free(query2);
06302                         }
06303                         break;
06304                 case IDO2DB_DBSERVER_DB2:
06305                         break;
06306                 case IDO2DB_DBSERVER_FIREBIRD:
06307                         break;
06308                 case IDO2DB_DBSERVER_FREETDS:
06309                         break;
06310                 case IDO2DB_DBSERVER_INGRES:
06311                         break;
06312                 case IDO2DB_DBSERVER_MSQL:
06313                         break;
06314                 case IDO2DB_DBSERVER_ORACLE:
06315                         break;
06316                 case IDO2DB_DBSERVER_SQLITE:
06317                         break;
06318                 case IDO2DB_DBSERVER_SQLITE3:
06319                         break;
06320                 default:
06321                         break;
06322         }
06323 #endif
06324 
06325 #ifdef USE_PGSQL /* pgsql */
06326 
06327 #endif
06328 
06329 #ifdef USE_ORACLE /* Oracle ocilib specific */
06330 
06331         /* check if we lost connection, and reconnect */
06332         if(ido2db_db_reconnect(idi)==IDO_ERROR)
06333                 return IDO_ERROR;
06334 
06335                         /* use prepared statements and ocilib */
06336                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicedependencydefinition_definition, MT(":X1"), (big_uint *) data[0])) {
06337                                 return IDO_ERROR;
06338                         }
06339                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedependencydefinition_definition, MT(":X2"), (int *) data[1])) {
06340                                 return IDO_ERROR;
06341                         }
06342                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicedependencydefinition_definition, MT(":X3"), (big_uint *) data[2])) {
06343                                 return IDO_ERROR;
06344                         }
06345                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicedependencydefinition_definition, MT(":X4"), (big_uint *) data[3])) {
06346                                 return IDO_ERROR;
06347                         }
06348                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedependencydefinition_definition, MT(":X5"), (int *) data[4])) {
06349                                 return IDO_ERROR;
06350                         }
06351                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedependencydefinition_definition, MT(":X6"), (int *) data[5])) {
06352                                 return IDO_ERROR;
06353                         }
06354                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_servicedependencydefinition_definition, MT(":X7"), (big_uint *) data[6])) {
06355                                 return IDO_ERROR;
06356                         }
06357                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedependencydefinition_definition, MT(":X8"), (int *) data[7])) {
06358                                 return IDO_ERROR;
06359                         }
06360                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedependencydefinition_definition, MT(":X9"), (int *) data[8])) {
06361                                 return IDO_ERROR;
06362                         }
06363                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedependencydefinition_definition, MT(":X10"), (int *) data[9])) {
06364                                 return IDO_ERROR;
06365                         }
06366                         if(!OCI_BindInt(idi->dbinfo.oci_statement_servicedependencydefinition_definition, MT(":X11"), (int *) data[10])) {
06367                                 return IDO_ERROR;
06368                         }
06369 
06370                         /* execute statement */
06371                         if(!OCI_Execute(idi->dbinfo.oci_statement_servicedependencydefinition_definition)) {
06372                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_servicedependencydefinition_definition() execute error\n");
06373                                 return IDO_ERROR;
06374                         }
06375 
06376                         /* commit statement */
06377                         OCI_Commit(idi->dbinfo.oci_connection);
06378 
06379                         /* do not free statement yet! */
06380 #endif
06381         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_servicedependencydefinition_definition_add() end\n");
06382 
06383         return result;
06384 }
06385 
06386 
06387 /************************************/
06388 /* HOSTESCALATIONDEFINITION         */
06389 /************************************/
06390 
06391 int ido2db_query_insert_or_update_hostescalationdefinition_definition_add(ido2db_idi *idi, void **data) {
06392         int result = IDO_OK;
06393 #ifdef USE_LIBDBI
06394         char * query1 = NULL;
06395         char * query2 = NULL;
06396 #endif
06397         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hostescalationdefinition_definition_add() start\n");
06398 
06399         if (idi == NULL)
06400                 return IDO_ERROR;
06401 
06402         if (idi->dbinfo.connected == IDO_FALSE)
06403                 return IDO_ERROR;
06404 
06405 #ifdef USE_LIBDBI /* everything else will be libdbi */
06406         switch (idi->dbinfo.server_type) {
06407                 case IDO2DB_DBSERVER_MYSQL:
06408                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, config_type, host_object_id, timeperiod_object_id, first_notification, last_notification, notification_interval, escalate_on_recovery, escalate_on_down, escalate_on_unreachable) VALUES (%lu, %d, %lu, %lu, %d, %d, %lf, %d, %d, %d) ON DUPLICATE KEY UPDATE notification_interval=%lf, escalate_on_recovery=%d, escalate_on_down=%d, escalate_on_unreachable=%d",
06409                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTESCALATIONS],
06410                                         *(unsigned long *) data[0],     /* insert start */
06411                                         *(int *) data[1],
06412                                         *(unsigned long *) data[2],
06413                                         *(unsigned long *) data[3],
06414                                         *(int *) data[4],
06415                                         *(int *) data[5],
06416                                         *(double *) data[6],
06417                                         *(int *) data[7],
06418                                         *(int *) data[8],
06419                                         *(int *) data[9],               /* insert end */
06420                                         *(double *) data[6],            /* update start */
06421                                         *(int *) data[7],               
06422                                         *(int *) data[8],
06423                                         *(int *) data[9]                /* update end */
06424                         );
06425                         /* send query to db */
06426                         result = ido2db_db_query(idi, query1);
06427                         free(query1);
06428                         break;
06429                 case IDO2DB_DBSERVER_PGSQL:
06430                         dummy=asprintf(&query1, "UPDATE %s SET notification_interval=%lf, escalate_on_recovery=%d, escalate_on_down=%d, escalate_on_unreachable=%d WHERE instance_id=%lu AND config_type=%d AND host_object_id=%lu AND timeperiod_object_id=%lu AND first_notification=%d AND last_notification=%d",
06431                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTESCALATIONS],
06432                                         *(double *) data[6],            /* update start */
06433                                         *(int *) data[7],               
06434                                         *(int *) data[8],
06435                                         *(int *) data[9],               /* update end */
06436                                         *(unsigned long *) data[0],     /* unique constraint start */
06437                                         *(int *) data[1],
06438                                         *(unsigned long *) data[2],
06439                                         *(unsigned long *) data[3],
06440                                         *(int *) data[4],
06441                                         *(int *) data[5]                /* unique constraint end */
06442                         );
06443                         /* send query to db */
06444                         result = ido2db_db_query(idi, query1);
06445                         free(query1);
06446 
06447                         /* check result if update was ok */
06448                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
06449                                 /* try insert instead */
06450                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, config_type, host_object_id, timeperiod_object_id, first_notification, last_notification, notification_interval, escalate_on_recovery, escalate_on_down, escalate_on_unreachable) VALUES (%lu, %d, %lu, %lu, %d, %d, %lf, %d, %d, %d)",
06451                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTESCALATIONS],
06452                                         *(unsigned long *) data[0],     /* insert start */
06453                                         *(int *) data[1],
06454                                         *(unsigned long *) data[2],
06455                                         *(unsigned long *) data[3],
06456                                         *(int *) data[4],
06457                                         *(int *) data[5],
06458                                         *(double *) data[6],
06459                                         *(int *) data[7],
06460                                         *(int *) data[8],
06461                                         *(int *) data[9]                /* insert end */
06462                                 );
06463                                 /* send query to db */
06464                                 result = ido2db_db_query(idi, query2);
06465                                 free(query2);
06466                         }
06467                         break;
06468                 case IDO2DB_DBSERVER_DB2:
06469                         break;
06470                 case IDO2DB_DBSERVER_FIREBIRD:
06471                         break;
06472                 case IDO2DB_DBSERVER_FREETDS:
06473                         break;
06474                 case IDO2DB_DBSERVER_INGRES:
06475                         break;
06476                 case IDO2DB_DBSERVER_MSQL:
06477                         break;
06478                 case IDO2DB_DBSERVER_ORACLE:
06479                         break;
06480                 case IDO2DB_DBSERVER_SQLITE:
06481                         break;
06482                 case IDO2DB_DBSERVER_SQLITE3:
06483                         break;
06484                 default:
06485                         break;
06486         }
06487 #endif
06488 
06489 #ifdef USE_PGSQL /* pgsql */
06490 
06491 #endif
06492 
06493 #ifdef USE_ORACLE /* Oracle ocilib specific */
06494 
06495         /* check if we lost connection, and reconnect */
06496         if(ido2db_db_reconnect(idi)==IDO_ERROR)
06497                 return IDO_ERROR;
06498 
06499                         /* use prepared statements and ocilib */
06500                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostescalationdefinition_definition, MT(":X1"), (big_uint *) data[0])) {
06501                                 return IDO_ERROR;
06502                         }
06503                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostescalationdefinition_definition, MT(":X2"), (int *) data[1])) {
06504                                 return IDO_ERROR;
06505                         }
06506                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostescalationdefinition_definition, MT(":X3"), (big_uint *) data[2])) {
06507                                 return IDO_ERROR;
06508                         }
06509                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostescalationdefinition_definition, MT(":X4"), (big_uint *) data[3])) {
06510                                 return IDO_ERROR;
06511                         }
06512                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostescalationdefinition_definition, MT(":X5"), (int *) data[4])) {
06513                                 return IDO_ERROR;
06514                         }
06515                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostescalationdefinition_definition, MT(":X6"), (int *) data[5])) {
06516                                 return IDO_ERROR;
06517                         }
06518                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_hostescalationdefinition_definition, MT(":X7"), (double *) data[6])) {
06519                                 return IDO_ERROR;
06520                         }
06521                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostescalationdefinition_definition, MT(":X8"), (int *) data[7])) {
06522                                 return IDO_ERROR;
06523                         }
06524                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostescalationdefinition_definition, MT(":X9"), (int *) data[8])) {
06525                                 return IDO_ERROR;
06526                         }
06527                         if(!OCI_BindInt(idi->dbinfo.oci_statement_hostescalationdefinition_definition, MT(":X10"), (int *) data[9])) {
06528                                 return IDO_ERROR;
06529                         }
06530 
06531                         /* execute statement */
06532                         if(!OCI_Execute(idi->dbinfo.oci_statement_hostescalationdefinition_definition)) {
06533                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_hostescalationdefinition_definition() execute error\n");
06534                                 return IDO_ERROR;
06535                         }
06536 
06537                         /* commit statement */
06538                         OCI_Commit(idi->dbinfo.oci_connection);
06539 
06540                         /* do not free statement yet! */
06541 #endif
06542         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hostescalationdefinition_definition_add() end\n");
06543 
06544         return result;
06545 }
06546 
06547 
06548 int ido2db_query_insert_or_update_hostescalationdefinition_contactgroups_add(ido2db_idi *idi, void **data) {
06549         int result = IDO_OK;
06550 #ifdef USE_LIBDBI
06551         char * query1 = NULL;
06552         char * query2 = NULL;
06553 #endif
06554         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hostescalationdefinition_contactgroups_add() start\n");
06555 
06556         if (idi == NULL)
06557                 return IDO_ERROR;
06558 
06559         if (idi->dbinfo.connected == IDO_FALSE)
06560                 return IDO_ERROR;
06561 
06562 #ifdef USE_LIBDBI /* everything else will be libdbi */
06563         switch (idi->dbinfo.server_type) {
06564                 case IDO2DB_DBSERVER_MYSQL:
06565                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, hostescalation_id, contactgroup_object_id) VALUES ('%lu', '%lu', '%lu') ON DUPLICATE KEY UPDATE instance_id='%lu'",
06566                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTESCALATIONCONTACTGROUPS],
06567                                         *(unsigned long *) data[0],     /* insert start */
06568                                         *(unsigned long *) data[1],     
06569                                         *(unsigned long *) data[2],     /* insert end */
06570                                         *(unsigned long *) data[0]     /* update start/end */
06571                         );
06572                         /* send query to db */
06573                         result = ido2db_db_query(idi, query1);
06574                         free(query1);
06575                         break;
06576                 case IDO2DB_DBSERVER_PGSQL:
06577                         dummy=asprintf(&query1, "UPDATE %s SET instance_id='%lu' WHERE hostescalation_id='%lu' AND contactgroup_object_id='%lu'",
06578                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTESCALATIONCONTACTGROUPS],
06579                                         *(unsigned long *) data[0],     /* update start/end */
06580                                         *(unsigned long *) data[1],     /* unique constraint start */
06581                                         *(unsigned long *) data[2]     /* unique constraint end */
06582                         );
06583                         /* send query to db */
06584                         result = ido2db_db_query(idi, query1);
06585 
06586                         /* check result if update was ok */
06587                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
06588                                 /* try insert instead */
06589                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, hostescalation_id, contactgroup_object_id) VALUES ('%lu', '%lu', '%lu')",
06590                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTESCALATIONCONTACTGROUPS],
06591                                         *(unsigned long *) data[0],     /* insert start */
06592                                         *(unsigned long *) data[1],     
06593                                         *(unsigned long *) data[2]     /* insert end */
06594                                 );
06595                                 /* send query to db */
06596                                 result = ido2db_db_query(idi, query2);
06597                                 free(query2);
06598                         }
06599                         break;
06600                 case IDO2DB_DBSERVER_DB2:
06601                         break;
06602                 case IDO2DB_DBSERVER_FIREBIRD:
06603                         break;
06604                 case IDO2DB_DBSERVER_FREETDS:
06605                         break;
06606                 case IDO2DB_DBSERVER_INGRES:
06607                         break;
06608                 case IDO2DB_DBSERVER_MSQL:
06609                         break;
06610                 case IDO2DB_DBSERVER_ORACLE:
06611                         break;
06612                 case IDO2DB_DBSERVER_SQLITE:
06613                         break;
06614                 case IDO2DB_DBSERVER_SQLITE3:
06615                         break;
06616                 default:
06617                         break;
06618         }
06619 #endif
06620 
06621 #ifdef USE_PGSQL /* pgsql */
06622 
06623 #endif
06624 
06625 #ifdef USE_ORACLE /* Oracle ocilib specific */
06626 
06627         /* check if we lost connection, and reconnect */
06628         if(ido2db_db_reconnect(idi)==IDO_ERROR)
06629                 return IDO_ERROR;
06630 
06631                         /* use prepared statements and ocilib */
06632                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostescalationdefinition_contactgroups, MT(":X1"), (big_uint *) data[0])) {
06633                                 return IDO_ERROR;
06634                         }
06635                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostescalationdefinition_contactgroups, MT(":X2"), (big_uint *) data[1])) {
06636                                 return IDO_ERROR;
06637                         }
06638                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostescalationdefinition_contactgroups, MT(":X3"), (big_uint *) data[2])) {
06639                                 return IDO_ERROR;
06640                         }
06641 
06642                         /* execute statement */
06643                         if(!OCI_Execute(idi->dbinfo.oci_statement_hostescalationdefinition_contactgroups)) {
06644                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_hostescalationdefinition_contactgroups() execute error\n");
06645                                 return IDO_ERROR;
06646                         }
06647 
06648                         /* commit statement */
06649                         OCI_Commit(idi->dbinfo.oci_connection);
06650 
06651                         /* do not free statement yet! */
06652 #endif
06653         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hostescalationdefinition_contactgroups_add() end\n");
06654 
06655         return result;
06656 }
06657 
06658 
06659 int ido2db_query_insert_or_update_hostescalationdefinition_contacts_add(ido2db_idi *idi, void **data) {
06660         int result = IDO_OK;
06661 #ifdef USE_LIBDBI
06662         char * query1 = NULL;
06663         char * query2 = NULL;
06664 #endif
06665         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hostescalationdefinition_contacts_add() start\n");
06666 
06667         if (idi == NULL)
06668                 return IDO_ERROR;
06669 
06670         if (idi->dbinfo.connected == IDO_FALSE)
06671                 return IDO_ERROR;
06672 
06673 #ifdef USE_LIBDBI /* everything else will be libdbi */
06674         switch (idi->dbinfo.server_type) {
06675                 case IDO2DB_DBSERVER_MYSQL:
06676                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, hostescalation_id, contact_object_id) VALUES (%lu, %lu, %lu) ON DUPLICATE KEY UPDATE instance_id=%lu, hostescalation_id=%lu, contact_object_id=%lu",
06677                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTESCALATIONCONTACTS],
06678                                         *(unsigned long *) data[0],     /* insert start */
06679                                         *(unsigned long *) data[1],     
06680                                         *(unsigned long *) data[2],     /* insert end */
06681                                         *(unsigned long *) data[0],     /* update start */
06682                                         *(unsigned long *) data[1],     
06683                                         *(unsigned long *) data[2]     /* update end */
06684                         );
06685                         /* send query to db */
06686                         result = ido2db_db_query(idi, query1);
06687                         free(query1);
06688                         break;
06689                 case IDO2DB_DBSERVER_PGSQL:
06690                         dummy=asprintf(&query1, "UPDATE %s SET instance_id=%lu, hostescalation_id=%lu, contact_object_id=%lu WHERE instance_id=%lu AND hostescalation_id=%lu AND contact_object_id=%lu",
06691                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTESCALATIONCONTACTS],
06692                                         *(unsigned long *) data[0],     /* update start */
06693                                         *(unsigned long *) data[1],     
06694                                         *(unsigned long *) data[2],     /* update end */
06695                                         *(unsigned long *) data[0],     /* unique constraint start */
06696                                         *(unsigned long *) data[1],     
06697                                         *(unsigned long *) data[2]     /* unique constraint end */
06698                         );
06699                         /* send query to db */
06700                         result = ido2db_db_query(idi, query1);
06701                         free(query1);
06702 
06703                         /* check result if update was ok */
06704                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
06705                                 /* try insert instead */
06706                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, hostescalation_id, contact_object_id) VALUES (%lu, %lu, %lu)",
06707                                         ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTESCALATIONCONTACTS],
06708                                         *(unsigned long *) data[0],     /* insert start */
06709                                         *(unsigned long *) data[1],     
06710                                         *(unsigned long *) data[2]     /* insert end */
06711                                 );
06712                                 /* send query to db */
06713                                 result = ido2db_db_query(idi, query2);
06714                                 free(query2);
06715                         }
06716                         break;
06717                 case IDO2DB_DBSERVER_DB2:
06718                         break;
06719                 case IDO2DB_DBSERVER_FIREBIRD:
06720                         break;
06721                 case IDO2DB_DBSERVER_FREETDS:
06722                         break;
06723                 case IDO2DB_DBSERVER_INGRES:
06724                         break;
06725                 case IDO2DB_DBSERVER_MSQL:
06726                         break;
06727                 case IDO2DB_DBSERVER_ORACLE:
06728                         break;
06729                 case IDO2DB_DBSERVER_SQLITE:
06730                         break;
06731                 case IDO2DB_DBSERVER_SQLITE3:
06732                         break;
06733                 default:
06734                         break;
06735         }
06736 #endif
06737 
06738 #ifdef USE_PGSQL /* pgsql */
06739 
06740 #endif
06741 
06742 #ifdef USE_ORACLE /* Oracle ocilib specific */
06743 
06744         /* check if we lost connection, and reconnect */
06745         if(ido2db_db_reconnect(idi)==IDO_ERROR)
06746                 return IDO_ERROR;
06747 
06748                         /* use prepared statements and ocilib */
06749                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostescalationdefinition_contacts, MT(":X1"), (big_uint *) data[0])) {
06750                                 return IDO_ERROR;
06751                         }
06752                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostescalationdefinition_contacts, MT(":X2"), (big_uint *) data[1])) {
06753                                 return IDO_ERROR;
06754                         }
06755                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_hostescalationdefinition_contacts, MT(":X3"), (big_uint *) data[2])) {
06756                                 return IDO_ERROR;
06757                         }
06758 
06759                         /* execute statement */
06760                         if(!OCI_Execute(idi->dbinfo.oci_statement_hostescalationdefinition_contacts)) {
06761                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_hostescalationdefinition_contacts() execute error\n");
06762                                 return IDO_ERROR;
06763                         }
06764 
06765                         /* commit statement */
06766                         OCI_Commit(idi->dbinfo.oci_connection);
06767 
06768                         /* do not free statement yet! */
06769 #endif
06770         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_hostescalationdefinition_contacts_add() end\n");
06771 
06772         return result;
06773 }
06774 
06775 
06776 /************************************/
06777 /* SERVICEESCALATIONDEFINITION      */
06778 /************************************/
06779 
06780 int ido2db_query_insert_or_update_serviceescalationdefinition_definition_add(ido2db_idi *idi, void **data) {
06781         int result = IDO_OK;
06782 #ifdef USE_LIBDBI
06783         char * query1 = NULL;
06784         char * query2 = NULL;
06785 #endif
06786         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_serviceescalationdefinition_definition_add() start\n");
06787 
06788         if (idi == NULL)
06789                 return IDO_ERROR;
06790 
06791         if (idi->dbinfo.connected == IDO_FALSE)
06792                 return IDO_ERROR;
06793 
06794 #ifdef USE_LIBDBI /* everything else will be libdbi */
06795         switch (idi->dbinfo.server_type) {
06796                 case IDO2DB_DBSERVER_MYSQL:
06797                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, config_type, service_object_id, timeperiod_object_id, first_notification, last_notification, notification_interval, escalate_on_recovery, escalate_on_warning, escalate_on_unknown, escalate_on_critical) VALUES (%lu, %d, %lu, %lu, %d, %d, %lf, %d, %d, %d, %d) ON DUPLICATE KEY UPDATE notification_interval=%lf, escalate_on_recovery=%d, escalate_on_warning=%d, escalate_on_unknown=%d, escalate_on_critical=%d",
06798                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEESCALATIONS],
06799                                         *(unsigned long *) data[0],     /* insert start */
06800                                         *(int *) data[1],
06801                                         *(unsigned long *) data[2],
06802                                         *(unsigned long *) data[3],
06803                                         *(int *) data[4],
06804                                         *(int *) data[5],
06805                                         *(double *) data[6],
06806                                         *(int *) data[7],
06807                                         *(int *) data[8],
06808                                         *(int *) data[9],
06809                                         *(int *) data[10],              /* insert end */
06810                                         *(double *) data[6],            /* update start */
06811                                         *(int *) data[7],
06812                                         *(int *) data[8],
06813                                         *(int *) data[9],
06814                                         *(int *) data[10]               /* update end */
06815                         );
06816                         /* send query to db */
06817                         result = ido2db_db_query(idi, query1);
06818                         free(query1);
06819                         break;
06820                 case IDO2DB_DBSERVER_PGSQL:
06821                         dummy=asprintf(&query1, "UPDATE %s SET notification_interval=%lf, escalate_on_recovery=%d, escalate_on_warning=%d, escalate_on_unknown=%d, escalate_on_critical=%d WHERE instance_id=%lu AND config_type=%d AND service_object_id=%lu AND timeperiod_object_id=%lu AND first_notification=%d AND last_notification=%d",
06822                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEESCALATIONS],
06823                                         *(double *) data[6],            /* update start */
06824                                         *(int *) data[7],
06825                                         *(int *) data[8],
06826                                         *(int *) data[9],
06827                                         *(int *) data[10],              /* update end */
06828                                         *(unsigned long *) data[0],     /* unique constraint start */ 
06829                                         *(int *) data[1],
06830                                         *(unsigned long *) data[2],
06831                                         *(unsigned long *) data[3],
06832                                         *(int *) data[4],
06833                                         *(int *) data[5]                /* unique constraint end */
06834                         );
06835                         /* send query to db */
06836                         result = ido2db_db_query(idi, query1);
06837                         free(query1);
06838 
06839                         /* check result if update was ok */
06840                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
06841                                 /* try insert instead */
06842                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, config_type, service_object_id, timeperiod_object_id, first_notification, last_notification, notification_interval, escalate_on_recovery, escalate_on_warning, escalate_on_unknown, escalate_on_critical) VALUES (%lu, %d, %lu, %lu, %d, %d, %lf, %d, %d, %d, %d)",
06843                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEESCALATIONS],
06844                                         *(unsigned long *) data[0],     /* insert start */
06845                                         *(int *) data[1],
06846                                         *(unsigned long *) data[2],
06847                                         *(unsigned long *) data[3],
06848                                         *(int *) data[4],
06849                                         *(int *) data[5],
06850                                         *(double *) data[6],
06851                                         *(int *) data[7],
06852                                         *(int *) data[8],
06853                                         *(int *) data[9],
06854                                         *(int *) data[10]               /* insert end */
06855                                 );
06856                                 /* send query to db */
06857                                 result = ido2db_db_query(idi, query2);
06858                                 free(query2);
06859                         }
06860                         break;
06861                 case IDO2DB_DBSERVER_DB2:
06862                         break;
06863                 case IDO2DB_DBSERVER_FIREBIRD:
06864                         break;
06865                 case IDO2DB_DBSERVER_FREETDS:
06866                         break;
06867                 case IDO2DB_DBSERVER_INGRES:
06868                         break;
06869                 case IDO2DB_DBSERVER_MSQL:
06870                         break;
06871                 case IDO2DB_DBSERVER_ORACLE:
06872                         break;
06873                 case IDO2DB_DBSERVER_SQLITE:
06874                         break;
06875                 case IDO2DB_DBSERVER_SQLITE3:
06876                         break;
06877                 default:
06878                         break;
06879         }
06880 #endif
06881 
06882 #ifdef USE_PGSQL /* pgsql */
06883 
06884 #endif
06885 
06886 #ifdef USE_ORACLE /* Oracle ocilib specific */
06887 
06888         /* check if we lost connection, and reconnect */
06889         if(ido2db_db_reconnect(idi)==IDO_ERROR)
06890                 return IDO_ERROR;
06891 
06892                         /* use prepared statements and ocilib */
06893                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_serviceescalationdefinition_definition, MT(":X1"), (big_uint *) data[0])) {
06894                                 return IDO_ERROR;
06895                         }
06896                         if(!OCI_BindInt(idi->dbinfo.oci_statement_serviceescalationdefinition_definition, MT(":X2"), (int *) data[1])) {
06897                                 return IDO_ERROR;
06898                         }
06899                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_serviceescalationdefinition_definition, MT(":X3"), (big_uint *) data[2])) {
06900                                 return IDO_ERROR;
06901                         }
06902                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_serviceescalationdefinition_definition, MT(":X4"), (big_uint *) data[3])) {
06903                                 return IDO_ERROR;
06904                         }
06905                         if(!OCI_BindInt(idi->dbinfo.oci_statement_serviceescalationdefinition_definition, MT(":X5"), (int *) data[4])) {
06906                                 return IDO_ERROR;
06907                         }
06908                         if(!OCI_BindInt(idi->dbinfo.oci_statement_serviceescalationdefinition_definition, MT(":X6"), (int *) data[5])) {
06909                                 return IDO_ERROR;
06910                         }
06911                         if(!OCI_BindDouble(idi->dbinfo.oci_statement_serviceescalationdefinition_definition, MT(":X7"), (double *) data[6])) {
06912                                 return IDO_ERROR;
06913                         }
06914                         if(!OCI_BindInt(idi->dbinfo.oci_statement_serviceescalationdefinition_definition, MT(":X8"), (int *) data[7])) {
06915                                 return IDO_ERROR;
06916                         }
06917                         if(!OCI_BindInt(idi->dbinfo.oci_statement_serviceescalationdefinition_definition, MT(":X9"), (int *) data[8])) {
06918                                 return IDO_ERROR;
06919                         }
06920                         if(!OCI_BindInt(idi->dbinfo.oci_statement_serviceescalationdefinition_definition, MT(":X10"), (int *) data[9])) {
06921                                 return IDO_ERROR;
06922                         }
06923                         if(!OCI_BindInt(idi->dbinfo.oci_statement_serviceescalationdefinition_definition, MT(":X11"), (int *) data[10])) {
06924                                 return IDO_ERROR;
06925                         }
06926 
06927                         /* execute statement */
06928                         if(!OCI_Execute(idi->dbinfo.oci_statement_serviceescalationdefinition_definition)) {
06929                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_serviceescalationdefinition_definition() execute error\n");
06930                                 return IDO_ERROR;
06931                         }
06932 
06933                         /* commit statement */
06934                         OCI_Commit(idi->dbinfo.oci_connection);
06935 
06936                         /* do not free statement yet! */
06937 #endif
06938         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_serviceescalationdefinition_definition_add() end\n");
06939 
06940         return result;
06941 }
06942 
06943 
06944 int ido2db_query_insert_or_update_serviceescalationdefinition_contactgroups_add(ido2db_idi *idi, void **data) {
06945         int result = IDO_OK;
06946 #ifdef USE_LIBDBI
06947         char * query1 = NULL;
06948         char * query2 = NULL;
06949 #endif
06950         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_serviceescalationdefinition_contactgroups_add() start\n");
06951 
06952         if (idi == NULL)
06953                 return IDO_ERROR;
06954 
06955         if (idi->dbinfo.connected == IDO_FALSE)
06956                 return IDO_ERROR;
06957 
06958 #ifdef USE_LIBDBI /* everything else will be libdbi */
06959         switch (idi->dbinfo.server_type) {
06960                 case IDO2DB_DBSERVER_MYSQL:
06961                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, serviceescalation_id, contactgroup_object_id) VALUES ('%lu', '%lu', '%lu') ON DUPLICATE KEY UPDATE instance_id='%lu'",
06962                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEESCALATIONCONTACTGROUPS],
06963                                         *(unsigned long *) data[0],     /* insert start */
06964                                         *(unsigned long *) data[1],     
06965                                         *(unsigned long *) data[2],     /* insert start */
06966                                         *(unsigned long *) data[0]     /* update start/end */
06967                         );
06968                         /* send query to db */
06969                         result = ido2db_db_query(idi, query1);
06970                         free(query1);
06971                         break;
06972                 case IDO2DB_DBSERVER_PGSQL:
06973                         dummy=asprintf(&query1, "UPDATE %s SET instance_id='%lu' WHERE serviceescalation_id='%lu' AND contactgroup_object_id='%lu'",
06974                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEESCALATIONCONTACTGROUPS],
06975                                         *(unsigned long *) data[0],     /* update start/end */
06976                                         *(unsigned long *) data[1],     /* unique constraint start */
06977                                         *(unsigned long *) data[2]     /* unique constraint end */
06978                         );
06979                         /* send query to db */
06980                         result = ido2db_db_query(idi, query1);
06981                         free(query1);
06982 
06983                         /* check result if update was ok */
06984                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
06985                                 /* try insert instead */
06986                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, serviceescalation_id, contactgroup_object_id) VALUES ('%lu', '%lu', '%lu')",
06987                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEESCALATIONCONTACTGROUPS],
06988                                         *(unsigned long *) data[0],     /* insert start */
06989                                         *(unsigned long *) data[1],     
06990                                         *(unsigned long *) data[2]    /* insert start */
06991                                 );
06992                                 /* send query to db */
06993                                 result = ido2db_db_query(idi, query2);
06994                                 free(query2);
06995                         }
06996                         break;
06997                 case IDO2DB_DBSERVER_DB2:
06998                         break;
06999                 case IDO2DB_DBSERVER_FIREBIRD:
07000                         break;
07001                 case IDO2DB_DBSERVER_FREETDS:
07002                         break;
07003                 case IDO2DB_DBSERVER_INGRES:
07004                         break;
07005                 case IDO2DB_DBSERVER_MSQL:
07006                         break;
07007                 case IDO2DB_DBSERVER_ORACLE:
07008                         break;
07009                 case IDO2DB_DBSERVER_SQLITE:
07010                         break;
07011                 case IDO2DB_DBSERVER_SQLITE3:
07012                         break;
07013                 default:
07014                         break;
07015         }
07016 #endif
07017 
07018 #ifdef USE_PGSQL /* pgsql */
07019 
07020 #endif
07021 
07022 #ifdef USE_ORACLE /* Oracle ocilib specific */
07023 
07024         /* check if we lost connection, and reconnect */
07025         if(ido2db_db_reconnect(idi)==IDO_ERROR)
07026                 return IDO_ERROR;
07027 
07028                         /* use prepared statements and ocilib */
07029                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_serviceescalationdefinition_contactgroups, MT(":X1"), (big_uint *) data[0])) {
07030                                 return IDO_ERROR;
07031                         }
07032                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_serviceescalationdefinition_contactgroups, MT(":X2"), (big_uint *) data[1])) {
07033                                 return IDO_ERROR;
07034                         }
07035                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_serviceescalationdefinition_contactgroups, MT(":X3"), (big_uint *) data[2])) {
07036                                 return IDO_ERROR;
07037                         }
07038 
07039                         /* execute statement */
07040                         if(!OCI_Execute(idi->dbinfo.oci_statement_serviceescalationdefinition_contactgroups)) {
07041                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_serviceescalationdefinition_contactgroups() execute error\n");
07042                                 return IDO_ERROR;
07043                         }
07044 
07045                         /* commit statement */
07046                         OCI_Commit(idi->dbinfo.oci_connection);
07047 
07048                         /* do not free statement yet! */
07049 #endif
07050         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_serviceescalationdefinition_contactgroups_add() end\n");
07051 
07052         return result;
07053 }
07054 
07055 
07056 int ido2db_query_insert_or_update_serviceescalationdefinition_contacts_add(ido2db_idi *idi, void **data) {
07057         int result = IDO_OK;
07058 #ifdef USE_LIBDBI
07059         char * query1 = NULL;
07060         char * query2 = NULL;
07061 #endif
07062         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_serviceescalationdefinition_contacts_add() start\n");
07063 
07064         if (idi == NULL)
07065                 return IDO_ERROR;
07066 
07067         if (idi->dbinfo.connected == IDO_FALSE)
07068                 return IDO_ERROR;
07069 
07070 #ifdef USE_LIBDBI /* everything else will be libdbi */
07071         switch (idi->dbinfo.server_type) {
07072                 case IDO2DB_DBSERVER_MYSQL:
07073                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, serviceescalation_id, contact_object_id) VALUES (%lu, %lu, %lu) ON DUPLICATE KEY UPDATE instance_id=%lu, serviceescalation_id=%lu, contact_object_id=%lu",
07074                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEESCALATIONCONTACTS],
07075                                         *(unsigned long *) data[0],     /* insert start */
07076                                         *(unsigned long *) data[1],     
07077                                         *(unsigned long *) data[2],     /* insert start */
07078                                         *(unsigned long *) data[0],     /* update start */
07079                                         *(unsigned long *) data[1],     
07080                                         *(unsigned long *) data[2]     /* update start */
07081                         );
07082                         /* send query to db */
07083                         result = ido2db_db_query(idi, query1);
07084                         free(query1);
07085                         break;
07086                 case IDO2DB_DBSERVER_PGSQL:
07087                         dummy=asprintf(&query1, "UPDATE %s SET instance_id=%lu, serviceescalation_id=%lu, contact_object_id=%lu WHERE instance_id=%lu AND serviceescalation_id=%lu AND contact_object_id=%lu",
07088                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEESCALATIONCONTACTS],
07089                                         *(unsigned long *) data[0],     /* update start */
07090                                         *(unsigned long *) data[1],     
07091                                         *(unsigned long *) data[2],     /* update start */
07092                                         *(unsigned long *) data[0],     /* unique constraint start */
07093                                         *(unsigned long *) data[1],     
07094                                         *(unsigned long *) data[2]     /* unique constraint end */
07095                         );
07096                         /* send query to db */
07097                         result = ido2db_db_query(idi, query1);
07098                         free(query1);
07099 
07100                         /* check result if update was ok */
07101                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
07102                                 /* try insert instead */
07103                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, serviceescalation_id, contact_object_id) VALUES (%lu, %lu, %lu)",
07104                                         ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEESCALATIONCONTACTS],
07105                                         *(unsigned long *) data[0],     /* insert start */
07106                                         *(unsigned long *) data[1],     
07107                                         *(unsigned long *) data[2]     /* insert end */
07108                                 );
07109                                 /* send query to db */
07110                                 result = ido2db_db_query(idi, query2);
07111                                 free(query2);
07112                         }
07113                         break;
07114                 case IDO2DB_DBSERVER_DB2:
07115                         break;
07116                 case IDO2DB_DBSERVER_FIREBIRD:
07117                         break;
07118                 case IDO2DB_DBSERVER_FREETDS:
07119                         break;
07120                 case IDO2DB_DBSERVER_INGRES:
07121                         break;
07122                 case IDO2DB_DBSERVER_MSQL:
07123                         break;
07124                 case IDO2DB_DBSERVER_ORACLE:
07125                         break;
07126                 case IDO2DB_DBSERVER_SQLITE:
07127                         break;
07128                 case IDO2DB_DBSERVER_SQLITE3:
07129                         break;
07130                 default:
07131                         break;
07132         }
07133 #endif
07134 
07135 #ifdef USE_PGSQL /* pgsql */
07136 
07137 #endif
07138 
07139 #ifdef USE_ORACLE /* Oracle ocilib specific */
07140 
07141         /* check if we lost connection, and reconnect */
07142         if(ido2db_db_reconnect(idi)==IDO_ERROR)
07143                 return IDO_ERROR;
07144 
07145                         /* use prepared statements and ocilib */
07146                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_serviceescalationdefinition_contacts, MT(":X1"), (big_uint *) data[0])) {
07147                                 return IDO_ERROR;
07148                         }
07149                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_serviceescalationdefinition_contacts, MT(":X2"), (big_uint *) data[1])) {
07150                                 return IDO_ERROR;
07151                         }
07152                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_serviceescalationdefinition_contacts, MT(":X3"), (big_uint *) data[2])) {
07153                                 return IDO_ERROR;
07154                         }
07155 
07156                         /* execute statement */
07157                         if(!OCI_Execute(idi->dbinfo.oci_statement_serviceescalationdefinition_contacts)) {
07158                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_serviceescalationdefinition_contacts() execute error\n");
07159                                 return IDO_ERROR;
07160                         }
07161 
07162                         /* commit statement */
07163                         OCI_Commit(idi->dbinfo.oci_connection);
07164 
07165                         /* do not free statement yet! */
07166 #endif
07167         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_serviceescalationdefinition_contacts_add() end\n");
07168 
07169         return result;
07170 }
07171 
07172 
07173 /************************************/
07174 /*  COMMANDDEFINITION               */
07175 /************************************/
07176 
07177 int ido2db_query_insert_or_update_commanddefinition_definition_add(ido2db_idi *idi, void **data) {
07178         int result = IDO_OK;
07179 #ifdef USE_LIBDBI
07180         char * query1 = NULL;
07181         char * query2 = NULL;
07182 #endif
07183         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_commanddefinition_definition_add() start\n");
07184 
07185         if (idi == NULL)
07186                 return IDO_ERROR;
07187 
07188         if (idi->dbinfo.connected == IDO_FALSE)
07189                 return IDO_ERROR;
07190 
07191 #ifdef USE_LIBDBI /* everything else will be libdbi */
07192         switch (idi->dbinfo.server_type) {
07193                 case IDO2DB_DBSERVER_MYSQL:
07194                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, object_id, config_type, command_line) VALUES (%lu, %lu, %d, '%s') ON DUPLICATE KEY UPDATE command_line='%s'",
07195                                         ido2db_db_tablenames[IDO2DB_DBTABLE_COMMANDS],
07196                                         *(unsigned long *) data[0],     /* insert start */
07197                                         *(unsigned long *) data[1],
07198                                         *(int *) data[2],
07199                                         *(char **) data[3],             /* insert end */
07200                                         *(char **) data[3]              /* update start/end */
07201                         );
07202                         /* send query to db */
07203                         result = ido2db_db_query(idi, query1);
07204                         free(query1);
07205                         break;
07206                 case IDO2DB_DBSERVER_PGSQL:
07207                         dummy=asprintf(&query1, "UPDATE %s SET command_line='%s' WHERE instance_id=%lu AND object_id=%lu AND config_type=%d",
07208                                         ido2db_db_tablenames[IDO2DB_DBTABLE_COMMANDS],
07209                                         *(char **) data[3],             /* update start/end */
07210                                         *(unsigned long *) data[0],     /* unique constraint start */
07211                                         *(unsigned long *) data[1],
07212                                         *(int *) data[2]                /* unique constraint end */
07213                         );
07214                         /* send query to db */
07215                         result = ido2db_db_query(idi, query1);
07216                         free(query1);
07217 
07218                         /* check result if update was ok */
07219                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
07220                                 /* try insert instead */
07221                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, object_id, config_type, command_line) VALUES (%lu, %lu, %d, '%s')",
07222                                         ido2db_db_tablenames[IDO2DB_DBTABLE_COMMANDS],
07223                                         *(unsigned long *) data[0],     /* insert start */
07224                                         *(unsigned long *) data[1],
07225                                         *(int *) data[2],
07226                                         *(char **) data[3]              /* insert end */
07227                                 );
07228                                 /* send query to db */
07229                                 result = ido2db_db_query(idi, query2);
07230                                 free(query2);
07231                         }
07232                         break;
07233                 case IDO2DB_DBSERVER_DB2:
07234                         break;
07235                 case IDO2DB_DBSERVER_FIREBIRD:
07236                         break;
07237                 case IDO2DB_DBSERVER_FREETDS:
07238                         break;
07239                 case IDO2DB_DBSERVER_INGRES:
07240                         break;
07241                 case IDO2DB_DBSERVER_MSQL:
07242                         break;
07243                 case IDO2DB_DBSERVER_ORACLE:
07244                         break;
07245                 case IDO2DB_DBSERVER_SQLITE:
07246                         break;
07247                 case IDO2DB_DBSERVER_SQLITE3:
07248                         break;
07249                 default:
07250                         break;
07251         }
07252 #endif
07253 
07254 #ifdef USE_PGSQL /* pgsql */
07255 
07256 #endif
07257 
07258 #ifdef USE_ORACLE /* Oracle ocilib specific */
07259 
07260         /* check if we lost connection, and reconnect */
07261         if(ido2db_db_reconnect(idi)==IDO_ERROR)
07262                 return IDO_ERROR;
07263 
07264                         /* use prepared statements and ocilib */
07265                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_commanddefinition_definition, MT(":X1"), (big_uint *) data[0])) {
07266                                 return IDO_ERROR;
07267                         }
07268                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_commanddefinition_definition, MT(":X2"), (big_uint *) data[1])) {
07269                                 return IDO_ERROR;
07270                         }
07271                         if(!OCI_BindInt(idi->dbinfo.oci_statement_commanddefinition_definition, MT(":X3"), (int *) data[2])) {
07272                                 return IDO_ERROR;
07273                         }
07274         if(*(char **) data[3]==NULL) {
07275                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_commanddefinition_definition, ":X4")==IDO_ERROR) {
07276                         return IDO_ERROR;
07277                 }
07278         } else {
07279                         if(!OCI_BindString(idi->dbinfo.oci_statement_commanddefinition_definition, MT(":X4"), *(char **) data[3], 0)) {
07280                                 return IDO_ERROR;
07281                         }
07282         }
07283 
07284                         /* execute statement */
07285                         if(!OCI_Execute(idi->dbinfo.oci_statement_commanddefinition_definition)) {
07286                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_() execute error\n");
07287                                 return IDO_ERROR;
07288                         }
07289 
07290                         /* commit statement */
07291                         OCI_Commit(idi->dbinfo.oci_connection);
07292 
07293                         /* do not free statement yet! */
07294 
07295 #endif
07296         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_commanddefinition_definition_add() end\n");
07297 
07298         return result;
07299 }
07300 
07301 
07302 /************************************/
07303 /*  TIMEPERIODDEFINITION            */
07304 /************************************/
07305 
07306 int ido2db_query_insert_or_update_timeperiodefinition_definition_add(ido2db_idi *idi, void **data) {
07307         int result = IDO_OK;
07308 #ifdef USE_LIBDBI
07309         char * query1 = NULL;
07310         char * query2 = NULL;
07311 #endif
07312         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_timeperiodefinition_definition_add() start\n");
07313 
07314         if (idi == NULL)
07315                 return IDO_ERROR;
07316 
07317         if (idi->dbinfo.connected == IDO_FALSE)
07318                 return IDO_ERROR;
07319 
07320 #ifdef USE_LIBDBI /* everything else will be libdbi */
07321         switch (idi->dbinfo.server_type) {
07322                 case IDO2DB_DBSERVER_MYSQL:
07323                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, config_type, timeperiod_object_id, alias) VALUES (%lu, %d, %lu, '%s') ON DUPLICATE KEY UPDATE alias='%s'",
07324                                         ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEPERIODS],
07325                                         *(unsigned long *) data[0],     /* insert start */
07326                                         *(int *) data[1],
07327                                         *(unsigned long *) data[2],
07328                                         *(char **) data[3],             /* insert end */
07329                                         *(char **) data[3]              /* update start/end */
07330                         );
07331                         /* send query to db */
07332                         result = ido2db_db_query(idi, query1);
07333                         free(query1);
07334                         break;
07335                 case IDO2DB_DBSERVER_PGSQL:
07336                         dummy=asprintf(&query1, "UPDATE %s SET alias='%s' WHERE instance_id=%lu AND config_type=%d AND timeperiod_object_id=%lu",
07337                                         ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEPERIODS],
07338                                         *(char **) data[3],             /* update start/end */
07339                                         *(unsigned long *) data[0],     /* unique constraint start */ 
07340                                         *(int *) data[1],
07341                                         *(unsigned long *) data[2]      /* unique constraint end */
07342                         );
07343                         /* send query to db */
07344                         result = ido2db_db_query(idi, query1);
07345                         free(query1);
07346 
07347                         /* check result if update was ok */
07348                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
07349                                 /* try insert instead */
07350                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, config_type, timeperiod_object_id, alias) VALUES (%lu, %d, %lu, '%s')",
07351                                         ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEPERIODS],
07352                                         *(unsigned long *) data[0],     /* insert start */
07353                                         *(int *) data[1],
07354                                         *(unsigned long *) data[2],
07355                                         *(char **) data[3]              /* insert end */
07356                                 );
07357                                 /* send query to db */
07358                                 result = ido2db_db_query(idi, query2);
07359                                 free(query2);
07360                         }
07361                         break;
07362                 case IDO2DB_DBSERVER_DB2:
07363                         break;
07364                 case IDO2DB_DBSERVER_FIREBIRD:
07365                         break;
07366                 case IDO2DB_DBSERVER_FREETDS:
07367                         break;
07368                 case IDO2DB_DBSERVER_INGRES:
07369                         break;
07370                 case IDO2DB_DBSERVER_MSQL:
07371                         break;
07372                 case IDO2DB_DBSERVER_ORACLE:
07373                         break;
07374                 case IDO2DB_DBSERVER_SQLITE:
07375                         break;
07376                 case IDO2DB_DBSERVER_SQLITE3:
07377                         break;
07378                 default:
07379                         break;
07380         }
07381 #endif
07382 
07383 #ifdef USE_PGSQL /* pgsql */
07384 
07385 #endif
07386 
07387 #ifdef USE_ORACLE /* Oracle ocilib specific */
07388 
07389         /* check if we lost connection, and reconnect */
07390         if(ido2db_db_reconnect(idi)==IDO_ERROR)
07391                 return IDO_ERROR;
07392 
07393                         /* use prepared statements and ocilib */
07394                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timeperiodefinition_definition, MT(":X1"), (big_uint *) data[0])) {
07395                                 return IDO_ERROR;
07396                         }
07397                         if(!OCI_BindInt(idi->dbinfo.oci_statement_timeperiodefinition_definition, MT(":X2"), (int *) data[1])) {
07398                                 return IDO_ERROR;
07399                         }
07400                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timeperiodefinition_definition, MT(":X3"), (big_uint *) data[2])) {
07401                                 return IDO_ERROR;
07402                         }
07403         if(*(char **) data[3]==NULL) {
07404                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_timeperiodefinition_definition, ":X3")==IDO_ERROR) {
07405                         return IDO_ERROR;
07406                 }
07407         } else {
07408                         if(!OCI_BindString(idi->dbinfo.oci_statement_timeperiodefinition_definition, MT(":X4"), *(char **) data[3], 0)) {
07409                                 return IDO_ERROR;
07410                         }
07411         }
07412 
07413                         /* execute statement */
07414                         if(!OCI_Execute(idi->dbinfo.oci_statement_timeperiodefinition_definition)) {
07415                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_timeperiodefinition_definition() execute error\n");
07416                                 return IDO_ERROR;
07417                         }
07418 
07419                         /* commit statement */
07420                         OCI_Commit(idi->dbinfo.oci_connection);
07421 
07422                         /* do not free statement yet! */
07423 #endif
07424         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_timeperiodefinition_definition_add() end\n");
07425 
07426         return result;
07427 }
07428 
07429 
07430 int ido2db_query_insert_or_update_timeperiodefinition_timeranges_add(ido2db_idi *idi, void **data) {
07431         int result = IDO_OK;
07432 #ifdef USE_LIBDBI
07433         char * query1 = NULL;
07434         char * query2 = NULL;
07435 #endif
07436         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_timeperiodefinition_timeranges_add() start\n");
07437 
07438         if (idi == NULL)
07439                 return IDO_ERROR;
07440 
07441         if (idi->dbinfo.connected == IDO_FALSE)
07442                 return IDO_ERROR;
07443 
07444 #ifdef USE_LIBDBI /* everything else will be libdbi */
07445         switch (idi->dbinfo.server_type) {
07446                 case IDO2DB_DBSERVER_MYSQL:
07447                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, timeperiod_id, day, start_sec, end_sec) VALUES (%lu, %lu, %d, %lu, %lu) ON DUPLICATE KEY UPDATE instance_id=%lu",
07448                                         ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEPERIODTIMERANGES],
07449                                         *(unsigned long *) data[0],     /* insert start */
07450                                         *(unsigned long *) data[1],
07451                                         *(int *) data[2],
07452                                         *(unsigned long *) data[3],
07453                                         *(unsigned long *) data[4],     /* insert end */
07454                                         *(unsigned long *) data[0]     /* update start/end */
07455                         );
07456                         /* send query to db */
07457                         result = ido2db_db_query(idi, query1);
07458                         free(query1);
07459                         break;
07460                 case IDO2DB_DBSERVER_PGSQL:
07461                         dummy=asprintf(&query1, "UPDATE %s SET instance_id=%lu WHERE timeperiod_id=%lu AND day=%d AND start_sec=%lu AND end_sec=%lu",
07462                                         ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEPERIODTIMERANGES],
07463                                         *(unsigned long *) data[0],     /* update start/end */
07464                                         *(unsigned long *) data[1],     /* unique constraint start */
07465                                         *(int *) data[2],
07466                                         *(unsigned long *) data[3],
07467                                         *(unsigned long *) data[4]      /* unique constraint end */
07468                         );
07469                         /* send query to db */
07470                         result = ido2db_db_query(idi, query1);
07471                         free(query1);
07472 
07473                         /* check result if update was ok */
07474                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
07475                                 /* try insert instead */
07476                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, timeperiod_id, day, start_sec, end_sec) VALUES (%lu, %lu, %d, %lu, %lu)",
07477                                         ido2db_db_tablenames[IDO2DB_DBTABLE_TIMEPERIODTIMERANGES],
07478                                         *(unsigned long *) data[0],     /* insert start */
07479                                         *(unsigned long *) data[1],
07480                                         *(int *) data[2],
07481                                         *(unsigned long *) data[3],
07482                                         *(unsigned long *) data[4]      /* insert end */
07483                                 );
07484                                 /* send query to db */
07485                                 result = ido2db_db_query(idi, query2);
07486                                 free(query2);
07487                         }
07488                         break;
07489                 case IDO2DB_DBSERVER_DB2:
07490                         break;
07491                 case IDO2DB_DBSERVER_FIREBIRD:
07492                         break;
07493                 case IDO2DB_DBSERVER_FREETDS:
07494                         break;
07495                 case IDO2DB_DBSERVER_INGRES:
07496                         break;
07497                 case IDO2DB_DBSERVER_MSQL:
07498                         break;
07499                 case IDO2DB_DBSERVER_ORACLE:
07500                         break;
07501                 case IDO2DB_DBSERVER_SQLITE:
07502                         break;
07503                 case IDO2DB_DBSERVER_SQLITE3:
07504                         break;
07505                 default:
07506                         break;
07507         }
07508 #endif
07509 
07510 #ifdef USE_PGSQL /* pgsql */
07511 
07512 #endif
07513 
07514 #ifdef USE_ORACLE /* Oracle ocilib specific */
07515 
07516         /* check if we lost connection, and reconnect */
07517         if(ido2db_db_reconnect(idi)==IDO_ERROR)
07518                 return IDO_ERROR;
07519 
07520                         /* use prepared statements and ocilib */
07521                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timeperiodefinition_timeranges, MT(":X1"), (big_uint *) data[0])) {
07522                                 return IDO_ERROR;
07523                         }
07524                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timeperiodefinition_timeranges, MT(":X2"), (big_uint *) data[1])) {
07525                                 return IDO_ERROR;
07526                         }
07527                         if(!OCI_BindInt(idi->dbinfo.oci_statement_timeperiodefinition_timeranges, MT(":X3"), (int *) data[2])) {
07528                                 return IDO_ERROR;
07529                         }
07530                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timeperiodefinition_timeranges, MT(":X4"), (big_uint *) data[3])) {
07531                                 return IDO_ERROR;
07532                         }
07533                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_timeperiodefinition_timeranges, MT(":X5"), (big_uint *) data[4])) {
07534                                 return IDO_ERROR;
07535                         }
07536 
07537                         /* execute statement */
07538                         if(!OCI_Execute(idi->dbinfo.oci_statement_timeperiodefinition_timeranges)) {
07539                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_timeperiodefinition_timeranges() execute error\n");
07540                                 return IDO_ERROR;
07541                         }
07542 
07543                         /* commit statement */
07544                         OCI_Commit(idi->dbinfo.oci_connection);
07545 #endif
07546         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_timeperiodefinition_timeranges_add() end\n");
07547 
07548         return result;
07549 }
07550 
07551 
07552 /************************************/
07553 /* CONTACTDEFINITION                */
07554 /************************************/
07555 
07556 int ido2db_query_insert_or_update_contactdefinition_definition_add(ido2db_idi *idi, void **data) {
07557         int result = IDO_OK;
07558 #ifdef USE_LIBDBI
07559         char * query1 = NULL;
07560         char * query2 = NULL;
07561 #endif
07562         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_contactdefinition_definition_add() start\n");
07563 
07564         if (idi == NULL)
07565                 return IDO_ERROR;
07566 
07567         if (idi->dbinfo.connected == IDO_FALSE)
07568                 return IDO_ERROR;
07569 
07570 #ifdef USE_LIBDBI /* everything else will be libdbi */
07571         switch (idi->dbinfo.server_type) {
07572                 case IDO2DB_DBSERVER_MYSQL:
07573                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, config_type, contact_object_id, alias, email_address, pager_address, host_timeperiod_object_id, service_timeperiod_object_id, host_notifications_enabled, service_notifications_enabled, can_submit_commands, notify_service_recovery, notify_service_warning, notify_service_unknown, notify_service_critical, notify_service_flapping, notify_service_downtime, notify_host_recovery, notify_host_down, notify_host_unreachable, notify_host_flapping, notify_host_downtime) VALUES (%lu, %d, %lu, '%s', '%s', '%s', %lu, %lu, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d) ON DUPLICATE KEY UPDATE alias='%s', email_address='%s', pager_address='%s', host_timeperiod_object_id=%lu, service_timeperiod_object_id=%lu, host_notifications_enabled=%d, service_notifications_enabled=%d, can_submit_commands=%d, notify_service_recovery=%d, notify_service_warning=%d, notify_service_unknown=%d, notify_service_critical=%d, notify_service_flapping=%d, notify_service_downtime=%d, notify_host_recovery=%d, notify_host_down=%d, notify_host_unreachable=%d, notify_host_flapping=%d, notify_host_downtime=%d",
07574                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTS],
07575                                         *(unsigned long *) data[0],     /* insert start */
07576                                         *(int *) data[1],
07577                                         *(unsigned long *) data[2],
07578                                         *(char **) data[3],
07579                                         *(char **) data[4],
07580                                         *(char **) data[5],
07581                                         *(unsigned long *) data[6],
07582                                         *(unsigned long *) data[7],
07583                                         *(int *) data[8],
07584                                         *(int *) data[9],
07585                                         *(int *) data[10],
07586                                         *(int *) data[11],
07587                                         *(int *) data[12],
07588                                         *(int *) data[13],
07589                                         *(int *) data[14],
07590                                         *(int *) data[15],
07591                                         *(int *) data[16],
07592                                         *(int *) data[17],
07593                                         *(int *) data[18],
07594                                         *(int *) data[19],
07595                                         *(int *) data[20],
07596                                         *(int *) data[21],              /* insert end */
07597                                         *(char **) data[3],             /* update start */
07598                                         *(char **) data[4],
07599                                         *(char **) data[5],
07600                                         *(unsigned long *) data[6],
07601                                         *(unsigned long *) data[7],
07602                                         *(int *) data[8],
07603                                         *(int *) data[9],
07604                                         *(int *) data[10],
07605                                         *(int *) data[11],
07606                                         *(int *) data[12],
07607                                         *(int *) data[13],
07608                                         *(int *) data[14],
07609                                         *(int *) data[15],
07610                                         *(int *) data[16],
07611                                         *(int *) data[17],
07612                                         *(int *) data[18],
07613                                         *(int *) data[19],
07614                                         *(int *) data[20],
07615                                         *(int *) data[21]              /* update end */
07616                         );
07617                         /* send query to db */
07618                         result = ido2db_db_query(idi, query1);
07619                         free(query1);
07620                         break;
07621                 case IDO2DB_DBSERVER_PGSQL:
07622                         dummy=asprintf(&query1, "UPDATE %s SET alias='%s', email_address='%s', pager_address='%s', host_timeperiod_object_id=%lu, service_timeperiod_object_id=%lu, host_notifications_enabled=%d, service_notifications_enabled=%d, can_submit_commands=%d, notify_service_recovery=%d, notify_service_warning=%d, notify_service_unknown=%d, notify_service_critical=%d, notify_service_flapping=%d, notify_service_downtime=%d, notify_host_recovery=%d, notify_host_down=%d, notify_host_unreachable=%d, notify_host_flapping=%d, notify_host_downtime=%d WHERE instance_id=%lu AND config_type=%d AND contact_object_id=%lu",
07623                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTS],
07624                                         *(char **) data[3],             /* update start */
07625                                         *(char **) data[4],
07626                                         *(char **) data[5],
07627                                         *(unsigned long *) data[6],
07628                                         *(unsigned long *) data[7],
07629                                         *(int *) data[8],
07630                                         *(int *) data[9],
07631                                         *(int *) data[10],
07632                                         *(int *) data[11],
07633                                         *(int *) data[12],
07634                                         *(int *) data[13],
07635                                         *(int *) data[14],
07636                                         *(int *) data[15],
07637                                         *(int *) data[16],
07638                                         *(int *) data[17],
07639                                         *(int *) data[18],
07640                                         *(int *) data[19],
07641                                         *(int *) data[20],
07642                                         *(int *) data[21],              /* update end */
07643                                         *(unsigned long *) data[0],     /* unique constraint start */
07644                                         *(int *) data[1],
07645                                         *(unsigned long *) data[2]      /* unique constraint end */
07646                         );
07647                         /* send query to db */
07648                         result = ido2db_db_query(idi, query1);
07649                         free(query1);
07650 
07651                         /* check result if update was ok */
07652                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
07653                                 /* try insert instead */
07654                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, config_type, contact_object_id, alias, email_address, pager_address, host_timeperiod_object_id, service_timeperiod_object_id, host_notifications_enabled, service_notifications_enabled, can_submit_commands, notify_service_recovery, notify_service_warning, notify_service_unknown, notify_service_critical, notify_service_flapping, notify_service_downtime, notify_host_recovery, notify_host_down, notify_host_unreachable, notify_host_flapping, notify_host_downtime) VALUES (%lu, %d, %lu, '%s', '%s', '%s', %lu, %lu, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)",
07655                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTS],
07656                                         *(unsigned long *) data[0],     /* insert start */
07657                                         *(int *) data[1],
07658                                         *(unsigned long *) data[2],
07659                                         *(char **) data[3],
07660                                         *(char **) data[4],
07661                                         *(char **) data[5],
07662                                         *(unsigned long *) data[6],
07663                                         *(unsigned long *) data[7],
07664                                         *(int *) data[8],
07665                                         *(int *) data[9],
07666                                         *(int *) data[10],
07667                                         *(int *) data[11],
07668                                         *(int *) data[12],
07669                                         *(int *) data[13],
07670                                         *(int *) data[14],
07671                                         *(int *) data[15],
07672                                         *(int *) data[16],
07673                                         *(int *) data[17],
07674                                         *(int *) data[18],
07675                                         *(int *) data[19],
07676                                         *(int *) data[20],
07677                                         *(int *) data[21]              /* insert end */
07678                                 );
07679                                 /* send query to db */
07680                                 result = ido2db_db_query(idi, query2);
07681                                 free(query2);
07682                         }
07683                         break;
07684                 case IDO2DB_DBSERVER_DB2:
07685                         break;
07686                 case IDO2DB_DBSERVER_FIREBIRD:
07687                         break;
07688                 case IDO2DB_DBSERVER_FREETDS:
07689                         break;
07690                 case IDO2DB_DBSERVER_INGRES:
07691                         break;
07692                 case IDO2DB_DBSERVER_MSQL:
07693                         break;
07694                 case IDO2DB_DBSERVER_ORACLE:
07695                         break;
07696                 case IDO2DB_DBSERVER_SQLITE:
07697                         break;
07698                 case IDO2DB_DBSERVER_SQLITE3:
07699                         break;
07700                 default:
07701                         break;
07702         }
07703 #endif
07704 
07705 #ifdef USE_PGSQL /* pgsql */
07706 
07707 #endif
07708 
07709 #ifdef USE_ORACLE /* Oracle ocilib specific */
07710 
07711         /* check if we lost connection, and reconnect */
07712         if(ido2db_db_reconnect(idi)==IDO_ERROR)
07713                 return IDO_ERROR;
07714 
07715                         /* use prepared statements and ocilib */
07716                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X1"), (big_uint *) data[0])) {
07717                                 return IDO_ERROR;
07718                         }
07719                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X2"), (int *) data[1])) {
07720                                 return IDO_ERROR;
07721                         }
07722                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X3"), (big_uint *) data[2])) {
07723                                 return IDO_ERROR;
07724                         }
07725         if(*(char **) data[3]==NULL) {
07726                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_contactdefinition_definition, ":X4")==IDO_ERROR) {
07727                         return IDO_ERROR;
07728                 }
07729         } else {
07730                         if(!OCI_BindString(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X4"), *(char **) data[3], 0)) {
07731                                 return IDO_ERROR;
07732                         }
07733         }
07734         if(*(char **) data[4]==NULL) {
07735                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_contactdefinition_definition, ":X5")==IDO_ERROR) {
07736                         return IDO_ERROR;
07737                 }
07738         } else {
07739                         if(!OCI_BindString(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X5"), *(char **) data[4], 0)) {
07740                                 return IDO_ERROR;
07741                         }
07742         }
07743         if(*(char **) data[5]==NULL) {
07744                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_contactdefinition_definition, ":X6")==IDO_ERROR) {
07745                         return IDO_ERROR;
07746                 }
07747         } else {
07748                         if(!OCI_BindString(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X6"), *(char **) data[5], 0)) {
07749                                 return IDO_ERROR;
07750                         }
07751         }
07752                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X7"), (big_uint *) data[6])) {
07753                                 return IDO_ERROR;
07754                         }
07755                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X8"), (big_uint *) data[7])) {
07756                                 return IDO_ERROR;
07757                         }
07758                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X9"), (int *) data[8])) {
07759                                 return IDO_ERROR;
07760                         }
07761                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X10"), (int *) data[9])) {
07762                                 return IDO_ERROR;
07763                         }
07764                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X11"), (int *) data[10])) {
07765                                 return IDO_ERROR;
07766                         }
07767                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X12"), (int *) data[11])) {
07768                                 return IDO_ERROR;
07769                         }
07770                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X13"), (int *) data[12])) {
07771                                 return IDO_ERROR;
07772                         }
07773                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X14"), (int *) data[13])) {
07774                                 return IDO_ERROR;
07775                         }
07776                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X15"), (int *) data[14])) {
07777                                 return IDO_ERROR;
07778                         }
07779                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X16"), (int *) data[15])) {
07780                                 return IDO_ERROR;
07781                         }
07782                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X17"), (int *) data[16])) {
07783                                 return IDO_ERROR;
07784                         }
07785                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X18"), (int *) data[17])) {
07786                                 return IDO_ERROR;
07787                         }
07788                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X19"), (int *) data[18])) {
07789                                 return IDO_ERROR;
07790                         }
07791                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X20"), (int *) data[19])) {
07792                                 return IDO_ERROR;
07793                         }
07794                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X21"), (int *) data[20])) {
07795                                 return IDO_ERROR;
07796                         }
07797                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contactdefinition_definition, MT(":X22"), (int *) data[21])) {
07798                                 return IDO_ERROR;
07799                         }
07800 
07801                         /* execute statement */
07802                         if(!OCI_Execute(idi->dbinfo.oci_statement_contactdefinition_definition)) {
07803                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_contactdefinition_definition() execute error\n");
07804                                 return IDO_ERROR;
07805                         }
07806 
07807                         /* commit statement */
07808                         OCI_Commit(idi->dbinfo.oci_connection);
07809 
07810                         /* do not free statement yet! */
07811 #endif
07812         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_contactdefinition_definition_add() end\n");
07813 
07814         return result;
07815 }
07816 
07817 
07818 int ido2db_query_insert_or_update_contactdefinition_addresses_add(ido2db_idi *idi, void **data) {
07819         int result = IDO_OK;
07820 #ifdef USE_LIBDBI
07821         char * query1 = NULL;
07822         char * query2 = NULL;
07823 #endif
07824         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_contactdefinition_addresses_add() start\n");
07825 
07826         if (idi == NULL)
07827                 return IDO_ERROR;
07828 
07829         if (idi->dbinfo.connected == IDO_FALSE)
07830                 return IDO_ERROR;
07831 
07832 #ifdef USE_LIBDBI /* everything else will be libdbi */
07833         switch (idi->dbinfo.server_type) {
07834                 case IDO2DB_DBSERVER_MYSQL:
07835                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, contact_id, address_number, address) VALUES (%lu, %lu, %d, '%s') ON DUPLICATE KEY UPDATE instance_id=%lu, address='%s'",
07836                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTADDRESSES],
07837                                         *(unsigned long *) data[0],     /* insert start */
07838                                         *(unsigned long *) data[1],
07839                                         *(int *) data[2],
07840                                         *(char **) data[3],             /* insert end */
07841                                         *(unsigned long *) data[0],     /* update start */
07842                                         *(char **) data[3]              /* update end */
07843                         );
07844                         /* send query to db */
07845                         result = ido2db_db_query(idi, query1);
07846                         free(query1);
07847                         break;
07848                 case IDO2DB_DBSERVER_PGSQL:
07849                         dummy=asprintf(&query1, "UPDATE %s SET instance_id=%lu, address='%s' WHERE contact_id=%lu AND address_number=%d",
07850                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTADDRESSES],
07851                                         *(unsigned long *) data[0],     /* update start */
07852                                         *(char **) data[3],             /* update end */
07853                                         *(unsigned long *) data[1],     /* unique constraint start */
07854                                         *(int *) data[2]                /* unique constraint end */
07855                         );
07856                         /* send query to db */
07857                         result = ido2db_db_query(idi, query1);
07858                         free(query1);
07859 
07860                         /* check result if update was ok */
07861                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
07862                                 /* try insert instead */
07863                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, contact_id, address_number, address) VALUES (%lu, %lu, %d, '%s')",
07864                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTADDRESSES],
07865                                         *(unsigned long *) data[0],     /* insert start */
07866                                         *(unsigned long *) data[1],
07867                                         *(int *) data[2],
07868                                         *(char **) data[3]              /* insert end */
07869                                 );
07870                                 /* send query to db */
07871                                 result = ido2db_db_query(idi, query2);
07872                                 free(query2);
07873                         }
07874                         break;
07875                 case IDO2DB_DBSERVER_DB2:
07876                         break;
07877                 case IDO2DB_DBSERVER_FIREBIRD:
07878                         break;
07879                 case IDO2DB_DBSERVER_FREETDS:
07880                         break;
07881                 case IDO2DB_DBSERVER_INGRES:
07882                         break;
07883                 case IDO2DB_DBSERVER_MSQL:
07884                         break;
07885                 case IDO2DB_DBSERVER_ORACLE:
07886                         break;
07887                 case IDO2DB_DBSERVER_SQLITE:
07888                         break;
07889                 case IDO2DB_DBSERVER_SQLITE3:
07890                         break;
07891                 default:
07892                         break;
07893         }
07894 #endif
07895 
07896 #ifdef USE_PGSQL /* pgsql */
07897 
07898 #endif
07899 
07900 #ifdef USE_ORACLE /* Oracle ocilib specific */
07901 
07902         /* check if we lost connection, and reconnect */
07903         if(ido2db_db_reconnect(idi)==IDO_ERROR)
07904                 return IDO_ERROR;
07905 
07906                         /* use prepared statements and ocilib */
07907                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactdefinition_addresses, MT(":X1"), (big_uint *) data[0])) {
07908                                 return IDO_ERROR;
07909                         }
07910                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactdefinition_addresses, MT(":X2"), (big_uint *) data[1])) {
07911                                 return IDO_ERROR;
07912                         }
07913                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contactdefinition_addresses, MT(":X3"), (int *) data[2])) {
07914                                 return IDO_ERROR;
07915                         }
07916         if(*(char **) data[3]==NULL) {
07917                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_contactdefinition_addresses, ":X4")==IDO_ERROR) {
07918                         return IDO_ERROR;
07919                 }
07920         } else {
07921                         if(!OCI_BindString(idi->dbinfo.oci_statement_contactdefinition_addresses, MT(":X4"), *(char **) data[3], 0)) {
07922                                 return IDO_ERROR;
07923                         }
07924         }
07925 
07926                         /* execute statement */
07927                         if(!OCI_Execute(idi->dbinfo.oci_statement_contactdefinition_addresses)) {
07928                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_contactdefinition_addresses() execute error\n");
07929                                 return IDO_ERROR;
07930                         }
07931 
07932                         /* commit statement */
07933                         OCI_Commit(idi->dbinfo.oci_connection);
07934 
07935                         /* do not free statement yet! */
07936 #endif
07937         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_contactdefinition_addresses_add() end\n");
07938 
07939         return result;
07940 }
07941 
07942 
07943 int ido2db_query_insert_or_update_contactdefinition_notificationcommands_add(ido2db_idi *idi, void **data) {
07944         int result = IDO_OK;
07945 #ifdef USE_LIBDBI
07946         char * query1 = NULL;
07947         char * query2 = NULL;
07948 #endif
07949         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_contactdefinition_notificationcommands_add() start\n");
07950 
07951         if (idi == NULL)
07952                 return IDO_ERROR;
07953 
07954         if (idi->dbinfo.connected == IDO_FALSE)
07955                 return IDO_ERROR;
07956 
07957 #ifdef USE_LIBDBI /* everything else will be libdbi */
07958         switch (idi->dbinfo.server_type) {
07959                 case IDO2DB_DBSERVER_MYSQL:
07960                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, contact_id, notification_type, command_object_id, command_args) VALUES (%lu, %lu, %d, %lu, '%s') ON DUPLICATE KEY UPDATE command_args='%s'",
07961                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTNOTIFICATIONCOMMANDS],
07962                                         *(unsigned long *) data[0],     /* insert start */
07963                                         *(unsigned long *) data[1],
07964                                         *(int *) data[2],
07965                                         *(unsigned long *) data[3],
07966                                         (*(char **) data[4]==NULL)?"":*(char **) data[4],               /* insert end */
07967                                         (*(char **) data[4]==NULL)?"":*(char **) data[4]                /* update start/end */
07968                         );
07969                         /* send query to db */
07970                         result = ido2db_db_query(idi, query1);
07971                         free(query1);
07972                         break;
07973                 case IDO2DB_DBSERVER_PGSQL:
07974                         dummy=asprintf(&query1, "UPDATE %s SET command_args='%s' WHERE instance_id=%lu AND contact_id=%lu AND notification_type=%d AND command_object_id=%lu",
07975                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTNOTIFICATIONCOMMANDS],
07976                                         (*(char **) data[4]==NULL)?"":*(char **) data[4],               /* update start/end */
07977                                         *(unsigned long *) data[0],     /* unique constraint start */
07978                                         *(unsigned long *) data[1],
07979                                         *(int *) data[2],
07980                                         *(unsigned long *) data[3]      /* unique constraint end */
07981                         );
07982                         /* send query to db */
07983                         result = ido2db_db_query(idi, query1);
07984                         free(query1);
07985 
07986                         /* check result if update was ok */
07987                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
07988                                 /* try insert instead */
07989                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, contact_id, notification_type, command_object_id, command_args) VALUES (%lu, %lu, %d, %lu, '%s')",
07990                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTNOTIFICATIONCOMMANDS],
07991                                         *(unsigned long *) data[0],     /* insert start */
07992                                         *(unsigned long *) data[1],     
07993                                         *(int *) data[2],
07994                                         *(unsigned long *) data[3],
07995                                         (*(char **) data[4]==NULL)?"":*(char **) data[4]                /* insert end */
07996                                 );
07997                                 /* send query to db */
07998                                 result = ido2db_db_query(idi, query2);
07999                                 free(query2);
08000                         }
08001                         break;
08002                 case IDO2DB_DBSERVER_DB2:
08003                         break;
08004                 case IDO2DB_DBSERVER_FIREBIRD:
08005                         break;
08006                 case IDO2DB_DBSERVER_FREETDS:
08007                         break;
08008                 case IDO2DB_DBSERVER_INGRES:
08009                         break;
08010                 case IDO2DB_DBSERVER_MSQL:
08011                         break;
08012                 case IDO2DB_DBSERVER_ORACLE:
08013                         break;
08014                 case IDO2DB_DBSERVER_SQLITE:
08015                         break;
08016                 case IDO2DB_DBSERVER_SQLITE3:
08017                         break;
08018                 default:
08019                         break;
08020         }
08021 #endif
08022 
08023 #ifdef USE_PGSQL /* pgsql */
08024 
08025 #endif
08026 
08027 #ifdef USE_ORACLE /* Oracle ocilib specific */
08028 
08029         /* check if we lost connection, and reconnect */
08030         if(ido2db_db_reconnect(idi)==IDO_ERROR)
08031                 return IDO_ERROR;
08032 
08033                         /* bind params to prepared statement */
08034                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contact_notificationcommands, MT(":X1"), (big_uint *) data[0])) {
08035                                 return IDO_ERROR;
08036                         }
08037                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contact_notificationcommands, MT(":X2"), (big_uint *) data[1])) {
08038                                 return IDO_ERROR;
08039                         }
08040                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contact_notificationcommands, MT(":X3"), (int *) data[2])) {
08041                                 return IDO_ERROR;
08042                         }
08043                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contact_notificationcommands, MT(":X4"), (big_uint *) data[3])) {
08044                                 return IDO_ERROR;
08045                         }
08046         if(*(char **) data[4]==NULL) {
08047                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_contact_notificationcommands, ":X5")==IDO_ERROR) {
08048                         return IDO_ERROR;
08049                 }
08050         } else {
08051                         if(!OCI_BindString(idi->dbinfo.oci_statement_contact_notificationcommands, MT(":X5"), *(char **) data[4], 0)) {
08052                                 return IDO_ERROR;
08053                         }
08054         }
08055 
08056                         /* execute statement */
08057                         if(!OCI_Execute(idi->dbinfo.oci_statement_contact_notificationcommands)) {
08058                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_contactdefinition_notificationcommands_add() execute error\n");
08059                                 return IDO_ERROR;
08060                         }
08061 
08062                         /* commit statement */
08063                         OCI_Commit(idi->dbinfo.oci_connection);
08064 
08065                         /* do not free statement yet! */
08066 #endif                       
08067         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_contactdefinitionnotificationcommands_add() end\n");
08068 
08069         return result;
08070 }
08071 
08072 
08073 int ido2db_query_insert_or_update_contactdefinition_servicenotificationcommands_add(ido2db_idi *idi, void **data) {
08074         int result = IDO_OK;
08075 #ifdef USE_LIBDBI
08076         char * query1 = NULL;
08077         char * query2 = NULL;
08078 #endif
08079         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_contactdefinition_servicenotificationcommands_add() start\n");
08080 
08081         if (idi == NULL)
08082                 return IDO_ERROR;
08083 
08084         if (idi->dbinfo.connected == IDO_FALSE)
08085                 return IDO_ERROR;
08086 
08087 #ifdef USE_LIBDBI /* everything else will be libdbi */
08088         switch (idi->dbinfo.server_type) {
08089                 case IDO2DB_DBSERVER_MYSQL:
08090                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, contact_id, notification_type, command_object_id, command_args) VALUES (%lu, %lu, %d, %lu, '%s') ON DUPLICATE KEY UPDATE command_args='%s'",
08091                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTNOTIFICATIONCOMMANDS],
08092                                         *(unsigned long *) data[0],     /* insert start */
08093                                         *(unsigned long *) data[1],
08094                                         *(int *) data[2],
08095                                         *(unsigned long *) data[3],
08096                                         *(char **) data[4],             /* insert end */
08097                                         *(char **) data[4]              /* update start/end */
08098                         );
08099                         /* send query to db */
08100                         result = ido2db_db_query(idi, query1);
08101                         free(query1);
08102                         break;
08103                 case IDO2DB_DBSERVER_PGSQL:
08104                         dummy=asprintf(&query1, "UPDATE %s SET command_args='%s' WHERE instance_id=%lu AND contact_id=%lu AND notification_type=%d AND command_object_id=%lu",
08105                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTNOTIFICATIONCOMMANDS],
08106                                         *(char **) data[4],             /* update start/end */
08107                                         *(unsigned long *) data[0],     /* unique constraint start */
08108                                         *(unsigned long *) data[1],
08109                                         *(int *) data[2],
08110                                         *(unsigned long *) data[3]      /* unique constraint end */
08111                         );
08112                         /* send query to db */
08113                         result = ido2db_db_query(idi, query1);
08114                         free(query1);
08115 
08116                         /* check result if update was ok */
08117                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
08118                                 /* try insert instead */
08119                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, contact_id, notification_type, command_object_id, command_args) VALUES (%lu, %lu, %d, %lu, '%s')",
08120                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTNOTIFICATIONCOMMANDS],
08121                                         *(unsigned long *) data[0],     /* insert start */
08122                                         *(unsigned long *) data[1],
08123                                         *(int *) data[2],
08124                                         *(unsigned long *) data[3],
08125                                         *(char **) data[4]              /* insert end */
08126                                 );
08127                                 /* send query to db */
08128                                 result = ido2db_db_query(idi, query2);
08129                                 free(query2);
08130                         }
08131                         break;
08132                 case IDO2DB_DBSERVER_DB2:
08133                         break;
08134                 case IDO2DB_DBSERVER_FIREBIRD:
08135                         break;
08136                 case IDO2DB_DBSERVER_FREETDS:
08137                         break;
08138                 case IDO2DB_DBSERVER_INGRES:
08139                         break;
08140                 case IDO2DB_DBSERVER_MSQL:
08141                         break;
08142                 case IDO2DB_DBSERVER_ORACLE:
08143                         break;
08144                 case IDO2DB_DBSERVER_SQLITE:
08145                         break;
08146                 case IDO2DB_DBSERVER_SQLITE3:
08147                         break;
08148                 default:
08149                         break;
08150         }
08151 #endif
08152 
08153 #ifdef USE_PGSQL /* pgsql */
08154 
08155 #endif
08156 
08157 #ifdef USE_ORACLE /* Oracle ocilib specific */
08158 
08159         /* check if we lost connection, and reconnect */
08160         if(ido2db_db_reconnect(idi)==IDO_ERROR)
08161                 return IDO_ERROR;
08162 
08163                         /* use prepared statements and ocilib */
08164                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactdefinition_servicenotificationcommands, MT(":X1"), (big_uint *) data[0])) {
08165                                 return IDO_ERROR;
08166                         }
08167                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactdefinition_servicenotificationcommands, MT(":X2"), (big_uint *) data[1])) {
08168                                 return IDO_ERROR;
08169                         }
08170                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contactdefinition_servicenotificationcommands, MT(":X3"), (int *) data[2])) {
08171                                 return IDO_ERROR;
08172                         }
08173                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactdefinition_servicenotificationcommands, MT(":X4"), (big_uint *) data[3])) {
08174                                 return IDO_ERROR;
08175                         }
08176                         if(!OCI_BindString(idi->dbinfo.oci_statement_contactdefinition_servicenotificationcommands, MT(":X5"), *(char **) data[4], 0)) {
08177                                 return IDO_ERROR;
08178                         }
08179 
08180                         /* execute statement */
08181                         if(!OCI_Execute(idi->dbinfo.oci_statement_contactdefinition_servicenotificationcommands)) {
08182                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_contactdefinition_servicenotificationcommands() execute error\n");
08183                                 return IDO_ERROR;
08184                         }
08185 
08186                         /* commit statement */
08187                         OCI_Commit(idi->dbinfo.oci_connection);
08188 
08189                         /* do not free statement yet! */
08190 #endif
08191         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_contactdefinition_servicenotificationcommands_add() end\n");
08192 
08193         return result;
08194 }
08195 
08196 
08197 /************************************/
08198 /* CUSTOMVARIABLES                  */
08199 /************************************/
08200 
08201 int ido2db_query_insert_or_update_save_custom_variables_customvariables_add(ido2db_idi *idi, void **data) {
08202         int result = IDO_OK;
08203 #ifdef USE_LIBDBI
08204         char * query1 = NULL;
08205         char * query2 = NULL;
08206 #endif
08207         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_save_custom_variables_customvariables_add() start\n");
08208 
08209         if (idi == NULL)
08210                 return IDO_ERROR;
08211 
08212         if (idi->dbinfo.connected == IDO_FALSE)
08213                 return IDO_ERROR;
08214 
08215 #ifdef USE_LIBDBI /* everything else will be libdbi */
08216         switch (idi->dbinfo.server_type) {
08217                 case IDO2DB_DBSERVER_MYSQL:
08218                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, object_id, config_type, has_been_modified, varname, varvalue) VALUES (%lu, %lu, %d, %d, '%s', '%s') ON DUPLICATE KEY UPDATE instance_id=%lu, config_type=%d, has_been_modified=%d, varvalue='%s'",
08219                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CUSTOMVARIABLES],
08220                                         *(unsigned long *) data[0],     /* insert start */
08221                                         *(unsigned long *) data[1],
08222                                         *(int *) data[2],
08223                                         *(int *) data[3],
08224                                         (*(char **) data[4]==NULL)?"":*(char **) data[4],
08225                                         (*(char **) data[5]==NULL)?"":*(char **) data[5],               /* insert end */
08226                                         *(unsigned long *) data[0],     /* update start */
08227                                         *(int *) data[2],
08228                                         *(int *) data[3],
08229                                         *(char **) data[5]              /* update end */
08230 
08231                         );
08232                         /* send query to db */
08233                         result = ido2db_db_query(idi, query1);
08234                         free(query1);
08235                         break;
08236                 case IDO2DB_DBSERVER_PGSQL:
08237                         dummy=asprintf(&query1, "UPDATE %s SET instance_id=%lu, config_type=%d, has_been_modified=%d, varvalue='%s' WHERE object_id=%lu AND varname='%s'",
08238                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CUSTOMVARIABLES],
08239                                         *(unsigned long *) data[0],     /* update start */
08240                                         *(int *) data[2],
08241                                         *(int *) data[3],
08242                                         (*(char **) data[5]==NULL)?"":*(char **) data[5],               /* update end */
08243                                         *(unsigned long *) data[1],     /* unique constraint start */
08244                                         (*(char **) data[4]==NULL)?"":*(char **) data[4]                /* unique constraint end */
08245                         );
08246                         /* send query to db */
08247                         result = ido2db_db_query(idi, query1);
08248                         free(query1);
08249 
08250                         /* check result if update was ok */
08251                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
08252                                 /* try insert instead */
08253                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, object_id, config_type, has_been_modified, varname, varvalue) VALUES (%lu, %lu, %d, %d, '%s', '%s')",
08254                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CUSTOMVARIABLES],
08255                                         *(unsigned long *) data[0],     /* insert start */
08256                                         *(unsigned long *) data[1],
08257                                         *(int *) data[2],
08258                                         *(int *) data[3],
08259                                         (*(char **) data[4]==NULL)?"":*(char **) data[4],
08260                                         (*(char **) data[5]==NULL)?"":*(char **) data[5]                /* insert end */
08261                                 );
08262                                 /* send query to db */
08263                                 result = ido2db_db_query(idi, query2);
08264                                 free(query2);
08265                         }
08266                         break;
08267                 case IDO2DB_DBSERVER_DB2:
08268                         break;
08269                 case IDO2DB_DBSERVER_FIREBIRD:
08270                         break;
08271                 case IDO2DB_DBSERVER_FREETDS:
08272                         break;
08273                 case IDO2DB_DBSERVER_INGRES:
08274                         break;
08275                 case IDO2DB_DBSERVER_MSQL:
08276                         break;
08277                 case IDO2DB_DBSERVER_ORACLE:
08278                         break;
08279                 case IDO2DB_DBSERVER_SQLITE:
08280                         break;
08281                 case IDO2DB_DBSERVER_SQLITE3:
08282                         break;
08283                 default:
08284                         break;
08285         }
08286 #endif
08287 
08288 #ifdef USE_PGSQL /* pgsql */
08289 
08290 #endif
08291 
08292 #ifdef USE_ORACLE /* Oracle ocilib specific */
08293 
08294         /* check if we lost connection, and reconnect */
08295         if(ido2db_db_reconnect(idi)==IDO_ERROR)
08296                 return IDO_ERROR;
08297 
08298                         /* use prepared statements and ocilib */
08299                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_save_custom_variables_customvariables, MT(":X1"), (big_uint *) data[0])) {
08300                                 return IDO_ERROR;
08301                         }
08302                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_save_custom_variables_customvariables, MT(":X2"), (big_uint *) data[1])) {
08303                                 return IDO_ERROR;
08304                         }
08305                         if(!OCI_BindInt(idi->dbinfo.oci_statement_save_custom_variables_customvariables, MT(":X3"), (int *) data[2])) {
08306                                 return IDO_ERROR;
08307                         }
08308                         if(!OCI_BindInt(idi->dbinfo.oci_statement_save_custom_variables_customvariables, MT(":X4"), (int *) data[3])) {
08309                                 return IDO_ERROR;
08310                         }
08311         if(*(char **) data[4]==NULL) {
08312                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_save_custom_variables_customvariables, ":X5")==IDO_ERROR) {
08313                         return IDO_ERROR;
08314                 }
08315         } else {
08316                 if(!OCI_BindString(idi->dbinfo.oci_statement_save_custom_variables_customvariables, MT(":X5"), *(char **) data[4], 0)) {
08317                         return IDO_ERROR;
08318                 }
08319         }
08320         if(*(char **) data[5]==NULL) {
08321                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_save_custom_variables_customvariables, ":X6")==IDO_ERROR) {
08322                         return IDO_ERROR;
08323                 }
08324         } else {
08325                 if(!OCI_BindString(idi->dbinfo.oci_statement_save_custom_variables_customvariables, MT(":X6"), *(char **) data[5], 0)) {
08326                         return IDO_ERROR;
08327                 }
08328         }
08329 
08330 
08331                         /* execute statement */
08332                         if(!OCI_Execute(idi->dbinfo.oci_statement_save_custom_variables_customvariables)) {
08333                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_save_custom_variables_customvariables() execute error\n");
08334                                 return IDO_ERROR;
08335                         }
08336 
08337                         /* commit statement */
08338                         OCI_Commit(idi->dbinfo.oci_connection);
08339 
08340                         /* do not free statement yet! */
08341 #endif
08342         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_save_custom_variables_customvariables_add() end\n");
08343 
08344         return result;
08345 }
08346 
08347 
08348 int ido2db_query_insert_or_update_save_custom_variables_customvariablestatus_add(ido2db_idi *idi, void **data) {
08349         int result = IDO_OK;
08350 #ifdef USE_LIBDBI
08351         char * query1 = NULL;
08352         char * query2 = NULL;
08353 #endif
08354 
08355         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_save_custom_variables_customvariablestatus_add() start\n");
08356 
08357         if (idi == NULL)
08358                 return IDO_ERROR;
08359 
08360         if (idi->dbinfo.connected == IDO_FALSE)
08361                 return IDO_ERROR;
08362 
08363 #ifdef USE_LIBDBI /* everything else will be libdbi */
08364         switch (idi->dbinfo.server_type) {
08365                 case IDO2DB_DBSERVER_MYSQL:
08366                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, object_id, status_update_time, has_been_modified, varname, varvalue) VALUES (%lu, %lu, %s, %d, '%s', '%s') ON DUPLICATE KEY UPDATE instance_id=%lu, status_update_time=%s, has_been_modified=%d, varvalue='%s'",
08367                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CUSTOMVARIABLESTATUS],
08368                                         *(unsigned long *) data[0],     /* insert start */
08369                                         *(unsigned long *) data[1],
08370                                         *(char **) data[2],
08371                                         *(int *) data[3],
08372                                         (*(char **) data[4]==NULL)?"":*(char **) data[4],
08373                                         (*(char **) data[5]==NULL)?"":*(char **) data[5],             /* insert end */
08374                                         *(unsigned long *) data[0],     /* update start */
08375                                         *(char **) data[2],
08376                                         *(int *) data[3],
08377                                         *(char **) data[5]              /* update end */
08378                         );
08379                         /* send query to db */
08380                         result = ido2db_db_query(idi, query1);
08381                         free(query1);
08382                         break;
08383                 case IDO2DB_DBSERVER_PGSQL:
08384                         dummy=asprintf(&query1, "UPDATE %s SET instance_id=%lu, status_update_time=%s, has_been_modified=%d, varvalue='%s' WHERE object_id=%lu AND varname='%s'",
08385                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CUSTOMVARIABLESTATUS],
08386                                         *(unsigned long *) data[0],     /* update start */
08387                                         *(char **) data[2],
08388                                         *(int *) data[3],
08389                                         (*(char **) data[5]==NULL)?"":*(char **) data[5],             /* update end */
08390                                         *(unsigned long *) data[1],     /* unique constraint start */
08391                                         (*(char **) data[4]==NULL)?"":*(char **) data[4]      /* unique constraint end */
08392                         );
08393                         /* send query to db */
08394                         result = ido2db_db_query(idi, query1);
08395                         free(query1);
08396 
08397                         /* check result if update was ok */
08398                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
08399                                 /* try insert instead */
08400                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, object_id, status_update_time, has_been_modified, varname, varvalue) VALUES (%lu, %lu, %s, %d, '%s', '%s')",
08401                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CUSTOMVARIABLESTATUS],
08402                                         *(unsigned long *) data[0],     /* insert start */
08403                                         *(unsigned long *) data[1],
08404                                         *(char **) data[2],
08405                                         *(int *) data[3],
08406                                         (*(char **) data[4]==NULL)?"":*(char **) data[4],
08407                                         (*(char **) data[5]==NULL)?"":*(char **) data[5]             /* insert end */
08408                                 );
08409                                 /* send query to db */
08410                                 result = ido2db_db_query(idi, query2);
08411                                 free(query2);
08412                         }
08413                         break;
08414                 case IDO2DB_DBSERVER_DB2:
08415                         break;
08416                 case IDO2DB_DBSERVER_FIREBIRD:
08417                         break;
08418                 case IDO2DB_DBSERVER_FREETDS:
08419                         break;
08420                 case IDO2DB_DBSERVER_INGRES:
08421                         break;
08422                 case IDO2DB_DBSERVER_MSQL:
08423                         break;
08424                 case IDO2DB_DBSERVER_ORACLE:
08425                         break;
08426                 case IDO2DB_DBSERVER_SQLITE:
08427                         break;
08428                 case IDO2DB_DBSERVER_SQLITE3:
08429                         break;
08430                 default:
08431                         break;
08432         }
08433 #endif
08434 
08435 #ifdef USE_PGSQL /* pgsql */
08436 
08437 #endif
08438 
08439 #ifdef USE_ORACLE /* Oracle ocilib specific */
08440 
08441         /* check if we lost connection, and reconnect */
08442         if(ido2db_db_reconnect(idi)==IDO_ERROR)
08443                 return IDO_ERROR;
08444 
08445                         /* use prepared statements and ocilib */
08446                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_save_custom_variables_customvariablestatus, MT(":X1"), (big_uint *) data[0])) {
08447                                 return IDO_ERROR;
08448                         }
08449                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_save_custom_variables_customvariablestatus, MT(":X2"), (big_uint *) data[1])) {
08450                                 return IDO_ERROR;
08451                         }
08452                         /* we need to check if time was provided, and then explicitely bind value to NULL */
08453                         if((*(big_uint *) data[6]) < 0) {
08454                                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_save_custom_variables_customvariablestatus, ":X3")==IDO_ERROR) {
08455                                         return IDO_ERROR;
08456                                 }
08457                         } else { /* fine */
08458                                 if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_save_custom_variables_customvariablestatus, MT(":X3"), (big_uint *) data[6])) { /* unixtimestamp instead of time2sql */
08459                                         return IDO_ERROR;
08460                                 }
08461                         }
08462                         if(!OCI_BindInt(idi->dbinfo.oci_statement_save_custom_variables_customvariablestatus, MT(":X4"), (int *) data[3])) {
08463                                 return IDO_ERROR;
08464                         }
08465 
08466         if(*(char **) data[4]==NULL) {
08467                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_save_custom_variables_customvariablestatus, ":X5")==IDO_ERROR) {
08468                         return IDO_ERROR;
08469                 }
08470         } else {
08471                 if(!OCI_BindString(idi->dbinfo.oci_statement_save_custom_variables_customvariablestatus, MT(":X5"), *(char **) data[4], 0)) {
08472                         return IDO_ERROR;
08473                 }
08474         }
08475         if(*(char **) data[5]==NULL) {
08476                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_save_custom_variables_customvariablestatus, ":X6")==IDO_ERROR) {
08477                         return IDO_ERROR;
08478                 }
08479         } else {
08480                 if(!OCI_BindString(idi->dbinfo.oci_statement_save_custom_variables_customvariablestatus, MT(":X6"), *(char **) data[5], 0)) {
08481                         return IDO_ERROR;
08482                 }
08483         }
08484 
08485 
08486                         /* execute statement */
08487                         if(!OCI_Execute(idi->dbinfo.oci_statement_save_custom_variables_customvariablestatus)) {
08488                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_save_custom_variables_customvariablestatus() execute error\n");
08489                                 return IDO_ERROR;
08490                         }
08491 
08492                         /* commit statement */
08493                         OCI_Commit(idi->dbinfo.oci_connection);
08494 
08495                         /* do not free statement yet! */
08496 #endif
08497         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_save_custom_variables_customvariablestatus_add() end\n");
08498 
08499         return result;
08500 }
08501 
08502 
08503 /************************************/
08504 /* CONTACTGROUPDEFINITION           */
08505 /************************************/
08506 
08507 int ido2db_query_insert_or_update_contactgroupdefinition_definition_add(ido2db_idi *idi, void **data) {
08508         int result = IDO_OK;
08509 #ifdef USE_LIBDBI
08510         char * query1 = NULL;
08511         char * query2 = NULL;
08512 #endif
08513         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_contactgroupdefinition_definition_add() start\n");
08514 
08515         if (idi == NULL)
08516                 return IDO_ERROR;
08517 
08518         if (idi->dbinfo.connected == IDO_FALSE)
08519                 return IDO_ERROR;
08520 
08521 #ifdef USE_LIBDBI /* everything else will be libdbi */
08522         switch (idi->dbinfo.server_type) {
08523                 case IDO2DB_DBSERVER_MYSQL:
08524                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, config_type, contactgroup_object_id, alias) VALUES ('%lu', '%d', '%lu', '%s') ON DUPLICATE KEY UPDATE alias='%s'",
08525                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTGROUPS],
08526                                         *(unsigned long *) data[0],     /* insert start */
08527                                         *(int *) data[1],
08528                                         *(unsigned long *) data[2],
08529                                         *(char **) data[3],             /* insert end */
08530                                         *(char **) data[3]              /* update start/end */
08531                         );
08532                         /* send query to db */
08533                         result = ido2db_db_query(idi, query1);
08534                         free(query1);
08535                         break;
08536                 case IDO2DB_DBSERVER_PGSQL:
08537                         dummy=asprintf(&query1, "UPDATE %s SET alias='%s' WHERE instance_id='%lu' AND config_type='%d' AND contactgroup_object_id='%lu'",
08538                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTGROUPS],
08539                                         *(char **) data[3],             /* update start/end */
08540                                         *(unsigned long *) data[0],     /* unique constraint start */    
08541                                         *(int *) data[1],
08542                                         *(unsigned long *) data[2]      /* unique constraint end */
08543                         );
08544                         /* send query to db */
08545                         result = ido2db_db_query(idi, query1);
08546                         free(query1);
08547 
08548                         /* check result if update was ok */
08549                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
08550                                 /* try insert instead */
08551                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, config_type, contactgroup_object_id, alias) VALUES ('%lu', '%d', '%lu', '%s')",
08552                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTGROUPS],
08553                                         *(unsigned long *) data[0],     /* insert start */
08554                                         *(int *) data[1],
08555                                         *(unsigned long *) data[2],
08556                                         *(char **) data[3]              /* insert end */
08557                                 );
08558                                 /* send query to db */
08559                                 result = ido2db_db_query(idi, query2);
08560                                 free(query2);
08561                         }
08562                         break;
08563                 case IDO2DB_DBSERVER_DB2:
08564                         break;
08565                 case IDO2DB_DBSERVER_FIREBIRD:
08566                         break;
08567                 case IDO2DB_DBSERVER_FREETDS:
08568                         break;
08569                 case IDO2DB_DBSERVER_INGRES:
08570                         break;
08571                 case IDO2DB_DBSERVER_MSQL:
08572                         break;
08573                 case IDO2DB_DBSERVER_ORACLE:
08574                         break;
08575                 case IDO2DB_DBSERVER_SQLITE:
08576                         break;
08577                 case IDO2DB_DBSERVER_SQLITE3:
08578                         break;
08579                 default:
08580                         break;
08581         }
08582 #endif
08583 
08584 #ifdef USE_PGSQL /* pgsql */
08585 
08586 #endif
08587 
08588 #ifdef USE_ORACLE /* Oracle ocilib specific */
08589 
08590         /* check if we lost connection, and reconnect */
08591         if(ido2db_db_reconnect(idi)==IDO_ERROR)
08592                 return IDO_ERROR;
08593 
08594                         /* use prepared statements and ocilib */
08595                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactgroupdefinition_definition, MT(":X1"), (big_uint *) data[0])) {
08596                                 return IDO_ERROR;
08597                         }
08598                         if(!OCI_BindInt(idi->dbinfo.oci_statement_contactgroupdefinition_definition, MT(":X2"), (int *) data[1])) {
08599                                 return IDO_ERROR;
08600                         }
08601                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactgroupdefinition_definition, MT(":X3"), (big_uint *) data[2])) {
08602                                 return IDO_ERROR;
08603                         }
08604         if(*(char **) data[3]==NULL) {
08605                 if(ido2db_oci_prepared_statement_bind_null_param(idi->dbinfo.oci_statement_contactgroupdefinition_definition, ":X4")==IDO_ERROR) {
08606                         return IDO_ERROR;
08607                 }
08608         } else {
08609                         if(!OCI_BindString(idi->dbinfo.oci_statement_contactgroupdefinition_definition, MT(":X4"), *(char **) data[3], 0)) {
08610                                 return IDO_ERROR;
08611                         }
08612         }
08613 
08614                         /* execute statement */
08615                         if(!OCI_Execute(idi->dbinfo.oci_statement_contactgroupdefinition_definition)) {
08616                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_contactgroupdefinition_definition() execute error\n");
08617                                 return IDO_ERROR;
08618                         }
08619 
08620                         /* commit statement */
08621                         OCI_Commit(idi->dbinfo.oci_connection);
08622 
08623                         /* do not free statement yet! */
08624 #endif
08625         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_contactgroupdefinition_definition_add() end\n");
08626 
08627         return result;
08628 }
08629 
08630 
08631 int ido2db_query_insert_or_update_contactgroupdefinition_contactgroupmembers_add(ido2db_idi *idi, void **data) {
08632         int result = IDO_OK;
08633 #ifdef USE_LIBDBI
08634         char * query1 = NULL;
08635         char * query2 = NULL;
08636 #endif
08637         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_contactgroupdefinition_contactgroupmembers_add() start\n");
08638 
08639         if (idi == NULL)
08640                 return IDO_ERROR;
08641 
08642         if (idi->dbinfo.connected == IDO_FALSE)
08643                 return IDO_ERROR;
08644 
08645 #ifdef USE_LIBDBI /* everything else will be libdbi */
08646         switch (idi->dbinfo.server_type) {
08647                 case IDO2DB_DBSERVER_MYSQL:
08648                         dummy=asprintf(&query1, "INSERT INTO %s (instance_id, contactgroup_id, contact_object_id) VALUES ('%lu', '%lu', '%lu') ON DUPLICATE KEY UPDATE instance_id='%lu'",
08649                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTGROUPMEMBERS],
08650                                         *(unsigned long *) data[0],     /* insert start */
08651                                         *(unsigned long *) data[1],     
08652                                         *(unsigned long *) data[2],     /* insert end */
08653                                         *(unsigned long *) data[0]     /* update start/end */
08654                         );
08655                         /* send query to db */
08656                         result = ido2db_db_query(idi, query1);
08657                         free(query1);
08658                         break;
08659                 case IDO2DB_DBSERVER_PGSQL:
08660                         dummy=asprintf(&query1, "UPDATE %s SET instance_id='%lu' WHERE contactgroup_id='%lu' AND contact_object_id='%lu'",
08661                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTGROUPMEMBERS],
08662                                         *(unsigned long *) data[0],     /* update start/end */
08663                                         *(unsigned long *) data[1],     /* unique constraint start */ 
08664                                         *(unsigned long *) data[2]     /* unique constraint end */
08665                         );
08666                         /* send query to db */
08667                         result = ido2db_db_query(idi, query1);
08668                         free(query1);
08669 
08670                         /* check result if update was ok */
08671                         if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
08672                                 /* try insert instead */
08673                                 dummy=asprintf(&query2, "INSERT INTO %s (instance_id, contactgroup_id, contact_object_id) VALUES ('%lu', '%lu', '%lu')",
08674                                         ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTGROUPMEMBERS],
08675                                         *(unsigned long *) data[0],     /* insert start */
08676                                         *(unsigned long *) data[1],     
08677                                         *(unsigned long *) data[2]     /* insert end */
08678                                 );
08679                                 /* send query to db */
08680                                 result = ido2db_db_query(idi, query2);
08681                                 free(query2);
08682                         }
08683                         break;
08684                 case IDO2DB_DBSERVER_DB2:
08685                         break;
08686                 case IDO2DB_DBSERVER_FIREBIRD:
08687                         break;
08688                 case IDO2DB_DBSERVER_FREETDS:
08689                         break;
08690                 case IDO2DB_DBSERVER_INGRES:
08691                         break;
08692                 case IDO2DB_DBSERVER_MSQL:
08693                         break;
08694                 case IDO2DB_DBSERVER_ORACLE:
08695                         break;
08696                 case IDO2DB_DBSERVER_SQLITE:
08697                         break;
08698                 case IDO2DB_DBSERVER_SQLITE3:
08699                         break;
08700                 default:
08701                         break;
08702         }
08703 #endif
08704 
08705 #ifdef USE_PGSQL /* pgsql */
08706 
08707 #endif
08708 
08709 #ifdef USE_ORACLE /* Oracle ocilib specific */
08710 
08711         /* check if we lost connection, and reconnect */
08712         if(ido2db_db_reconnect(idi)==IDO_ERROR)
08713                 return IDO_ERROR;
08714 
08715                         /* use prepared statements and ocilib */
08716                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactgroupdefinition_contactgroupmembers, MT(":X1"), (big_uint *) data[0])) {
08717                                 return IDO_ERROR;
08718                         }
08719                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactgroupdefinition_contactgroupmembers, MT(":X2"), (big_uint *) data[1])) {
08720                                 return IDO_ERROR;
08721                         }
08722                         if(!OCI_BindUnsignedBigInt(idi->dbinfo.oci_statement_contactgroupdefinition_contactgroupmembers, MT(":X3"), (big_uint *) data[2])) {
08723                                 return IDO_ERROR;
08724                         }
08725 
08726                         /* execute statement */
08727                         if(!OCI_Execute(idi->dbinfo.oci_statement_contactgroupdefinition_contactgroupmembers)) {
08728                                 ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_contactgroupdefinition_contactgroupmembers() execute error\n");
08729                                 return IDO_ERROR;
08730                         }
08731 
08732                         /* commit statement */
08733                         OCI_Commit(idi->dbinfo.oci_connection);
08734 
08735                         /* do not free statement yet! */
08736 #endif
08737         ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_query_insert_or_update_contactgroupdefinition_contactgroupmembers_add() end\n");
08738 
08739         return result;
08740 }
08741 
08742 
08743 
08744 
 All Data Structures Files Functions Variables Typedefs Defines