[icinga-checkins] icinga.org: icinga-core/test/core: dump host/ servicegroup memebers multiline mbuf as bulk inserts #1110

git at icinga.org git at icinga.org
Tue Jul 26 17:31:08 CEST 2011


Module: icinga-core
Branch: test/core
Commit: 621bb9443e6b4e3f2b4a0e1c8a66a154602b504d
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=621bb9443e6b4e3f2b4a0e1c8a66a154602b504d

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Sat Jul 23 23:45:27 2011 +0200

dump host/servicegroup memebers multiline mbuf as bulk inserts #1110

refs #1110

---

 Changelog                        |    2 +-
 module/idoutils/src/dbhandlers.c |  172 ++++++++++++++++++++++++++++++++++----
 2 files changed, 155 insertions(+), 19 deletions(-)

diff --git a/Changelog b/Changelog
index fe3fc03..49663ab 100644
--- a/Changelog
+++ b/Changelog
@@ -7,7 +7,7 @@ Icinga 1.5.x Change Log
 ENHANCEMENTS
 * idoutils: add update-version-schema for updating the idoutils db schema versions automagically, independant of update-version #1616
 * idoutils: dump multiline mbufs as bluk inserts, part 1 #1110
-	** configfilevariables, host contacts/parents, service contacts, timeranges
+	** configfilevariables, host contacts/parents, service contacts, timeranges, host/servicegroup memebers
 
 * classic ui: Added option to suppress coloring of hosts/services in maintenance (Matthew Brooks) #992
 * classic ui: Added option to show partial hostgroups (Matthew Brooks) #1013
diff --git a/module/idoutils/src/dbhandlers.c b/module/idoutils/src/dbhandlers.c
index 6c602d8..d28fef3 100644
--- a/module/idoutils/src/dbhandlers.c
+++ b/module/idoutils/src/dbhandlers.c
@@ -5843,14 +5843,14 @@ int ido2db_handle_hostgroupdefinition(ido2db_idi *idi) {
 	int result = IDO_OK;
 	char *es[1];
 	int x = 0;
-#ifdef USE_LIBDBI
 	char *buf = NULL;
-#endif
+	char *buf1 = NULL;
 	ido2db_mbuf mbuf;
 #ifdef USE_ORACLE
         char *seq_name = NULL;
 #endif
         void *data[4];
+	int first;
 
 	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostgroupdefinition() start\n");
 
@@ -5949,6 +5949,30 @@ int ido2db_handle_hostgroupdefinition(ido2db_idi *idi) {
 	free(es[0]);
 
 	/* save hostgroup members to db */
+        ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_()  start\n");
+
+#ifdef USE_LIBDBI
+
+        /* build a multiple insert value array */
+        if(asprintf(&buf1, "INSERT INTO %s (instance_id, hostgroup_id, host_object_id) VALUES ",
+                        ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTGROUPMEMBERS]
+                        )==-1)
+                buf1=NULL;
+#endif
+
+#ifdef USE_ORACLE /* Oracle ocilib specific */
+
+        /* build a multiple insert value array */
+        if(asprintf(&buf1, "INSERT INTO %s (id, instance_id, hostgroup_id, host_object_id) SELECT seq_%s.nextval, x1, x2, x3 from (",
+                        ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTGROUPMEMBERS],
+                        ido2db_db_tablenames[IDO2DB_DBTABLE_HOSTGROUPMEMBERS]
+                        )==-1)
+                buf1=NULL;
+
+#endif /* Oracle ocilib specific */
+
+        first=1;
+
 	mbuf = idi->mbuf[IDO2DB_MBUF_HOSTGROUPMEMBER];
 	for (x = 0; x < mbuf.used_lines; x++) {
 
@@ -5959,15 +5983,55 @@ int ido2db_handle_hostgroupdefinition(ido2db_idi *idi) {
 		result = ido2db_get_object_id_with_insert(idi, IDO2DB_OBJECTTYPE_HOST,
 				mbuf.buffer[x], NULL, &member_id);
 
-	        /* save entry to db */
-        	data[0] = (void *) &idi->dbinfo.instance_id;
-	        data[1] = (void *) &group_id;
-	        data[2] = (void *) &member_id;
+                buf=buf1; /* save this pointer for later free'ing */
 
-	        result = ido2db_query_insert_or_update_hostgroupdefinition_hostgroupmembers_add(idi, data);
+#ifdef USE_LIBDBI
+                if(asprintf(&buf1, "%s%s(%lu,%lu,%lu)",
+                                buf1,
+                                (first==1?"":","),
+                                idi->dbinfo.instance_id,
+                                group_id,
+                                member_id
+                                )==-1)
+                        buf1=NULL;
+#endif
+
+#ifdef USE_ORACLE /* Oracle ocilib specific */
+                if(first==1) {
+                        if(asprintf(&buf1, "%s SELECT %lu as x1, %lu as x2, %lu as x3 FROM DUAL ",
+                                        buf1,
+                                        idi->dbinfo.instance_id,
+                                        group_id,
+                                        member_id
+                                        )==-1)
+                                buf1=NULL;
+
+                } else {
+                        if(asprintf(&buf1, "%s UNION ALL SELECT %lu, %lu, %lu FROM DUAL ",
+                                        buf1,
+                                        idi->dbinfo.instance_id,
+                                        group_id,
+                                        member_id
+                                        )==-1)
+                                buf1=NULL;
+                }
+#endif /* Oracle ocilib specific */
+
+                free(buf);
+                first=0;
+        }
+#ifdef USE_ORACLE /* Oracle ocilib specific */
+
+        if(asprintf(&buf1, "%s)", buf1)==-1)
+                buf1=NULL;
+
+#endif /* Oracle ocilib specific */
+
+        if(first==0){
+                result=ido2db_db_query(idi, buf1);
 
 #ifdef USE_LIBDBI /* everything else will be libdbi */
-		dbi_result_free(idi->dbinfo.dbi_result);
+                dbi_result_free(idi->dbinfo.dbi_result);
 #endif
 
 #ifdef USE_PGSQL /* pgsql */
@@ -5976,10 +6040,14 @@ int ido2db_handle_hostgroupdefinition(ido2db_idi *idi) {
 
 #ifdef USE_ORACLE /* Oracle ocilib specific */
 
+        /* statement handle not re-binded */
+        OCI_StatementFree(idi->dbinfo.oci_statement);
 
 #endif /* Oracle ocilib specific */
 
-	}
+        }
+
+        free(buf1);
 
 	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_hostgroupdefinition() end\n");
 
@@ -6478,9 +6546,8 @@ int ido2db_handle_servicegroupdefinition(ido2db_idi *idi) {
 	int result = IDO_OK;
 	char *es[1];
 	int x = 0;
-#ifdef USE_LIBDBI
 	char *buf = NULL;
-#endif
+	char *buf1 = NULL;
 	ido2db_mbuf mbuf;
 	char *hptr = NULL;
 	char *sptr = NULL;
@@ -6488,6 +6555,7 @@ int ido2db_handle_servicegroupdefinition(ido2db_idi *idi) {
         char *seq_name = NULL;
 #endif
         void *data[4];
+	int first;
 
 	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicegroupdefinition() start\n");
 
@@ -6587,6 +6655,30 @@ int ido2db_handle_servicegroupdefinition(ido2db_idi *idi) {
 	free(es[0]);
 
 	/* save members to db */
+        ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_()  start\n");
+
+#ifdef USE_LIBDBI
+
+        /* build a multiple insert value array */
+        if(asprintf(&buf1, "INSERT INTO %s (instance_id, servicegroup_id, service_object_id) VALUES ",
+                        ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEGROUPMEMBERS]
+                        )==-1)
+                buf1=NULL;
+#endif
+
+#ifdef USE_ORACLE /* Oracle ocilib specific */
+
+        /* build a multiple insert value array */
+        if(asprintf(&buf1, "INSERT INTO %s (id, instance_id, servicegroup_id, service_object_id) SELECT seq_%s.nextval, x1, x2, x3 from (",
+                        ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEGROUPMEMBERS],
+                        ido2db_db_tablenames[IDO2DB_DBTABLE_SERVICEGROUPMEMBERS]
+                        )==-1)
+                buf1=NULL;
+
+#endif /* Oracle ocilib specific */
+
+        first=1;
+
 	mbuf = idi->mbuf[IDO2DB_MBUF_SERVICEGROUPMEMBER];
 	for (x = 0; x < mbuf.used_lines; x++) {
 
@@ -6601,15 +6693,55 @@ int ido2db_handle_servicegroupdefinition(ido2db_idi *idi) {
 		result = ido2db_get_object_id_with_insert(idi,
 				IDO2DB_OBJECTTYPE_SERVICE, hptr, sptr, &member_id);
 
-		/* save entry to db */
-	        data[0] = (void *) &idi->dbinfo.instance_id;
-	        data[1] = (void *) &group_id;
-	        data[2] = (void *) &member_id;
+                buf=buf1; /* save this pointer for later free'ing */
 
-		result = ido2db_query_insert_or_update_servicegroupdefinition_members_add(idi, data);
+#ifdef USE_LIBDBI
+                if(asprintf(&buf1, "%s%s(%lu,%lu,%lu)",
+                                buf1,
+                                (first==1?"":","),
+                                idi->dbinfo.instance_id,
+                                group_id,
+                                member_id
+                                )==-1)
+                        buf1=NULL;
+#endif
+
+#ifdef USE_ORACLE /* Oracle ocilib specific */
+                if(first==1) {
+                        if(asprintf(&buf1, "%s SELECT %lu as x1, %lu as x2, %lu as x3 FROM DUAL ",
+                                        buf1,
+                                        idi->dbinfo.instance_id,
+                                        service_id,
+                                        group_id
+                                        )==-1)
+                                buf1=NULL;
+
+                } else {
+                        if(asprintf(&buf1, "%s UNION ALL SELECT %lu, %lu, %lu FROM DUAL ",
+                                        buf1,
+                                        idi->dbinfo.instance_id,
+                                        group_id,
+                                        member_id
+                                        )==-1)
+                                buf1=NULL;
+                }
+#endif /* Oracle ocilib specific */
+
+                free(buf);
+                first=0;
+        }
+#ifdef USE_ORACLE /* Oracle ocilib specific */
+
+        if(asprintf(&buf1, "%s)", buf1)==-1)
+                buf1=NULL;
+
+#endif /* Oracle ocilib specific */
+
+        if(first==0){
+                result=ido2db_db_query(idi, buf1);
 
 #ifdef USE_LIBDBI /* everything else will be libdbi */
-		dbi_result_free(idi->dbinfo.dbi_result);
+                dbi_result_free(idi->dbinfo.dbi_result);
 #endif
 
 #ifdef USE_PGSQL /* pgsql */
@@ -6618,10 +6750,14 @@ int ido2db_handle_servicegroupdefinition(ido2db_idi *idi) {
 
 #ifdef USE_ORACLE /* Oracle ocilib specific */
 
+        /* statement handle not re-binded */
+        OCI_StatementFree(idi->dbinfo.oci_statement);
 
 #endif /* Oracle ocilib specific */
 
-	}
+        }
+
+        free(buf1);
 
 	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_servicegroupdefinition() end\n");
 





More information about the icinga-checkins mailing list