]> granicus.if.org Git - php/commitdiff
MFB: Make quote() in PostgreSQL use PQescapeByteaConn() whenever possible
authorIlia Alshanetsky <iliaa@php.net>
Fri, 6 Oct 2006 22:34:29 +0000 (22:34 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Fri, 6 Oct 2006 22:34:29 +0000 (22:34 +0000)
for binary strings.

ext/pdo_pgsql/config.m4
ext/pdo_pgsql/pgsql_driver.c

index b466655fa482aaf2cda1d8b9ea1049746ba10931..edab0441b805732eafb0180e39e0bd92ce849584 100644 (file)
@@ -83,6 +83,7 @@ if test "$PHP_PDO_PGSQL" != "no"; then
   LDFLAGS="$LDFLAGS -L$PGSQL_LIBDIR"
   AC_CHECK_LIB(pq, PQescapeString,AC_DEFINE(HAVE_PQESCAPE,1,[PostgreSQL 7.2.0 or later]))
   AC_CHECK_LIB(pq, PQescapeStringConn, AC_DEFINE(HAVE_PQESCAPE_CONN,1,[PostgreSQL 8.1.4 or later]))
+  AC_CHECK_LIB(pq, PQescapeByteaConn, AC_DEFINE(HAVE_PQESCAPE_BYTEA_CONN,1,[PostgreSQL 8.1.4 or later]))
   AC_CHECK_LIB(pq, PQsetnonblocking,AC_DEFINE(HAVE_PQSETNONBLOCKING,1,[PostgreSQL 7.0.x or later]))
   AC_CHECK_LIB(pq, PQcmdTuples,AC_DEFINE(HAVE_PQCMDTUPLES,1,[Broken libpq under windows]))
   AC_CHECK_LIB(pq, PQoidValue,AC_DEFINE(HAVE_PQOIDVALUE,1,[Older PostgreSQL]))
index 002391f29e10883e555885dd7293e238973daf04..2ed26595835592da61811e3ec3d9b5bc0d5c3a04 100644 (file)
@@ -251,11 +251,16 @@ static long pgsql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRM
 static int pgsql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, char **quoted, int *quotedlen, enum pdo_param_type paramtype TSRMLS_DC)
 {
        unsigned char *escaped;
+       pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
        
        switch (paramtype) {
                case PDO_PARAM_LOB:
                        /* escapedlen returned by PQescapeBytea() accounts for trailing 0 */
+#ifdef HAVE_PQESCAPE_BYTEA_CONN
+                       escaped = PQescapeByteaConn(H->server, unquoted, unquotedlen, quotedlen);
+#else
                        escaped = PQescapeBytea(unquoted, unquotedlen, quotedlen);
+#endif
                        *quotedlen += 1;
                        *quoted = emalloc(*quotedlen + 1);
                        memcpy((*quoted)+1, escaped, *quotedlen-2);
@@ -264,9 +269,7 @@ static int pgsql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquote
                        (*quoted)[*quotedlen] = '\0';
                        free(escaped);
                        break;
-               default: {
-                       pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
-
+               default:
                        *quoted = safe_emalloc(2, unquotedlen, 3);
                        (*quoted)[0] = '\'';
 #ifndef HAVE_PQESCAPE_CONN
@@ -277,7 +280,6 @@ static int pgsql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquote
                        (*quoted)[*quotedlen + 1] = '\'';
                        (*quoted)[*quotedlen + 2] = '\0';
                        *quotedlen += 2;
-               }
        }
        return 1;
 }