]> granicus.if.org Git - php/commitdiff
MFB: Added support for character sets in PDO quote() method for PostgreSQL
authorIlia Alshanetsky <iliaa@php.net>
Wed, 4 Oct 2006 23:53:54 +0000 (23:53 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Wed, 4 Oct 2006 23:53:54 +0000 (23:53 +0000)
8.1.4 and higher.

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

index 9f356db64afb712136920013af1c2416ae5660c6..b466655fa482aaf2cda1d8b9ea1049746ba10931 100644 (file)
@@ -82,6 +82,7 @@ if test "$PHP_PDO_PGSQL" != "no"; then
   old_LDFLAGS=$LDFLAGS
   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, 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 08edc81f92407976a758cc9940050df40de487bc..002391f29e10883e555885dd7293e238973daf04 100644 (file)
@@ -264,13 +264,20 @@ static int pgsql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquote
                        (*quoted)[*quotedlen] = '\0';
                        free(escaped);
                        break;
-               default:
-                       *quoted = emalloc(2*unquotedlen + 3);
+               default: {
+                       pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
+
+                       *quoted = safe_emalloc(2, unquotedlen, 3);
                        (*quoted)[0] = '\'';
+#ifndef HAVE_PQESCAPE_CONN
                        *quotedlen = PQescapeString(*quoted + 1, unquoted, unquotedlen);
+#else
+                       *quotedlen = PQescapeStringConn(H->server, *quoted + 1, unquoted, unquotedlen, NULL);
+#endif
                        (*quoted)[*quotedlen + 1] = '\'';
                        (*quoted)[*quotedlen + 2] = '\0';
                        *quotedlen += 2;
+               }
        }
        return 1;
 }
@@ -297,7 +304,11 @@ static char *pdo_pgsql_last_insert_id(pdo_dbh_t *dbh, const char *name, unsigned
                size_t l = strlen(name);
         
                name_escaped = safe_emalloc(l, 2, 1);
+#ifndef HAVE_PQESCAPE_CONN
                PQescapeString(name_escaped, name, l);
+#else
+               PQescapeStringConn(H->server, name_escaped, name, l, NULL);
+#endif
                spprintf(&q, 0, "SELECT CURRVAL('%s')", name_escaped);
                res = PQexec(H->server, q);
                efree(name_escaped);