[icinga-checkins] icinga.org: icinga-core/master: fix BINARY just for MySQL, not Postgres or Oracle

git at icinga.org git at icinga.org
Wed Oct 21 23:23:34 CEST 2009


Module: icinga-core
Branch: master
Commit: 1a94a4620106f2541deb0b47deb8766b94644020
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=1a94a4620106f2541deb0b47deb8766b94644020

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Wed Oct 21 23:23:28 2009 +0200

fix BINARY just for MySQL, not Postgres or Oracle
pnly MySQL string compare is case INsensitive, Postgres and Oracle do that case sensitive by default

---

 module/idoutils/src/dbhandlers.c |   78 ++++++++++++++++++++++++++++++++++++--
 1 files changed, 74 insertions(+), 4 deletions(-)

diff --git a/module/idoutils/src/dbhandlers.c b/module/idoutils/src/dbhandlers.c
index 14de343..3bbcad5 100644
--- a/module/idoutils/src/dbhandlers.c
+++ b/module/idoutils/src/dbhandlers.c
@@ -74,8 +74,43 @@ int ndo2db_get_object_id(ndo2db_idi *idi, int object_type, char *n1, char *n2, u
 			buf1 = NULL;
 	} else {
 		es[0] = ndo2db_db_escape_string(idi, name1);
-		if (asprintf(&buf1, "BINARY name1='%s'", es[0]) == -1)
-			buf1 = NULL;
+                switch (idi->dbinfo.server_type) {
+                        case NDO2DB_DBSERVER_MYSQL:
+                                /* mysql does case INsensitive compare, use BINARY */
+                                if (asprintf(&buf1, "BINARY name1='%s'", es[0]) == -1)
+                                        buf1 = NULL;
+                                break;
+                        case NDO2DB_DBSERVER_PGSQL:
+                                /* Postgres does case sensitive compare  */
+                                if (asprintf(&buf1, "name1='%s'", es[0]) == -1)
+                                        buf1 = NULL;
+                                break;
+                        case NDO2DB_DBSERVER_DB2:
+                                break;
+                        case NDO2DB_DBSERVER_FIREBIRD:
+                                break;
+                        case NDO2DB_DBSERVER_FREETDS:
+                                break;
+                        case NDO2DB_DBSERVER_INGRES:
+                                break;
+                        case NDO2DB_DBSERVER_MSQL:
+                                break;
+                        case NDO2DB_DBSERVER_ORACLE:
+
+#ifdef USE_ORACLE /* Oracle ocilib specific */
+                                /* Oracle does case sensitive compare  */
+                                if (asprintf(&buf1, "name1='%s'", es[0]) == -1)
+                                        buf1 = NULL;
+#endif /* Oracle ocilib specific */
+
+                                break;
+                        case NDO2DB_DBSERVER_SQLITE:
+                                break;
+                        case NDO2DB_DBSERVER_SQLITE3:
+                                break;
+                        default:
+                                break;
+                }
 	}
 
 	if (name2 == NULL) {
@@ -84,8 +119,43 @@ int ndo2db_get_object_id(ndo2db_idi *idi, int object_type, char *n1, char *n2, u
 			buf2 = NULL;
 	} else {
 		es[1] = ndo2db_db_escape_string(idi, name2);
-		if (asprintf(&buf2, "BINARY name2='%s'", es[1]) == -1)
-			buf2 = NULL;
+                switch (idi->dbinfo.server_type) {
+                        case NDO2DB_DBSERVER_MYSQL:
+                                /* mysql does case INsensitive compare, use BINARY */
+		                if (asprintf(&buf2, "BINARY name2='%s'", es[1]) == -1)
+                			buf2 = NULL;
+                                break;
+                        case NDO2DB_DBSERVER_PGSQL:
+                                /* Postgres does case sensitive compare  */
+                                if (asprintf(&buf2, "name2='%s'", es[1]) == -1)
+                                        buf2 = NULL;
+                                break;
+                        case NDO2DB_DBSERVER_DB2:
+                                break;
+                        case NDO2DB_DBSERVER_FIREBIRD:
+                                break;
+                        case NDO2DB_DBSERVER_FREETDS:
+                                break;
+                        case NDO2DB_DBSERVER_INGRES:
+                                break;
+                        case NDO2DB_DBSERVER_MSQL:
+                                break;
+                        case NDO2DB_DBSERVER_ORACLE:
+
+#ifdef USE_ORACLE /* Oracle ocilib specific */
+				/* Oracle does case sensitive compare  */
+		                if (asprintf(&buf2, "name2='%s'", es[1]) == -1)
+		                        buf2 = NULL;
+#endif /* Oracle ocilib specific */
+
+                                break;
+                        case NDO2DB_DBSERVER_SQLITE:
+                                break;
+                        case NDO2DB_DBSERVER_SQLITE3:
+                                break;
+                        default:
+                                break;
+                }
 	}
 
 	if (asprintf(&buf, "SELECT * FROM %s WHERE instance_id='%lu' AND objecttype_id='%d' AND %s AND %s", ndo2db_db_tablenames[NDO2DB_DBTABLE_OBJECTS], idi->dbinfo.instance_id, object_type, buf1, buf2) == -1)





More information about the icinga-checkins mailing list