mbeccati                Thu Apr 30 12:35:36 2009 UTC

  Modified files:              
    /php-src/ext/pdo_pgsql      config.m4 config.w32 pgsql_driver.c 
                                pgsql_statement.c php_pdo_pgsql_int.h 
  Log:
  - Changed PDO_PGSQL configure script to require libpq 7.4
  - Cleaned up usage of HAVE_PQ* defines
  - Fixed compiler warnings
  - Removed custom implementation of PQunescapeByte
  # Rationale:
  # - PDO_PGSQL couldn't even compile when using libpq 7.3
  # - PostgreSQL 7.3 is unsupported since a long time
  # - Got consensus from pgsql devs on freenode
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_pgsql/config.m4?r1=1.21&r2=1.22&diff_format=u
Index: php-src/ext/pdo_pgsql/config.m4
diff -u php-src/ext/pdo_pgsql/config.m4:1.21 
php-src/ext/pdo_pgsql/config.m4:1.22
--- php-src/ext/pdo_pgsql/config.m4:1.21        Sat Mar 28 02:34:02 2009
+++ php-src/ext/pdo_pgsql/config.m4     Thu Apr 30 12:35:36 2009
@@ -1,4 +1,4 @@
-dnl $Id: config.m4,v 1.21 2009/03/28 02:34:02 mbeccati Exp $
+dnl $Id: config.m4,v 1.22 2009/04/30 12:35:36 mbeccati Exp $
 dnl config.m4 for extension pdo_pgsql
 dnl vim:et:sw=2:ts=2:
 
@@ -82,23 +82,18 @@
 
   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
http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_pgsql/config.w32?r1=1.10&r2=1.11&diff_format=u
Index: php-src/ext/pdo_pgsql/config.w32
diff -u php-src/ext/pdo_pgsql/config.w32:1.10 
php-src/ext/pdo_pgsql/config.w32:1.11
--- php-src/ext/pdo_pgsql/config.w32:1.10       Wed Apr  1 16:16:20 2009
+++ php-src/ext/pdo_pgsql/config.w32    Thu Apr 30 12:35:36 2009
@@ -1,4 +1,4 @@
-// $Id: config.w32,v 1.10 2009/04/01 16:16:20 pajoye Exp $
+// $Id: config.w32,v 1.11 2009/04/30 12:35:36 mbeccati Exp $
 // vim:ft=javascript
 
 ARG_WITH("pdo-pgsql", "PostgreSQL support for PDO", "no");
@@ -12,8 +12,11 @@
                        ADD_FLAG('CFLAGS_PDO_PGSQL', "/D HAVE_PG_CONFIG_H");
                }
 
-               AC_DEFINE('HAVE_PQPREPARE', 1, 'Have PqPrepare');
-               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_PQEXECPARAMS',          1, 'Have PQexecParams');
+               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 {
http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_pgsql/pgsql_driver.c?r1=1.73&r2=1.74&diff_format=u
Index: php-src/ext/pdo_pgsql/pgsql_driver.c
diff -u php-src/ext/pdo_pgsql/pgsql_driver.c:1.73 
php-src/ext/pdo_pgsql/pgsql_driver.c:1.74
--- php-src/ext/pdo_pgsql/pgsql_driver.c:1.73   Wed Apr  1 16:14:50 2009
+++ php-src/ext/pdo_pgsql/pgsql_driver.c        Thu Apr 30 12:35:36 2009
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: pgsql_driver.c,v 1.73 2009/04/01 16:14:50 pajoye Exp $ */
+/* $Id: pgsql_driver.c,v 1.74 2009/04/30 12:35:36 mbeccati Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -232,7 +232,7 @@
                if (S->cursor_name) {
                        efree(S->cursor_name);
                }
-               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
@@ -264,7 +264,7 @@
                        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) {
@@ -300,9 +300,7 @@
                return -1;
        }
        H->pgoid = PQoidValue(res);
-#if HAVE_PQCMDTUPLES
        ret = atol(PQcmdTuples(res));
-#endif
        PQclear(res);
 
        return ret;
@@ -312,16 +310,17 @@
 {
        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] = '\'';
@@ -402,11 +401,9 @@
                        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) {
@@ -456,7 +453,6 @@
                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,
@@ -464,9 +460,6 @@
                                (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;
http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_pgsql/pgsql_statement.c?r1=1.53&r2=1.54&diff_format=u
Index: php-src/ext/pdo_pgsql/pgsql_statement.c
diff -u php-src/ext/pdo_pgsql/pgsql_statement.c:1.53 
php-src/ext/pdo_pgsql/pgsql_statement.c:1.54
--- php-src/ext/pdo_pgsql/pgsql_statement.c:1.53        Thu Apr 23 13:22:12 2009
+++ php-src/ext/pdo_pgsql/pgsql_statement.c     Thu Apr 30 12:35:36 2009
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: pgsql_statement.c,v 1.53 2009/04/23 13:22:12 mbeccati Exp $ */
+/* $Id: pgsql_statement.c,v 1.54 2009/04/30 12:35:36 mbeccati Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -175,7 +175,7 @@
                                         * 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);
@@ -467,110 +467,6 @@
        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;
@@ -618,12 +514,20 @@
                                        *len = 0;
                                        return 0;
                                } else {
-                                       *ptr = 
php_pdo_pgsql_unescape_bytea(*ptr, &tmp_len);
+                                       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;
                                        }
http://cvs.php.net/viewvc.cgi/php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h?r1=1.19&r2=1.20&diff_format=u
Index: php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h
diff -u php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h:1.19 
php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h:1.20
--- php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h:1.19      Sat Mar 28 02:34:02 2009
+++ php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h   Thu Apr 30 12:35:36 2009
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_pdo_pgsql_int.h,v 1.19 2009/03/28 02:34:02 mbeccati Exp $ */
+/* $Id: php_pdo_pgsql_int.h,v 1.20 2009/04/30 12:35:36 mbeccati Exp $ */
 
 #ifndef PHP_PDO_PGSQL_INT_H
 #define PHP_PDO_PGSQL_INT_H
@@ -81,11 +81,7 @@
 
 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,

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to