diff options
Diffstat (limited to 'ext/pdo_pgsql')
-rw-r--r-- | ext/pdo_pgsql/config.m4 | 4 | ||||
-rw-r--r-- | ext/pdo_pgsql/config.w32 | 5 | ||||
-rw-r--r-- | ext/pdo_pgsql/pgsql_driver.c | 21 | ||||
-rw-r--r-- | ext/pdo_pgsql/pgsql_statement.c | 23 |
4 files changed, 38 insertions, 15 deletions
diff --git a/ext/pdo_pgsql/config.m4 b/ext/pdo_pgsql/config.m4 index fd9a9297a..2ba87ab8c 100644 --- a/ext/pdo_pgsql/config.m4 +++ b/ext/pdo_pgsql/config.m4 @@ -1,5 +1,5 @@ dnl -dnl $Id: config.m4,v 1.13 2005/07/27 02:51:01 wez Exp $ +dnl $Id: config.m4,v 1.13.4.2 2006/10/06 22:34:16 iliaa Exp $ dnl if test "$PHP_PDO" != "no"; then @@ -82,6 +82,8 @@ 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, PQescapeByteaConn, AC_DEFINE(HAVE_PQESCAPE_BYTEA_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/config.w32 b/ext/pdo_pgsql/config.w32 index 618ff1fc6..765abedda 100644 --- a/ext/pdo_pgsql/config.w32 +++ b/ext/pdo_pgsql/config.w32 @@ -1,4 +1,4 @@ -// $Id: config.w32,v 1.4.2.1 2006/03/14 10:49:18 edink Exp $ +// $Id: config.w32,v 1.4.2.1.2.3 2006/10/11 11:00:03 edink Exp $ // vim:ft=javascript ARG_WITH("pdo-pgsql", "PostgreSQL support for PDO", "no"); @@ -12,9 +12,8 @@ if (PHP_PDO_PGSQL != "no") { ADD_FLAG('CFLAGS_PDO_PGSQL', "/D HAVE_PG_CONFIG_H"); } - ADD_FLAG('CFLAGS_PDO_PGSQL', "/I ..\\pecl"); AC_DEFINE('HAVE_PDO_PGSQL', 1, 'Have PostgreSQL library'); - ADD_FLAG('CFLAGS_PDO_PGSQL', "/D HAVE_PQPARAMETERSTATUS=1 /D HAVE_PQPROTOCOLVERSION=1 /D HAVE_PGTRANSACTIONSTATUS=1 /D HAVE_PQUNESCAPEBYTEA=1 /D HAVE_PQRESULTERRORFIELD=1"); + ADD_FLAG('CFLAGS_PDO_PGSQL', "/D HAVE_PQPARAMETERSTATUS=1 /D HAVE_PQPROTOCOLVERSION=1 /D HAVE_PGTRANSACTIONSTATUS=1 /D HAVE_PQUNESCAPEBYTEA=1 /D HAVE_PQRESULTERRORFIELD=1 /D HAVE_PQESCAPE_CONN=1 /D HAVE_PQESCAPE_BYTEA_CONN=1"); } else { WARNING("pdo_pgsql not enabled; libraries and headers not found"); } diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c index 84fd076c6..2a8c971df 100644 --- a/ext/pdo_pgsql/pgsql_driver.c +++ b/ext/pdo_pgsql/pgsql_driver.c @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pgsql_driver.c,v 1.53.2.14 2006/04/09 08:17:50 wez Exp $ */ +/* $Id: pgsql_driver.c,v 1.53.2.14.2.4 2006/10/06 22:34:16 iliaa Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -229,6 +229,9 @@ static int pgsql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len, PDO_CURSOR_FWDONLY TSRMLS_CC) == PDO_CURSOR_SCROLL; if (scrollable) { + if (S->cursor_name) { + efree(S->cursor_name); + } /* TODO: check how scrollable cursors related to prepared statements */ spprintf(&S->cursor_name, 0, "pdo_pgsql_cursor_%08x", (unsigned int) stmt); } @@ -306,11 +309,16 @@ static long pgsql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRM static int pgsql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen, char **quoted, int *quotedlen, enum pdo_param_type paramtype TSRMLS_DC) { unsigned char *escaped; + pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data; switch (paramtype) { case PDO_PARAM_LOB: /* escapedlen returned by PQescapeBytea() accounts for trailing 0 */ +#ifdef HAVE_PQESCAPE_BYTEA_CONN + escaped = PQescapeByteaConn(H->server, unquoted, unquotedlen, quotedlen); +#else escaped = PQescapeBytea(unquoted, unquotedlen, quotedlen); +#endif *quotedlen += 1; *quoted = emalloc(*quotedlen + 1); memcpy((*quoted)+1, escaped, *quotedlen-2); @@ -320,9 +328,13 @@ static int pgsql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquote free(escaped); break; default: - *quoted = emalloc(2*unquotedlen + 3); + *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; @@ -352,7 +364,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); @@ -469,6 +485,7 @@ static int pdo_pgsql_transaction_cmd(const char *cmd, pdo_dbh_t *dbh TSRMLS_DC) res = PQexec(H->server, cmd); if (PQresultStatus(res) != PGRES_COMMAND_OK) { + pdo_pgsql_error(dbh, PQresultStatus(res), pdo_pgsql_sqlstate(res)); ret = 0; } diff --git a/ext/pdo_pgsql/pgsql_statement.c b/ext/pdo_pgsql/pgsql_statement.c index 5abdfa111..01271fbaf 100644 --- a/ext/pdo_pgsql/pgsql_statement.c +++ b/ext/pdo_pgsql/pgsql_statement.c @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pgsql_statement.c,v 1.31.2.12 2006/03/27 20:51:01 wez Exp $ */ +/* $Id: pgsql_statement.c,v 1.31.2.12.2.3 2006/09/19 15:45:21 iliaa Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -60,10 +60,14 @@ static int pgsql_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC) char *q = NULL; PGresult *res; - spprintf(&q, 0, "DEALLOCATE %s", S->stmt_name); - res = PQexec(H->server, q); - efree(q); - if (res) PQclear(res); + if (S->is_prepared) { + spprintf(&q, 0, "DEALLOCATE %s", S->stmt_name); + res = PQexec(H->server, q); + efree(q); + if (res) { + PQclear(res); + } + } efree(S->stmt_name); S->stmt_name = NULL; } @@ -247,16 +251,16 @@ static int pgsql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data * case PDO_PARAM_EVT_EXEC_PRE: if (!S->param_values) { S->param_values = ecalloc( - zend_hash_num_elements(stmt->bound_params), + zend_hash_num_elements(stmt->bound_param_map), sizeof(char*)); S->param_lengths = ecalloc( - zend_hash_num_elements(stmt->bound_params), + zend_hash_num_elements(stmt->bound_param_map), sizeof(int)); S->param_formats = ecalloc( - zend_hash_num_elements(stmt->bound_params), + zend_hash_num_elements(stmt->bound_param_map), sizeof(int)); S->param_types = ecalloc( - zend_hash_num_elements(stmt->bound_params), + zend_hash_num_elements(stmt->bound_param_map), sizeof(Oid)); } if (param->paramno >= 0) { @@ -341,6 +345,7 @@ static int pgsql_stmt_fetch(pdo_stmt_t *stmt, spprintf(&q, 0, "FETCH %s %ld FROM %s", ori_str, offset, S->cursor_name); S->result = PQexec(S->H->server, q); + efree(q); status = PQresultStatus(S->result); if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) { |