[dovecot-cvs] dovecot/src/lib-sql driver-mysql.c, 1.16.2.1, 1.16.2.2 driver-pgsql.c, 1.10, 1.10.2.1 driver-sqlite.c, 1.5, 1.5.2.1 sql-api-private.h, 1.6, 1.6.2.1 sql-api.c, 1.8, 1.8.2.1 sql-api.h, 1.8, 1.8.2.1

cras at dovecot.org cras at dovecot.org
Wed May 31 14:02:47 EEST 2006


Update of /var/lib/cvs/dovecot/src/lib-sql
In directory talvi:/tmp/cvs-serv23399/lib-sql

Modified Files:
      Tag: branch_1_0
	driver-mysql.c driver-pgsql.c driver-sqlite.c 
	sql-api-private.h sql-api.c sql-api.h 
Log Message:
Added sql_escape_string()



Index: driver-mysql.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-sql/driver-mysql.c,v
retrieving revision 1.16.2.1
retrieving revision 1.16.2.2
diff -u -d -r1.16.2.1 -r1.16.2.2
--- driver-mysql.c	30 May 2006 15:10:32 -0000	1.16.2.1
+++ driver-mysql.c	31 May 2006 11:02:45 -0000	1.16.2.2
@@ -337,6 +337,23 @@
 	return 0;
 }
 
+static char *
+driver_mysql_escape_string(struct sql_db *_db, const char *string)
+{
+	struct mysql_db *db = (struct mysql_db *)_db;
+	const struct mysql_connection *conn;
+	size_t len = strlen(string);
+	char *to;
+
+	/* All the connections should be identical, so just use the first one */
+	conn = array_idx(&db->connections, 0);
+
+	to = t_buffer_get(len * 2 + 1);
+	len = mysql_real_escape_string(conn->mysql, to, string, len);
+	t_buffer_alloc(len + 1);
+	return to;
+}
+
 static void driver_mysql_exec(struct sql_db *_db, const char *query)
 {
 	struct mysql_db *db = (struct mysql_db *)_db;
@@ -574,6 +591,7 @@
 	_driver_mysql_deinit,
 	driver_mysql_get_flags,
         driver_mysql_connect_all,
+        driver_mysql_escape_string,
 	driver_mysql_exec,
 	driver_mysql_query,
 	driver_mysql_query_s,

Index: driver-pgsql.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-sql/driver-pgsql.c,v
retrieving revision 1.10
retrieving revision 1.10.2.1
diff -u -d -r1.10 -r1.10.2.1
--- driver-pgsql.c	31 Jan 2006 05:06:42 -0000	1.10
+++ driver-pgsql.c	31 May 2006 11:02:45 -0000	1.10.2.1
@@ -441,6 +441,22 @@
 	i_error("pgsql: sql_exec() failed: %s", last_error(db));
 }
 
+static char *driver_pgsql_escape_string(struct sql_db *_db, const char *string)
+{
+	struct pgsql_db *db = (struct pgsql_db *)_db;
+	size_t len = strlen(string);
+	char *to;
+
+	to = t_buffer_get(len * 2 + 1);
+#ifdef HAVE_PQESCAPE_STRING_CONN
+	len = PQescapeStringConn(db->pg, to, string, len, NULL);
+#else
+	len = PQescapeString(to, string, len);
+#endif
+	t_buffer_alloc(len + 1);
+	return to;
+}
+
 static void driver_pgsql_exec(struct sql_db *db, const char *query)
 {
 	struct pgsql_result *result;
@@ -758,6 +774,7 @@
 	_driver_pgsql_deinit,
         driver_pgsql_get_flags,
 	driver_pgsql_connect,
+	driver_pgsql_escape_string,
 	driver_pgsql_exec,
 	driver_pgsql_query,
 	driver_pgsql_query_s,

Index: driver-sqlite.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-sql/driver-sqlite.c,v
retrieving revision 1.5
retrieving revision 1.5.2.1
diff -u -d -r1.5 -r1.5.2.1
--- driver-sqlite.c	27 Jan 2006 15:44:40 -0000	1.5
+++ driver-sqlite.c	31 May 2006 11:02:45 -0000	1.5.2.1
@@ -2,6 +2,7 @@
 
 #include "lib.h"
 #include "str.h"
+#include "strescape.h"
 #include "sql-api-private.h"
 
 #ifdef BUILD_SQLITE
@@ -88,6 +89,12 @@
 	return SQL_DB_FLAG_BLOCKING;
 }
 
+static char *driver_sqlite_escape_string(struct sql_db *_db __attr_unused__,
+					 const char *string)
+{
+	return t_strdup_noconst(str_escape(string));
+}
+
 static void driver_sqlite_exec(struct sql_db *_db, const char *query)
 {
 	struct sqlite_db *db = (struct sqlite_db *)_db;
@@ -338,6 +345,7 @@
 	_driver_sqlite_deinit,
 	driver_sqlite_get_flags,
 	driver_sqlite_connect,
+	driver_sqlite_escape_string,
 	driver_sqlite_exec,
 	driver_sqlite_query,
 	driver_sqlite_query_s,

Index: sql-api-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-sql/sql-api-private.h,v
retrieving revision 1.6
retrieving revision 1.6.2.1
diff -u -d -r1.6 -r1.6.2.1
--- sql-api-private.h	26 Jan 2006 22:01:08 -0000	1.6
+++ sql-api-private.h	31 May 2006 11:02:45 -0000	1.6.2.1
@@ -12,6 +12,7 @@
 	enum sql_db_flags (*get_flags)(struct sql_db *db);
 
 	int (*connect)(struct sql_db *db);
+	char *(*escape_string)(struct sql_db *db, const char *string);
 	void (*exec)(struct sql_db *db, const char *query);
 	void (*query)(struct sql_db *db, const char *query,
 		      sql_query_callback_t *callback, void *context);

Index: sql-api.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-sql/sql-api.c,v
retrieving revision 1.8
retrieving revision 1.8.2.1
diff -u -d -r1.8 -r1.8.2.1
--- sql-api.c	26 Jan 2006 22:01:08 -0000	1.8
+++ sql-api.c	31 May 2006 11:02:45 -0000	1.8.2.1
@@ -66,6 +66,11 @@
 	return db->connect(db);
 }
 
+char *sql_escape_string(struct sql_db *db, const char *string)
+{
+	return db->escape_string(db, string);
+}
+
 void sql_exec(struct sql_db *db, const char *query)
 {
 	db->exec(db, query);

Index: sql-api.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-sql/sql-api.h,v
retrieving revision 1.8
retrieving revision 1.8.2.1
diff -u -d -r1.8 -r1.8.2.1
--- sql-api.h	24 Feb 2006 10:20:27 -0000	1.8
+++ sql-api.h	31 May 2006 11:02:45 -0000	1.8.2.1
@@ -37,6 +37,9 @@
    1 if we are fully connected now. */
 int sql_connect(struct sql_db *db);
 
+/* Escape the given string if needed and return it. */
+char *sql_escape_string(struct sql_db *db, const char *string);
+
 /* Execute SQL query without waiting for results. */
 void sql_exec(struct sql_db *db, const char *query);
 /* Execute SQL query and return result in callback. */



More information about the dovecot-cvs mailing list