[icinga-checkins] icinga.org: icinga-core/test/ido: dump runtimevariables multiline mbuf as bulk inserts #1110

git at icinga.org git at icinga.org
Sun Jul 24 00:34:35 CEST 2011


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

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Sun Jul 24 00:01:21 2011 +0200

dump runtimevariables multiline mbuf as bulk inserts #1110

refs #1110

---

 Changelog                        |    2 +-
 module/idoutils/src/dbhandlers.c |   91 +++++++++++++++++++++++++++++++++----
 2 files changed, 82 insertions(+), 11 deletions(-)

diff --git a/Changelog b/Changelog
index d77410f..e531491 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/service/contactgroup memebers
+	** configfile/runtime variables, 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 5027729..45c19e9 100644
--- a/module/idoutils/src/dbhandlers.c
+++ b/module/idoutils/src/dbhandlers.c
@@ -5139,10 +5139,12 @@ int ido2db_handle_runtimevariables(ido2db_idi *idi) {
 	int result = IDO_OK;
 	char *es[2];
 	int x = 0;
+	char *buf = NULL;
+	char *buf1 = NULL;
 	char *varname = NULL;
 	char *varvalue = NULL;
 	ido2db_mbuf mbuf;
-	void *data[3];
+	int first;
 
 	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_runtimevariables() start\n");
 
@@ -5158,6 +5160,30 @@ int ido2db_handle_runtimevariables(ido2db_idi *idi) {
 		return IDO_OK;
 
 	/* save config file variables 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, varname, varvalue) VALUES ",
+                        ido2db_db_tablenames[IDO2DB_DBTABLE_RUNTIMEVARIABLES]
+                        )==-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, varname, varvalue) SELECT seq_%s.nextval, x1, x2, x3 from (",
+                        ido2db_db_tablenames[IDO2DB_DBTABLE_RUNTIMEVARIABLES],
+                        ido2db_db_tablenames[IDO2DB_DBTABLE_RUNTIMEVARIABLES]
+                        )==-1)
+                buf1=NULL;
+
+#endif /* Oracle ocilib specific */
+
+        first=1;
+
 	mbuf = idi->mbuf[IDO2DB_MBUF_RUNTIMEVARIABLE];
 	for (x = 0; x < mbuf.used_lines; x++) {
 
@@ -5171,15 +5197,58 @@ int ido2db_handle_runtimevariables(ido2db_idi *idi) {
 		es[0] = ido2db_db_escape_string(idi, varname);
 		es[1] = ido2db_db_escape_string(idi, varvalue);
 
-		/* save entry to db */
-	        data[0] = (void *) &idi->dbinfo.instance_id;
-	        data[1] = (void *) &es[0];
-	        data[2] = (void *) &es[1];
+                buf=buf1; /* save this pointer for later free'ing */
 
-	        result = ido2db_query_insert_or_update_runtimevariables_add(idi, data);
+#ifdef USE_LIBDBI
+                if(asprintf(&buf1, "%s%s(%lu,'%s','%s')",
+                                buf1,
+                                (first==1?"":","),
+                                idi->dbinfo.instance_id,
+				es[0],
+				es[1]
+                                )==-1)
+                        buf1=NULL;
+#endif
+
+#ifdef USE_ORACLE /* Oracle ocilib specific */
+                if(first==1) {
+                        if(asprintf(&buf1, "%s SELECT %lu as x1, '%s' as x2, '%s' as x3 FROM DUAL ",
+                                        buf1,
+                                        idi->dbinfo.instance_id,
+					es[0],
+					es[1]
+                                        )==-1)
+                                buf1=NULL;
+
+                } else {
+                        if(asprintf(&buf1, "%s UNION ALL SELECT %lu, '%s', '%s' FROM DUAL ",
+                                        buf1,
+                                        idi->dbinfo.instance_id,
+					es[0],
+					es[1]
+                                        )==-1)
+                                buf1=NULL;
+                }
+#endif /* Oracle ocilib specific */
+
+		free(es[0]);
+		free(es[1]);
+
+                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 */
@@ -5188,12 +5257,14 @@ int ido2db_handle_runtimevariables(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(es[0]);
-		free(es[1]);
-	}
+        }
+
+        free(buf1);
 
 	ido2db_log_debug_info(IDO2DB_DEBUGL_PROCESSINFO, 2, "ido2db_handle_runtimevariables() end\n");
 





More information about the icinga-checkins mailing list