From: Ilia Alshanetsky Date: Thu, 7 Jul 2005 13:35:39 +0000 (+0000) Subject: Use PQexecParams() when available, use original case in all other instances. X-Git-Tag: php-5.1.0b3~141 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6c332449f926ff3bc3f4bf3bb7786bcc27afcc3a;p=php Use PQexecParams() when available, use original case in all other instances. --- diff --git a/ext/pdo_pgsql/config.m4 b/ext/pdo_pgsql/config.m4 index 844aad1f8f..7e334505b1 100644 --- a/ext/pdo_pgsql/config.m4 +++ b/ext/pdo_pgsql/config.m4 @@ -90,6 +90,7 @@ if test "$PHP_PDO_PGSQL" != "no"; then AC_CHECK_LIB(pq, PQprotocolVersion,AC_DEFINE(HAVE_PQPROTOCOLVERSION,1,[PostgreSQL 7.4 or later])) AC_CHECK_LIB(pq, PQtransactionStatus,AC_DEFINE(HAVE_PGTRANSACTIONSTATUS,1,[PostgreSQL 7.4 or later])) AC_CHECK_LIB(pq, PQunescapeBytea,AC_DEFINE(HAVE_PQUNESCAPEBYTEA,1,[PostgreSQL 7.4 or later])) + AC_CHECK_LIB(pq, PQExecParams,AC_DEFINE(HAVE_PQEXECPARAMS,1,[PostgreSQL 7.4 or later])) AC_CHECK_LIB(pq, PQresultErrorField,AC_DEFINE(HAVE_PQRESULTERRORFIELD,1,[PostgreSQL 7.4 or later])) AC_CHECK_LIB(pq, pg_encoding_to_char,AC_DEFINE(HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT,1,[Whether libpq is compiled with --enable-multibyte])) LIBS=$old_LIBS diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c index 5dde6f2511..bc33bdb733 100644 --- a/ext/pdo_pgsql/pgsql_driver.c +++ b/ext/pdo_pgsql/pgsql_driver.c @@ -210,12 +210,22 @@ static char *pdo_pgsql_last_insert_id(pdo_dbh_t *dbh, const char *name, unsigned *len = spprintf(&id, 0, "%ld", (long) H->pgoid); } else { PGresult *res; - char *q; ExecStatusType status; - - spprintf(&q, sizeof("SELECT CURRVAL('')") + strlen(name), "SELECT CURRVAL('%s')", name); +#ifdef HAVE_PQEXECPARAMS + const char *q[1]; + q[0] = name; + res = PQexecParams(H->server, "SELECT CURRVAL($1)", 1, NULL, q, NULL, NULL, 0); +#else + char *name_escaped, *q; + size_t l = strlen(name); + + name_escaped = safe_emalloc(l, 2, 1); + PQescapeString(name_escaped, name, l); + spprintf(&q, 0, "SELECT CURRVAL('%s')", name_escaped); res = PQexec(H->server, q); + efree(name_escaped); efree(q); +#endif status = PQresultStatus(res); if (res && (status == PGRES_TUPLES_OK)) {