From 40765184be9523a3fb4f8e4a1750bbfd6eb6a877 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Wed, 4 Oct 2006 23:53:36 +0000 Subject: [PATCH] Added support for character sets in PDO quote() method for PostgreSQL 8.1.4 and higher. --- NEWS | 2 ++ ext/pdo_pgsql/config.m4 | 1 + ext/pdo_pgsql/pgsql_driver.c | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 096e7957fa..be687953d5 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ PHP NEWS - Added ability to make SOAP call userspace PHP<->XML converters. (Dmitry) - Added support for character sets in pg_escape_string() for PostgreSQL 8.1.4 and higher. (Ilia) +- Added support for character sets in PDO quote() method for PostgreSQL + 8.1.4 and higher. (Ilia) - Fixed infinite loop when a wrong color index is given to imagefill (Pierre) - Fixed mess with CGI/CLI -d option (now it works with cgi; constants are working exactly like in php.ini; with FastCGI -d affects all requests). 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 11f320e416..24e66adba9 100644 --- a/ext/pdo_pgsql/pgsql_driver.c +++ b/ext/pdo_pgsql/pgsql_driver.c @@ -322,13 +322,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; } @@ -355,7 +362,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.40.0