[icinga-checkins] icinga.org: icinga-core/mfriedrich/ocilib: fix several query constraint issues

git at icinga.org git at icinga.org
Mon Oct 19 03:43:39 CEST 2009


Module: icinga-core
Branch: mfriedrich/ocilib
Commit: 52208119530d80290dfa4273d6aaad371da4566b
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=52208119530d80290dfa4273d6aaad371da4566b

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Mon Oct 19 03:43:05 2009 +0200

fix several query constraint issues

---

 module/idoutils/src/dbhandlers.c |   22 +++++++++++++++++++---
 module/idoutils/src/dbqueries.c  |   18 +++++++++---------
 2 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/module/idoutils/src/dbhandlers.c b/module/idoutils/src/dbhandlers.c
index fe9c85d..844fe8f 100644
--- a/module/idoutils/src/dbhandlers.c
+++ b/module/idoutils/src/dbhandlers.c
@@ -3522,8 +3522,8 @@ int ndo2db_handle_configfilevariables(ndo2db_idi *idi, int configfile_type) {
 		es[1] = ndo2db_db_escape_string(idi, varname);
 		es[2] = ndo2db_db_escape_string(idi, varvalue);
 
-		if (asprintf(&buf,
-				"(instance_id, configfile_id, varname, varvalue) VALUES ('%lu', '%lu', '%s', '%s')",
+#ifndef USE_ORACLE /* everything else will be libdbi */
+		if (asprintf(&buf,"(instance_id, configfile_id, varname, varvalue) VALUES ('%lu', '%lu', '%s', '%s')",
 				idi->dbinfo.instance_id, configfile_id, es[1], es[2]) == -1)
 			buf = NULL;
 
@@ -3531,6 +3531,22 @@ int ndo2db_handle_configfilevariables(ndo2db_idi *idi, int configfile_type) {
 				ndo2db_db_tablenames[NDO2DB_DBTABLE_CONFIGFILEVARIABLES], buf)
 				== -1)
 			buf1 = NULL;
+
+#else /* Oracle ocilib specific */
+		if (asprintf(&buf1, "MERGE INTO %s USING DUAL ON (instance_id=%lu AND configfile_id=%lu AND varname='%s') WHEN MATCHED THEN UPDATE SET varvalue='%s' WHEN NOT MATCHED THEN INSERT (instance_id, configfile_id, varname, varvalue) VALUES ('%lu', '%lu', '%s', '%s')",
+				ndo2db_db_tablenames[NDO2DB_DBTABLE_CONFIGFILEVARIABLES],
+				idi->dbinfo.instance_id,	/* unique constraint start */
+				configfile_id,
+				es[1],				/* unique constraint end */
+				es[2],				/* update start/end */
+				idi->dbinfo.instance_id,	/* insert start */
+				configfile_id,
+				es[1],
+				es[2]				/* insert end */
+		) == -1) 
+			buf1 = NULL;				
+
+#endif /* Oracle ocilib specific */
 		result = ndo2db_db_query(idi, buf1);
 
 #ifndef USE_ORACLE /* everything else will be libdbi */
@@ -3612,7 +3628,7 @@ int ndo2db_handle_runtimevariables(ndo2db_idi *idi) {
 		dbi_result_free(idi->dbinfo.dbi_result);
 #else /* Oracle ocilib specific */
 
-	OCI_StatementFree(idi->dbinfo.oci_statement);
+		OCI_StatementFree(idi->dbinfo.oci_statement);
 
 #endif /* Oracle ocilib specific */
 
diff --git a/module/idoutils/src/dbqueries.c b/module/idoutils/src/dbqueries.c
index b80dd50..77cbac2 100644
--- a/module/idoutils/src/dbqueries.c
+++ b/module/idoutils/src/dbqueries.c
@@ -6660,10 +6660,10 @@ int ido2db_query_insert_or_update_contactgroupdefinition_definition_add(ndo2db_i
 
         switch (idi->dbinfo.server_type) {
                 case NDO2DB_DBSERVER_MYSQL:
-                        asprintf(&query1, "INSERT INTO %s (instance_id, config_type, contactgroup_object_id, alias) VALUES ('%lu', '%lu', '%lu', '%s') ON DUPLICATE KEY UPDATE alias='%s'",
+                        asprintf(&query1, "INSERT INTO %s (instance_id, config_type, contactgroup_object_id, alias) VALUES ('%lu', '%d', '%lu', '%s') ON DUPLICATE KEY UPDATE alias='%s'",
                                         ndo2db_db_tablenames[NDO2DB_DBTABLE_CONTACTGROUPS],
                                         *(unsigned long *) data[0],     /* insert start */
-                                        *(unsigned long *) data[1],
+                                        *(int *) data[1],
                                         *(unsigned long *) data[2],
                                         *(char **) data[3],		/* insert end */
                                         *(char **) data[3]		/* update start/end */
@@ -6673,11 +6673,11 @@ int ido2db_query_insert_or_update_contactgroupdefinition_definition_add(ndo2db_i
 			free(query1);
                         break;
                 case NDO2DB_DBSERVER_PGSQL:
-                        asprintf(&query1, "UPDATE %s SET alias='%s' WHERE instance_id='%lu' AND config_type='%lu' AND contactgroup_object_id='%lu'",
+                        asprintf(&query1, "UPDATE %s SET alias='%s' WHERE instance_id='%lu' AND config_type='%d' AND contactgroup_object_id='%lu'",
                                         ndo2db_db_tablenames[NDO2DB_DBTABLE_CONTACTGROUPS],
                                         *(char **) data[3],		/* update start/end */
                                         *(unsigned long *) data[0], 	/* unique constraint start */    
-                                        *(unsigned long *) data[1],
+                                        *(int *) data[1],
                                         *(unsigned long *) data[2]	/* unique constraint end */
                         );
                         /* send query to db */
@@ -6687,10 +6687,10 @@ int ido2db_query_insert_or_update_contactgroupdefinition_definition_add(ndo2db_i
                         /* check result if update was ok */
 			if(dbi_result_get_numrows_affected(idi->dbinfo.dbi_result) == 0) {
                                 /* try insert instead */
-                                asprintf(&query2, "INSERT INTO %s (instance_id, config_type, contactgroup_object_id, alias) VALUES ('%lu', '%lu', '%lu', '%s')",
+                                asprintf(&query2, "INSERT INTO %s (instance_id, config_type, contactgroup_object_id, alias) VALUES ('%lu', '%d', '%lu', '%s')",
                                         ndo2db_db_tablenames[NDO2DB_DBTABLE_CONTACTGROUPS],
                                         *(unsigned long *) data[0],     /* insert start */
-                                        *(unsigned long *) data[1],
+                                        *(int *) data[1],
                                         *(unsigned long *) data[2],
                                         *(char **) data[3]		/* insert end */
                                 );
@@ -6712,14 +6712,14 @@ int ido2db_query_insert_or_update_contactgroupdefinition_definition_add(ndo2db_i
                 case NDO2DB_DBSERVER_ORACLE:
 #ifdef USE_ORACLE
                         /* use prepared statements and ocilib */
-                        asprintf(&query1, "MERGE INTO %s USING DUAL ON (instance_id='%lu' AND config_type='%lu' AND contactgroup_object_id='%lu') WHEN MATCHED THEN UPDATE SET alias='%s' WHEN NOT MATCHED THEN INSERT (instance_id, config_type, contactgroup_object_id, alias) VALUES ('%lu', '%lu', '%lu', '%s')",
+                        asprintf(&query1, "MERGE INTO %s USING DUAL ON (instance_id='%lu' AND config_type='%d' AND contactgroup_object_id='%lu') WHEN MATCHED THEN UPDATE SET alias='%s' WHEN NOT MATCHED THEN INSERT (instance_id, config_type, contactgroup_object_id, alias) VALUES ('%lu', '%d', '%lu', '%s')",
                                         ndo2db_db_tablenames[NDO2DB_DBTABLE_CONTACTGROUPS],
                                         *(unsigned long *) data[0], 	/* unique constraint start */    
-                                        *(unsigned long *) data[1],
+                                        *(int *) data[1],
                                         *(unsigned long *) data[2],	/* unique constraint end */
                                         *(char **) data[3],		/* update start/end */
                                         *(unsigned long *) data[0],     /* insert start */
-                                        *(unsigned long *) data[1],
+                                        *(int *) data[1],
                                         *(unsigned long *) data[2],
                                         *(char **) data[3]		/* insert end */
                         );





More information about the icinga-checkins mailing list