summaryrefslogtreecommitdiff
path: root/ext/pdo_pgsql
diff options
context:
space:
mode:
authorSean Finney <seanius@debian.org>2009-06-24 22:49:04 +0200
committerSean Finney <seanius@debian.org>2009-06-24 22:49:04 +0200
commit84f4ca9b07fe5b73d840258f4aa7c1eb534c4253 (patch)
tree9829bd578af8a4a8b42b04277f9067e00dc5ad90 /ext/pdo_pgsql
parent6821b67124604da690c5e9276d5370d679c63ac8 (diff)
downloadphp-84f4ca9b07fe5b73d840258f4aa7c1eb534c4253.tar.gz
Imported Upstream version 5.3.0~RC4upstream/5.3.0_RC4upstream/5.3.0.RC4
Diffstat (limited to 'ext/pdo_pgsql')
-rw-r--r--ext/pdo_pgsql/config.m423
-rw-r--r--ext/pdo_pgsql/config.w327
-rw-r--r--ext/pdo_pgsql/pdo_pgsql.c9
-rw-r--r--ext/pdo_pgsql/pgsql_driver.c43
-rw-r--r--ext/pdo_pgsql/pgsql_statement.c188
-rw-r--r--ext/pdo_pgsql/php_pdo_pgsql_int.h8
-rw-r--r--ext/pdo_pgsql/tests/bug46274_2.phpt16
7 files changed, 108 insertions, 186 deletions
diff --git a/ext/pdo_pgsql/config.m4 b/ext/pdo_pgsql/config.m4
index 85d8cb6ed..4e59b77f5 100644
--- a/ext/pdo_pgsql/config.m4
+++ b/ext/pdo_pgsql/config.m4
@@ -1,4 +1,4 @@
-dnl $Id: config.m4,v 1.13.4.6.2.1 2008/07/25 13:46:24 jani Exp $
+dnl $Id: config.m4,v 1.13.4.6.2.2 2009/04/30 12:38:43 mbeccati Exp $
dnl config.m4 for extension pdo_pgsql
dnl vim:et:sw=2:ts=2:
@@ -82,23 +82,18 @@ if test "$PHP_PDO_PGSQL" != "no"; then
old_LIBS=$LIBS
old_LDFLAGS=$LDFLAGS
- LDFLAGS="$LDFLAGS -L$PGSQL_LIBDIR"
- AC_CHECK_LIB(pq, PQescapeString,AC_DEFINE(HAVE_PQESCAPE,1,[PostgreSQL 7.2.0 or later]))
+ LDFLAGS="-L$PGSQL_LIBDIR $LDFLAGS"
+ AC_CHECK_LIB(pq, PQparameterStatus,AC_DEFINE(HAVE_PQPARAMETERSTATUS,1,[PostgreSQL 7.4 or later]), [
+ echo "Unable to build the PDO PostgreSQL driver: libpq 7.4+ is required"
+ exit 1
+ ])
+
+ AC_CHECK_LIB(pq, PQprepare,AC_DEFINE(HAVE_PQPREPARE,1,[PostgreSQL 8.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]))
- AC_CHECK_LIB(pq, PQclientEncoding,AC_DEFINE(HAVE_PQCLIENTENCODING,1,[PostgreSQL 7.0.x or later]))
- AC_CHECK_LIB(pq, PQparameterStatus,AC_DEFINE(HAVE_PQPARAMETERSTATUS,1,[PostgreSQL 7.4 or later]))
- 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]))
- AC_CHECK_LIB(pq, PQprepare,AC_DEFINE(HAVE_PQPREPARE,1,[prepared statements]))
LIBS=$old_LIBS
LDFLAGS=$old_LDFLAGS
diff --git a/ext/pdo_pgsql/config.w32 b/ext/pdo_pgsql/config.w32
index 83b5d217d..f14107b68 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.2.3.2.2 2009/03/09 17:52:37 pajoye Exp $
+// $Id: config.w32,v 1.4.2.1.2.3.2.5 2009/04/30 12:56:00 mbeccati Exp $
// vim:ft=javascript
ARG_WITH("pdo-pgsql", "PostgreSQL support for PDO", "no");
@@ -12,7 +12,10 @@ if (PHP_PDO_PGSQL != "no") {
ADD_FLAG('CFLAGS_PDO_PGSQL', "/D HAVE_PG_CONFIG_H");
}
- AC_DEFINE('HAVE_PDO_PGSQL', 1, 'Have PostgreSQL library');
+ AC_DEFINE('HAVE_PDO_PGSQL', 1, 'Have PostgreSQL library');
+ AC_DEFINE('HAVE_PQESCAPE_BYTEA_CONN', 1, 'Have PQescapeByteaConn');
+ AC_DEFINE('HAVE_PQESCAPE_CONN', 1, 'Have PQescapeConn');
+ AC_DEFINE('HAVE_PQPREPARE', 1, 'Have PQprepare');
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");
ADD_EXTENSION_DEP('pdo_pgsql', 'pdo');
} else {
diff --git a/ext/pdo_pgsql/pdo_pgsql.c b/ext/pdo_pgsql/pdo_pgsql.c
index 84c98cb60..2e4e820d0 100644
--- a/ext/pdo_pgsql/pdo_pgsql.c
+++ b/ext/pdo_pgsql/pdo_pgsql.c
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: pdo_pgsql.c,v 1.7.2.11.2.1.2.3 2008/12/31 11:15:41 sebastian Exp $ */
+/* $Id: pdo_pgsql.c,v 1.7.2.11.2.1.2.4 2009/03/28 01:58:49 mbeccati Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -31,6 +31,11 @@
#include "php_pdo_pgsql_int.h"
#ifdef HAVE_PG_CONFIG_H
+#undef PACKAGE_BUGREPORT
+#undef PACKAGE_NAME
+#undef PACKAGE_STRING
+#undef PACKAGE_TARNAME
+#undef PACKAGE_VERSION
#include <pg_config.h>
#endif
@@ -123,7 +128,7 @@ PHP_MINFO_FUNCTION(pdo_pgsql)
php_info_print_table_row(2, "PostgreSQL(libpq) Version", PG_VERSION);
#endif
php_info_print_table_row(2, "Module version", pdo_pgsql_module_entry.version);
- php_info_print_table_row(2, "Revision", " $Id: pdo_pgsql.c,v 1.7.2.11.2.1.2.3 2008/12/31 11:15:41 sebastian Exp $ ");
+ php_info_print_table_row(2, "Revision", " $Id: pdo_pgsql.c,v 1.7.2.11.2.1.2.4 2009/03/28 01:58:49 mbeccati Exp $ ");
php_info_print_table_end();
}
diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c
index 97d68a6d7..91f8d7754 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.2.9.2.4 2008/12/31 11:15:41 sebastian Exp $ */
+/* $Id: pgsql_driver.c,v 1.53.2.14.2.9.2.8 2009/04/30 12:56:00 mbeccati Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -232,13 +232,15 @@ static int pgsql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len,
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);
+ spprintf(&S->cursor_name, 0, "pdo_crsr_%016lx", (unsigned long) stmt);
+#if HAVE_PQPREPARE
+ emulate = 1;
+#endif
}
#if HAVE_PQPREPARE
- if (driver_options) {
+ else if (driver_options) {
if (pdo_attr_lval(driver_options,
PDO_PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT, 0 TSRMLS_CC) == 1) {
emulate = 1;
@@ -262,7 +264,7 @@ static int pgsql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len,
return 0;
}
- spprintf(&S->stmt_name, 0, "pdo_pgsql_stmt_%08x", (unsigned int)stmt);
+ spprintf(&S->stmt_name, 0, "pdo_stmt_%016lx", (unsigned long)stmt);
/* that's all for now; we'll defer the actual prepare until the first execute call */
if (nsql) {
@@ -298,9 +300,7 @@ static long pgsql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRM
return -1;
}
H->pgoid = PQoidValue(res);
-#if HAVE_PQCMDTUPLES
ret = atol(PQcmdTuples(res));
-#endif
PQclear(res);
return ret;
@@ -310,16 +310,17 @@ static int pgsql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquote
{
unsigned char *escaped;
pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
+ size_t tmp_len;
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);
+ escaped = PQescapeByteaConn(H->server, unquoted, unquotedlen, &tmp_len);
#else
- escaped = PQescapeBytea(unquoted, unquotedlen, quotedlen);
+ escaped = PQescapeBytea(unquoted, unquotedlen, &tmp_len);
#endif
- *quotedlen += 1;
+ *quotedlen = (int)tmp_len + 1;
*quoted = emalloc(*quotedlen + 1);
memcpy((*quoted)+1, escaped, *quotedlen-2);
(*quoted)[0] = '\'';
@@ -355,25 +356,9 @@ static char *pdo_pgsql_last_insert_id(pdo_dbh_t *dbh, const char *name, unsigned
} else {
PGresult *res;
ExecStatusType status;
-#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);
-#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);
- efree(q);
-#endif
status = PQresultStatus(res);
if (res && (status == PGRES_TUPLES_OK)) {
@@ -400,11 +385,9 @@ static int pdo_pgsql_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_value
break;
case PDO_ATTR_SERVER_VERSION:
-#ifdef HAVE_PQPROTOCOLVERSION
if (PQprotocolVersion(H->server) >= 3) { /* PostgreSQL 7.4 or later */
ZVAL_STRING(return_value, (char*)PQparameterStatus(H->server, "server_version"), 1);
} else /* emulate above via a query */
-#endif
{
PGresult *res = PQexec(H->server, "SELECT VERSION()");
if (res && PQresultStatus(res) == PGRES_TUPLES_OK) {
@@ -454,7 +437,6 @@ static int pdo_pgsql_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_value
case PDO_ATTR_SERVER_INFO: {
int spid = PQbackendPID(H->server);
char *tmp;
-#ifdef HAVE_PQPROTOCOLVERSION
spprintf(&tmp, 0,
"PID: %d; Client Encoding: %s; Is Superuser: %s; Session Authorization: %s; Date Style: %s",
spid,
@@ -462,9 +444,6 @@ static int pdo_pgsql_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_value
(char*)PQparameterStatus(H->server, "is_superuser"),
(char*)PQparameterStatus(H->server, "session_authorization"),
(char*)PQparameterStatus(H->server, "DateStyle"));
-#else
- spprintf(&tmp, 0, "PID: %d", spid);
-#endif
ZVAL_STRING(return_value, tmp, 0);
}
break;
diff --git a/ext/pdo_pgsql/pgsql_statement.c b/ext/pdo_pgsql/pgsql_statement.c
index a854f5d0e..d35af9aa0 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.2.7.2.8 2008/12/31 11:15:41 sebastian Exp $ */
+/* $Id: pgsql_statement.c,v 1.31.2.12.2.7.2.13 2009/05/25 19:41:13 kalle Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -129,6 +129,34 @@ static int pgsql_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC)
S->current_row = 0;
+ if (S->cursor_name) {
+ char *q = NULL;
+
+ if (S->is_prepared) {
+ spprintf(&q, 0, "CLOSE %s", S->cursor_name);
+ S->result = PQexec(H->server, q);
+ efree(q);
+ }
+
+ spprintf(&q, 0, "DECLARE %s SCROLL CURSOR WITH HOLD FOR %s", S->cursor_name, stmt->active_query_string);
+ S->result = PQexec(H->server, q);
+ efree(q);
+
+ /* check if declare failed */
+ status = PQresultStatus(S->result);
+ if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) {
+ pdo_pgsql_error_stmt(stmt, status, pdo_pgsql_sqlstate(S->result));
+ return 0;
+ }
+
+ /* the cursor was declared correctly */
+ S->is_prepared = 1;
+
+ /* fetch to be able to get the number of tuples later, but don't advance the cursor pointer */
+ spprintf(&q, 0, "FETCH FORWARD 0 FROM %s", S->cursor_name);
+ S->result = PQexec(H->server, q);
+ efree(q);
+ } else
#if HAVE_PQPREPARE
if (S->stmt_name) {
/* using a prepared statement */
@@ -152,12 +180,12 @@ stmt_retry:
char *sqlstate = pdo_pgsql_sqlstate(S->result);
/* 42P05 means that the prepared statement already existed. this can happen if you use
* a connection pooling software line pgpool which doesn't close the db-connection once
- * php disconnects. if php dies (no chanche to run RSHUTDOWN) during execution it has no
+ * php disconnects. if php dies (no chance to run RSHUTDOWN) during execution it has no
* chance to DEALLOCATE the prepared statements it has created. so, if we hit a 42P05 we
* deallocate it and retry ONCE (thies 2005.12.15)
*/
if (!strcmp(sqlstate, "42P05")) {
- char buf[100]; /* stmt_name == "pdo_pgsql_cursor_%08x" */
+ char buf[100]; /* stmt_name == "pdo_crsr_%016lx" */
PGresult *res;
snprintf(buf, sizeof(buf), "DEALLOCATE %s", S->stmt_name);
res = PQexec(H->server, buf);
@@ -182,12 +210,7 @@ stmt_retry:
0);
} else
#endif
- if (S->cursor_name) {
- char *q = NULL;
- spprintf(&q, 0, "DECLARE %s CURSOR FOR %s", S->cursor_name, stmt->active_query_string);
- S->result = PQexec(H->server, q);
- efree(q);
- } else {
+ {
S->result = PQexec(H->server, stmt->active_query_string);
}
status = PQresultStatus(S->result);
@@ -350,19 +373,23 @@ static int pgsql_stmt_fetch(pdo_stmt_t *stmt,
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
if (S->cursor_name) {
- char *ori_str;
+ char *ori_str = NULL;
char *q = NULL;
ExecStatusType status;
switch (ori) {
- case PDO_FETCH_ORI_NEXT: ori_str = "FORWARD"; break;
- case PDO_FETCH_ORI_PRIOR: ori_str = "BACKWARD"; break;
- case PDO_FETCH_ORI_REL: ori_str = "RELATIVE"; break;
+ case PDO_FETCH_ORI_NEXT: spprintf(&ori_str, 0, "NEXT"); break;
+ case PDO_FETCH_ORI_PRIOR: spprintf(&ori_str, 0, "BACKWARD"); break;
+ case PDO_FETCH_ORI_FIRST: spprintf(&ori_str, 0, "FIRST"); break;
+ case PDO_FETCH_ORI_LAST: spprintf(&ori_str, 0, "LAST"); break;
+ case PDO_FETCH_ORI_ABS: spprintf(&ori_str, 0, "ABSOLUTE %ld", offset); break;
+ case PDO_FETCH_ORI_REL: spprintf(&ori_str, 0, "RELATIVE %ld", offset); break;
default:
return 0;
}
- spprintf(&q, 0, "FETCH %s %ld FROM %s", ori_str, offset, S->cursor_name);
+ spprintf(&q, 0, "FETCH %s FROM %s", ori_str, S->cursor_name);
+ efree(ori_str);
S->result = PQexec(S->H->server, q);
efree(q);
status = PQresultStatus(S->result);
@@ -372,9 +399,12 @@ static int pgsql_stmt_fetch(pdo_stmt_t *stmt,
return 0;
}
- S->current_row = 1;
- return 1;
-
+ if (PQntuples(S->result)) {
+ S->current_row = 1;
+ return 1;
+ } else {
+ return 0;
+ }
} else {
if (S->current_row < stmt->row_count) {
S->current_row++;
@@ -447,110 +477,6 @@ static int pgsql_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC)
return 1;
}
-/* PQunescapeBytea() from PostgreSQL 7.3 to provide bytea unescape feature to 7.2 users.
- Renamed to php_pdo_pgsql_unescape_bytea() */
-/*
- * PQunescapeBytea - converts the null terminated string representation
- * of a bytea, strtext, into binary, filling a buffer. It returns a
- * pointer to the buffer which is NULL on error, and the size of the
- * buffer in retbuflen. The pointer may subsequently be used as an
- * argument to the function free(3). It is the reverse of PQescapeBytea.
- *
- * The following transformations are reversed:
- * '\0' == ASCII 0 == \000
- * '\'' == ASCII 39 == \'
- * '\\' == ASCII 92 == \\
- *
- * States:
- * 0 normal 0->1->2->3->4
- * 1 \ 1->5
- * 2 \0 1->6
- * 3 \00
- * 4 \000
- * 5 \'
- * 6 \\
- */
-static unsigned char *php_pdo_pgsql_unescape_bytea(unsigned char *strtext, size_t *retbuflen)
-{
- size_t buflen;
- unsigned char *buffer,
- *sp,
- *bp;
- unsigned int state = 0;
-
- if (strtext == NULL)
- return NULL;
- buflen = strlen(strtext); /* will shrink, also we discover if
- * strtext */
- buffer = (unsigned char *) emalloc(buflen); /* isn't NULL terminated */
- for (bp = buffer, sp = strtext; *sp != '\0'; bp++, sp++)
- {
- switch (state)
- {
- case 0:
- if (*sp == '\\')
- state = 1;
- *bp = *sp;
- break;
- case 1:
- if (*sp == '\'') /* state=5 */
- { /* replace \' with 39 */
- bp--;
- *bp = '\'';
- buflen--;
- state = 0;
- }
- else if (*sp == '\\') /* state=6 */
- { /* replace \\ with 92 */
- bp--;
- *bp = '\\';
- buflen--;
- state = 0;
- }
- else
- {
- if (isdigit(*sp))
- state = 2;
- else
- state = 0;
- *bp = *sp;
- }
- break;
- case 2:
- if (isdigit(*sp))
- state = 3;
- else
- state = 0;
- *bp = *sp;
- break;
- case 3:
- if (isdigit(*sp)) /* state=4 */
- {
- unsigned char *start, *end, buf[4]; /* 000 + '\0' */
-
- bp -= 3;
- memcpy(buf, sp-2, 3);
- buf[3] = '\0';
- start = buf;
- *bp = (unsigned char)strtoul(start, (char **)&end, 8);
- buflen -= 3;
- state = 0;
- }
- else
- {
- *bp = *sp;
- state = 0;
- }
- break;
- }
- }
- buffer = erealloc(buffer, buflen+1);
- buffer[buflen] = '\0';
-
- *retbuflen = buflen;
- return buffer;
-}
-
static int pgsql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsigned long *len, int *caller_frees TSRMLS_DC)
{
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
@@ -598,9 +524,23 @@ static int pgsql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsigned
*len = 0;
return 0;
} else {
- *ptr = php_pdo_pgsql_unescape_bytea(*ptr, &tmp_len);
- *len = tmp_len;
- *caller_frees = 1;
+ char *tmp_ptr = PQunescapeBytea(*ptr, &tmp_len);
+ if (!tmp_ptr) {
+ /* PQunescapeBytea returned an error */
+ *len = 0;
+ return 0;
+ }
+ if (!tmp_len) {
+ /* Empty string, return as empty stream */
+ *ptr = (char *)php_stream_memory_open(TEMP_STREAM_READONLY, "", 0);
+ PQfreemem(tmp_ptr);
+ *len = 0;
+ } else {
+ *ptr = estrndup(tmp_ptr, tmp_len);
+ PQfreemem(tmp_ptr);
+ *len = tmp_len;
+ *caller_frees = 1;
+ }
}
break;
case PDO_PARAM_NULL:
diff --git a/ext/pdo_pgsql/php_pdo_pgsql_int.h b/ext/pdo_pgsql/php_pdo_pgsql_int.h
index d3bfe84d6..2c080c112 100644
--- a/ext/pdo_pgsql/php_pdo_pgsql_int.h
+++ b/ext/pdo_pgsql/php_pdo_pgsql_int.h
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_pdo_pgsql_int.h,v 1.13.2.4.2.1.2.2 2008/12/31 11:15:41 sebastian Exp $ */
+/* $Id: php_pdo_pgsql_int.h,v 1.13.2.4.2.1.2.4 2009/05/12 22:18:14 mbeccati Exp $ */
#ifndef PHP_PDO_PGSQL_INT_H
#define PHP_PDO_PGSQL_INT_H
@@ -65,8 +65,8 @@ typedef struct {
int *param_lengths;
int *param_formats;
Oid *param_types;
- zend_bool is_prepared;
#endif
+ zend_bool is_prepared;
} pdo_pgsql_stmt;
typedef struct {
@@ -81,11 +81,7 @@ extern int _pdo_pgsql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, int errcode, const
extern struct pdo_stmt_methods pgsql_stmt_methods;
-#ifdef HAVE_PQRESULTERRORFIELD
#define pdo_pgsql_sqlstate(r) PQresultErrorField(r, PG_DIAG_SQLSTATE)
-#else
-#define pdo_pgsql_sqlstate(r) (const char *)NULL
-#endif
enum {
PDO_PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT = PDO_ATTR_DRIVER_SPECIFIC,
diff --git a/ext/pdo_pgsql/tests/bug46274_2.phpt b/ext/pdo_pgsql/tests/bug46274_2.phpt
index 5e3555688..eb675afe9 100644
--- a/ext/pdo_pgsql/tests/bug46274_2.phpt
+++ b/ext/pdo_pgsql/tests/bug46274_2.phpt
@@ -47,11 +47,13 @@ $res = $db->query("SELECT blob1 from test_one_blob");
var_dump($x = $res->fetch());
var_dump(fread($x['blob1'], 10));
-// Empty string
+// Resource
var_dump($res->fetch());
+var_dump(fread($x['blob1'], 10));
-// Empty string
+// Resource
var_dump($res->fetch());
+var_dump(fread($x['blob1'], 10));
// NULL
var_dump($res->fetch());
@@ -69,16 +71,18 @@ array(2) {
string(3) "foo"
array(2) {
["blob1"]=>
- string(0) ""
+ resource(%d) of type (stream)
[0]=>
- string(0) ""
+ resource(%d) of type (stream)
}
+string(0) ""
array(2) {
["blob1"]=>
- string(0) ""
+ resource(%d) of type (stream)
[0]=>
- string(0) ""
+ resource(%d) of type (stream)
}
+string(0) ""
array(2) {
["blob1"]=>
NULL