wez             Fri May 13 14:09:04 2005 EDT

  Modified files:              
    /php-src/ext/pdo_pgsql      config.m4 pgsql_driver.c pgsql_statement.c 
                                php_pdo_pgsql_int.h 
  Log:
  patch by Christopher Kings-Lynne, slightly modified
  
http://cvs.php.net/diff.php/php-src/ext/pdo_pgsql/config.m4?r1=1.7&r2=1.8&ty=u
Index: php-src/ext/pdo_pgsql/config.m4
diff -u php-src/ext/pdo_pgsql/config.m4:1.7 php-src/ext/pdo_pgsql/config.m4:1.8
--- php-src/ext/pdo_pgsql/config.m4:1.7 Mon Feb 28 03:18:47 2005
+++ php-src/ext/pdo_pgsql/config.m4     Fri May 13 14:09:03 2005
@@ -1,5 +1,5 @@
 dnl
-dnl $Id: config.m4,v 1.7 2005/02/28 08:18:47 rasmus Exp $
+dnl $Id: config.m4,v 1.8 2005/05/13 18:09:03 wez Exp $
 dnl
 
 if test "$PHP_PDO" != "no"; then
@@ -90,6 +90,8 @@
   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, 
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
   LDFLAGS=$old_LDFLAGS
http://cvs.php.net/diff.php/php-src/ext/pdo_pgsql/pgsql_driver.c?r1=1.37&r2=1.38&ty=u
Index: php-src/ext/pdo_pgsql/pgsql_driver.c
diff -u php-src/ext/pdo_pgsql/pgsql_driver.c:1.37 
php-src/ext/pdo_pgsql/pgsql_driver.c:1.38
--- php-src/ext/pdo_pgsql/pgsql_driver.c:1.37   Sat Feb 26 12:27:51 2005
+++ php-src/ext/pdo_pgsql/pgsql_driver.c        Fri May 13 14:09:03 2005
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: pgsql_driver.c,v 1.37 2005/02/26 17:27:51 wez Exp $ */
+/* $Id: pgsql_driver.c,v 1.38 2005/05/13 18:09:03 wez Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -52,7 +52,7 @@
        return tmp;
 }
 
-int _pdo_pgsql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, int errcode, const char 
*file, int line TSRMLS_DC) /* {{{ */
+int _pdo_pgsql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, int errcode, const char 
*sqlstate, const char *file, int line TSRMLS_DC) /* {{{ */
 {
        pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
        pdo_error_type *pdo_err = stmt ? &stmt->error_code : &dbh->error_code;
@@ -68,10 +68,11 @@
                einfo->errmsg = NULL;
        }
 
-       switch (errcode) {
-               default:
-                       strcpy(*pdo_err, "HY000");
-                       break;
+       if (sqlstate == NULL) {
+               strcpy(*pdo_err, "HY000");
+       }
+       else {
+               strcpy(*pdo_err, sqlstate);
        }
 
        if (errmsg) {
@@ -154,12 +155,18 @@
        
        if (!(res = PQexec(H->server, sql))) {
                /* fatal error */
-               pdo_pgsql_error(dbh, PGRES_FATAL_ERROR);
+               pdo_pgsql_error(dbh, PGRES_FATAL_ERROR, NULL);
                return 0;
        } else {
                ExecStatusType qs = PQresultStatus(res);
                if (qs != PGRES_COMMAND_OK && qs != PGRES_TUPLES_OK) {
-                       pdo_pgsql_error(dbh, qs);
+#if HAVE_PQRESULTERRORFIELD
+                       char * sqlstate = PQresultErrorField(res, 
PG_DIAG_SQLSTATE);
+                       pdo_pgsql_error(dbh, qs, (const char *)sqlstate);
+                       PQfreemem(sqlstate);
+#else
+                       pdo_pgsql_error(dbh, qs, NULL);
+#endif
                        PQclear(res);
                        return 0;
                }
@@ -384,7 +391,7 @@
        }
        
        if (PQstatus(H->server) != CONNECTION_OK) {
-               pdo_pgsql_error(dbh, PGRES_FATAL_ERROR);
+               pdo_pgsql_error(dbh, PGRES_FATAL_ERROR, 
PHP_PDO_PGSQL_CONNECTION_FAILURE_SQLSTATE);
                goto cleanup;
        }
 
http://cvs.php.net/diff.php/php-src/ext/pdo_pgsql/pgsql_statement.c?r1=1.20&r2=1.21&ty=u
Index: php-src/ext/pdo_pgsql/pgsql_statement.c
diff -u php-src/ext/pdo_pgsql/pgsql_statement.c:1.20 
php-src/ext/pdo_pgsql/pgsql_statement.c:1.21
--- php-src/ext/pdo_pgsql/pgsql_statement.c:1.20        Wed Mar 23 03:52:40 2005
+++ php-src/ext/pdo_pgsql/pgsql_statement.c     Fri May 13 14:09:03 2005
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: pgsql_statement.c,v 1.20 2005/03/23 08:52:40 chriskl Exp $ */
+/* $Id: pgsql_statement.c,v 1.21 2005/05/13 18:09:03 wez Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -97,7 +97,13 @@
        status = PQresultStatus(S->result);
 
        if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) {
-               pdo_pgsql_error_stmt(stmt, status);
+#if HAVE_PQRESULTERRORFIELD
+               char * sqlstate = PQresultErrorField(S->result, 
PG_DIAG_SQLSTATE);
+               pdo_pgsql_error_stmt(stmt, status, (const char *)sqlstate);
+#else
+               pdo_pgsql_error_stmt(stmt, status, NULL);
+#endif
+
                return 0;
        }
 
@@ -145,7 +151,12 @@
                status = PQresultStatus(S->result);
 
                if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) {
-                       pdo_pgsql_error_stmt(stmt, status);
+#if HAVE_PQRESULTERRORFIELD
+                       char * sqlstate = PQresultErrorField(S->result, 
PG_DIAG_SQLSTATE);
+                       pdo_pgsql_error_stmt(stmt, status, (const char 
*)sqlstate);
+#else
+                       pdo_pgsql_error_stmt(stmt, status, NULL);
+#endif
                        return 0;
                }
 
@@ -209,7 +220,7 @@
 }
 
 /* PQunescapeBytea() from PostgreSQL 7.3 to provide bytea unescape feature to 
7.2 users.
-   Renamed to php_pgsql_unescape_bytea() */
+   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
@@ -231,7 +242,7 @@
  *             5       \'
  *             6       \\
  */
-static unsigned char * php_pgsql_unescape_bytea(unsigned char *strtext, size_t 
*retbuflen)
+static unsigned char *php_pdo_pgsql_unescape_bytea(unsigned char *strtext, 
size_t *retbuflen)
 {
        size_t          buflen;
        unsigned char *buffer,
@@ -346,11 +357,14 @@
                                break;
                                
                        case PDO_PARAM_LOB:
-                               tmp_ptr = php_pgsql_unescape_bytea(*ptr, 
&tmp_len);
-                               *ptr = estrndup(tmp_ptr, tmp_len);
+                               *ptr = php_pdo_pgsql_unescape_bytea(*ptr, 
&tmp_len);
                                *len = tmp_len;
                                *caller_frees = 1;
-                               free(tmp_ptr);
+                               break;
+                       case PDO_PARAM_NULL:
+                       case PDO_PARAM_STR:
+                       case PDO_PARAM_STMT:
+                       case PDO_PARAM_INPUT_OUTPUT:
                                break;
                }
        }
http://cvs.php.net/diff.php/php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h?r1=1.8&r2=1.9&ty=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.8 
php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h:1.9
--- php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h:1.8       Sat Feb 12 20:02:18 2005
+++ php-src/ext/pdo_pgsql/php_pdo_pgsql_int.h   Fri May 13 14:09:03 2005
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_pdo_pgsql_int.h,v 1.8 2005/02/13 01:02:18 edink Exp $ */
+/* $Id: php_pdo_pgsql_int.h,v 1.9 2005/05/13 18:09:03 wez Exp $ */
 
 #ifndef PHP_PDO_PGSQL_INT_H
 #define PHP_PDO_PGSQL_INT_H
@@ -25,6 +25,8 @@
 
 #include <libpq-fe.h>
 
+#define PHP_PDO_PGSQL_CONNECTION_FAILURE_SQLSTATE "08006"
+
 typedef struct {
        const char *file;
        int line;
@@ -65,9 +67,9 @@
 
 extern pdo_driver_t pdo_pgsql_driver;
 
-extern int _pdo_pgsql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, int errcode, 
const char *file, int line TSRMLS_DC);
-#define pdo_pgsql_error(d,e)   _pdo_pgsql_error(d, NULL, e, __FILE__, __LINE__ 
TSRMLS_CC)
-#define pdo_pgsql_error_stmt(s,e)      _pdo_pgsql_error(s->dbh, s, e, 
__FILE__, __LINE__ TSRMLS_CC)
+extern int _pdo_pgsql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, int errcode, 
const char *sqlstate, const char *file, int line TSRMLS_DC);
+#define pdo_pgsql_error(d,e,z) _pdo_pgsql_error(d, NULL, e, z, __FILE__, 
__LINE__ TSRMLS_CC)
+#define pdo_pgsql_error_stmt(s,e,z)    _pdo_pgsql_error(s->dbh, s, e, z, 
__FILE__, __LINE__ TSRMLS_CC)
 
 extern struct pdo_stmt_methods pgsql_stmt_methods;
 

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

Reply via email to