diff options
author | Ilia Alshanetsky <iliaa@php.net> | 2005-07-07 13:35:39 +0000 |
---|---|---|
committer | Ilia Alshanetsky <iliaa@php.net> | 2005-07-07 13:35:39 +0000 |
commit | 6c332449f926ff3bc3f4bf3bb7786bcc27afcc3a (patch) | |
tree | 65d1430b1093b0aae9141e1af20d385ad89c962c /ext | |
parent | 09d433a3491c45f25c6cbfb16b45053e078dd9fa (diff) | |
download | php-git-6c332449f926ff3bc3f4bf3bb7786bcc27afcc3a.tar.gz |
Use PQexecParams() when available, use original case in all other instances.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/pdo_pgsql/config.m4 | 1 | ||||
-rw-r--r-- | ext/pdo_pgsql/pgsql_driver.c | 16 |
2 files changed, 14 insertions, 3 deletions
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)) { |