[icinga-checkins] icinga.org: icinga-core/rbartels/cgi-current: dump contactgroupmembers multiline mbuf as bulk inserts #1110

git at icinga.org git at icinga.org
Thu Jul 28 01:37:08 CEST 2011


Module: icinga-core
Branch: rbartels/cgi-current
Commit: 263f6d8ee12bf25d1ec7e27a7e21242800986fd0
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=263f6d8ee12bf25d1ec7e27a7e21242800986fd0

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

dump contactgroupmembers multiline mbuf as bulk inserts #1110

refs #1110

---

 Changelog                        |    2 +-
 module/idoutils/src/dbhandlers.c |   86 ++++++++++++++++++++++++++++++++++----
 2 files changed, 78 insertions(+), 10 deletions(-)

diff --git a/Changelog b/Changelog
index 49663ab..d77410f 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, host/servicegroup memebers
+	** configfilevariables, host contacts/parents, service contacts, timeranges, host/service/contactgroup 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 d28fef3..5027729 100644
--- a/module/idoutils/src/dbhandlers.c
+++ b/module/idoutils/src/dbhandlers.c
@@ -8060,14 +8060,14 @@ int ido2db_handle_contactgroupdefinition(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_contactgroupdefinition() start\n");
 
@@ -8165,6 +8165,30 @@ int ido2db_handle_contactgroupdefinition(ido2db_idi *idi) {
 	free(es[0]);
 
 	/* save contact group 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, contactgroup_id, contact_object_id) VALUES ",
+                        ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTGROUPMEMBERS]
+                        )==-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, contactgroup_id, contact_object_id) SELECT seq_%s.nextval, x1, x2, x3 from (",
+                        ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTGROUPMEMBERS],
+                        ido2db_db_tablenames[IDO2DB_DBTABLE_CONTACTGROUPMEMBERS]
+                        )==-1)
+                buf1=NULL;
+
+#endif /* Oracle ocilib specific */
+
+        first=1;
+
 	mbuf = idi->mbuf[IDO2DB_MBUF_CONTACTGROUPMEMBER];
 	for (x = 0; x < mbuf.used_lines; x++) {
 
@@ -8175,15 +8199,55 @@ int ido2db_handle_contactgroupdefinition(ido2db_idi *idi) {
 		result = ido2db_get_object_id_with_insert(idi,
 				IDO2DB_OBJECTTYPE_CONTACT, 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_contactgroupdefinition_contactgroupmembers_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 */
@@ -8192,10 +8256,14 @@ int ido2db_handle_contactgroupdefinition(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_contactgroupdefinition() end\n");
 





More information about the icinga-checkins mailing list