[icinga-checkins] icinga.org: icinga-core/master: modify string escaping for mysql and pgsql

git at icinga.org git at icinga.org
Mon Jan 4 16:42:43 CET 2010


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

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Wed Dec 30 16:10:24 2009 +0100

modify string escaping for mysql and pgsql
* the rdbm only needs ' to be escaped by '' nothing else
* both mysql and pgsql are now the same as oracle, tested fine
* small fix for pgsql table systemcommands (missing column output)
* added upgrade path for pgsql in 1.0.1

---

 module/idoutils/db/pgsql-upgrade-1.0.1.sql |   17 +++++++++++
 module/idoutils/db/pgsql.sql               |    1 +
 module/idoutils/src/db.c                   |   42 ++-------------------------
 3 files changed, 22 insertions(+), 38 deletions(-)

diff --git a/module/idoutils/db/pgsql-upgrade-1.0.1.sql b/module/idoutils/db/pgsql-upgrade-1.0.1.sql
new file mode 100644
index 0000000..8e563c1
--- /dev/null
+++ b/module/idoutils/db/pgsql-upgrade-1.0.1.sql
@@ -0,0 +1,17 @@
+-- -----------------------------------------
+-- pgsql-upgrade-1.0.1.sql
+-- upgrade path for Icinga IDOUtils 1.0.1
+-- fixes output missing in table systemcommands
+-- -----------------------------------------
+-- Copyright (c) 2009 Icinga Development Team (http://www.icinga.org)
+--
+-- Initial Revision: 2009-12-30 Michael Friedrich <michael.friedrich(at)univie.ac.at>
+-- 
+-- Please check http://docs.icinga.org for upgrading information!
+-- -----------------------------------------
+
+-- -----------------------------------------
+-- systemcommands upgrade path
+-- -----------------------------------------
+
+ALTER TABLE icinga_systemcommands ADD output VARCHAR(255) NOT NULL default '';
diff --git a/module/idoutils/db/pgsql.sql b/module/idoutils/db/pgsql.sql
index ccb7d9a..8e7c752 100644
--- a/module/idoutils/db/pgsql.sql
+++ b/module/idoutils/db/pgsql.sql
@@ -1305,6 +1305,7 @@ CREATE TABLE  icinga_systemcommands (
   early_timeout INTEGER NOT NULL default '0',
   execution_time double precision NOT NULL default '0',
   return_code INTEGER NOT NULL default '0',
+  output varchar(255) NOT NULL default '',
   long_output varchar(8192) NOT NULL default '',
   PRIMARY KEY  (systemcommand_id),
   UNIQUE (instance_id,start_time,start_time_usec)
diff --git a/module/idoutils/src/db.c b/module/idoutils/src/db.c
index 7aac04d..3f3e0b8 100644
--- a/module/idoutils/src/db.c
+++ b/module/idoutils/src/db.c
@@ -865,44 +865,8 @@ char *ndo2db_db_escape_string(ndo2db_idi *idi, char *buf) {
 	/* escape characters */
 	for (x = 0, y = 0; x < z; x++) {
 
-        	switch (idi->dbinfo.server_type) {
-	                case NDO2DB_DBSERVER_MYSQL:
-				if (buf[x] == '\'' || buf[x] == '\"' || buf[x] == '*' || buf[x]	== '\\' || 
-					buf[x] == '$' || buf[x] == '?' || buf[x] == '.'	|| 
-					buf[x] == '^' || buf[x] == '+' || buf[x] == '['	|| 
-					buf[x] == ']' || buf[x] == '(' || buf[x] == ')')
-					newbuf[y++] = '\\';
-				break;
-			case NDO2DB_DBSERVER_PGSQL:
-				if (buf[x] == '\'' || buf[x] == '[' || 
-					buf[x] == ']' || buf[x] == '(' || buf[x] == ')')
-					newbuf[y++] = '\\';
-	                        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 */
-				if(buf[x]=='\'' )
-					newbuf[y++]='\'';
-#endif /* Oracle ocilib specific */
-
-        	                break;
-	                case NDO2DB_DBSERVER_SQLITE:
-	                        break;
-	                case NDO2DB_DBSERVER_SQLITE3:
-	                        break;
-	                default:
-	                        break;
-		}
+                if(buf[x]=='\'' )
+	                newbuf[y++]='\'';
 
 		newbuf[y++] = buf[x];
 	}
@@ -1033,6 +997,8 @@ int ndo2db_db_query(ndo2db_idi *idi, char *buf) {
 	ndo2db_log_debug_info(NDO2DB_DEBUGL_SQL, 0, "%s\n", buf);
 
 #ifndef USE_ORACLE /* everything else will be libdbi */
+
+	/* send query */
 	idi->dbinfo.dbi_result = dbi_conn_query(idi->dbinfo.dbi_conn, buf);
 
 	if (idi->dbinfo.dbi_result == NULL){





More information about the icinga-checkins mailing list