From e448be3c28baecc424f92478999ca1367b64c55d Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Wed, 4 Oct 2006 23:53:54 +0000 Subject: [PATCH] MFB: Added support for character sets in PDO quote() method for PostgreSQL 8.1.4 and higher. --- ext/pdo_pgsql/config.m4 | 1 + ext/pdo_pgsql/pgsql_driver.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ext/pdo_pgsql/config.m4 b/ext/pdo_pgsql/config.m4 index 9f356db64a..b466655fa4 100644 --- a/ext/pdo_pgsql/config.m4 +++ b/ext/pdo_pgsql/config.m4 @@ -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])) diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c index 08edc81f92..002391f29e 100644 --- a/ext/pdo_pgsql/pgsql_driver.c +++ b/ext/pdo_pgsql/pgsql_driver.c @@ -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); -- 2.50.1