chriskl         Fri Mar 25 01:26:31 2005 EDT

  Modified files:              
    /php-src    NEWS 
    /php-src/ext/pgsql  config.m4 config.w32 pgsql.c 
    /php-src/ext/pgsql/tests    08escape.phpt 25async_query_params.phpt 
  Log:
  (PHP pg_unescape_bytea) Use libpq version of PQunescapeBytea if it exists.
  
  # The version in libpq is newer and faster than the one in PHP, but it is
  # necessary for me to add a string copy for freeing purposes.  This copy
  # is only needed in Windows AFAIK, how can I detect that?
  
  
http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1858&r2=1.1859&ty=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.1858 php-src/NEWS:1.1859
--- php-src/NEWS:1.1858 Tue Mar 22 19:37:34 2005
+++ php-src/NEWS        Fri Mar 25 01:26:30 2005
@@ -1,6 +1,8 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2004, PHP 5.1.0
+- Changed pg_unescape_bytea() to use the libpq version of PQunescapeBytea if
+  it is available.
 - Moved extensions to PECL:
   . ext/cpdf        (Tony, Derick)
   . ext/dio         (Jani, Derick)
http://cvs.php.net/diff.php/php-src/ext/pgsql/config.m4?r1=1.41&r2=1.42&ty=u
Index: php-src/ext/pgsql/config.m4
diff -u php-src/ext/pgsql/config.m4:1.41 php-src/ext/pgsql/config.m4:1.42
--- php-src/ext/pgsql/config.m4:1.41    Tue Mar 22 03:51:21 2005
+++ php-src/ext/pgsql/config.m4 Fri Mar 25 01:26:30 2005
@@ -1,5 +1,5 @@
 dnl
-dnl $Id: config.m4,v 1.41 2005/03/22 08:51:21 chriskl Exp $
+dnl $Id: config.m4,v 1.42 2005/03/25 06:26:30 chriskl Exp $
 dnl
 
 AC_DEFUN([PHP_PGSQL_CHECK_FUNCTIONS],[
@@ -69,6 +69,7 @@
   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, 
PQunescapeBytea,AC_DEFINE(HAVE_PQUNESCAPEBYTEA,1,[PostgreSQL 7.3.0 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]))
http://cvs.php.net/diff.php/php-src/ext/pgsql/config.w32?r1=1.5&r2=1.6&ty=u
Index: php-src/ext/pgsql/config.w32
diff -u php-src/ext/pgsql/config.w32:1.5 php-src/ext/pgsql/config.w32:1.6
--- php-src/ext/pgsql/config.w32:1.5    Tue Mar 22 03:51:21 2005
+++ php-src/ext/pgsql/config.w32        Fri Mar 25 01:26:30 2005
@@ -1,4 +1,4 @@
-// $Id: config.w32,v 1.5 2005/03/22 08:51:21 chriskl Exp $
+// $Id: config.w32,v 1.6 2005/03/25 06:26:30 chriskl Exp $
 // vim:ft=javascript
 
 ARG_WITH("pgsql", "PostgreSQL support", "no");
@@ -8,7 +8,7 @@
                CHECK_HEADER_ADD_INCLUDE("libpq-fe.h", "CFLAGS_PGSQL", 
PHP_PHP_BUILD + "\\include\\pgsql;" + PHP_PGSQL)) {
                EXTENSION("pgsql", "pgsql.c");
                AC_DEFINE('HAVE_PGSQL', 1, 'Have PostgreSQL library');
-               ADD_FLAG("CFLAGS_PGSQL", "/D HAVE_PG_CONFIG_H /D PGSQL_EXPORTS 
/D HAVE_PQSETNONBLOCKING /D HAVE_PQCMDTUPLES /D HAVE_PQCLIENTENCODING /D 
HAVE_PQESCAPE /D HAVE_PQPARAMETERSTATUS /D HAVE_PGTRANSACTIONSTATUS /D 
HAVE_PQEXECPARAMS /D HAVE_PQPREPARE /D HAVE_PQEXECPREPARED /D 
HAVE_PQRESULTERRORFIELD /D HAVE_PQSENDQUERYPARAMS /D HAVE_PQSENDPREPARE /D 
HAVE_PQSENDQUERYPREPARED /D HAVE_PQPUTCOPYDATA /D HAVE_PQPUTCOPYEND /D 
HAVE_PQGETCOPYDATA /D HAVE_PQSETERRORVERBOSITY");
+               ADD_FLAG("CFLAGS_PGSQL", "/D HAVE_PG_CONFIG_H /D PGSQL_EXPORTS 
/D HAVE_PQSETNONBLOCKING /D HAVE_PQCMDTUPLES /D HAVE_PQCLIENTENCODING /D 
HAVE_PQESCAPE /D HAVE_PQPARAMETERSTATUS /D HAVE_PGTRANSACTIONSTATUS /D 
HAVE_PQEXECPARAMS /D HAVE_PQPREPARE /D HAVE_PQEXECPREPARED /D 
HAVE_PQRESULTERRORFIELD /D HAVE_PQSENDQUERYPARAMS /D HAVE_PQSENDPREPARE /D 
HAVE_PQSENDQUERYPREPARED /D HAVE_PQPUTCOPYDATA /D HAVE_PQPUTCOPYEND /D 
HAVE_PQGETCOPYDATA /D HAVE_PQSETERRORVERBOSITY /D HAVE_PQUNESCAPEBYTEA");
        } else {
                WARNING("pgsql not enabled; libraries and headers not found");
        }
http://cvs.php.net/diff.php/php-src/ext/pgsql/pgsql.c?r1=1.321&r2=1.322&ty=u
Index: php-src/ext/pgsql/pgsql.c
diff -u php-src/ext/pgsql/pgsql.c:1.321 php-src/ext/pgsql/pgsql.c:1.322
--- php-src/ext/pgsql/pgsql.c:1.321     Thu Mar 24 19:30:43 2005
+++ php-src/ext/pgsql/pgsql.c   Fri Mar 25 01:26:30 2005
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
  */
  
-/* $Id: pgsql.c,v 1.321 2005/03/25 00:30:43 iliaa Exp $ */
+/* $Id: pgsql.c,v 1.322 2005/03/25 06:26:30 chriskl Exp $ */
 
 #include <stdlib.h>
 
@@ -3414,6 +3414,7 @@
 }
 /* }}} */
 
+#if !HAVE_PQUNESCAPEBYTEA
 /* PQunescapeBytea() from PostgreSQL 7.3 to provide bytea unescape feature to 
7.2 users.
    Renamed to php_pgsql_unescape_bytea() */
 /*
@@ -3517,12 +3518,13 @@
        *retbuflen = buflen;
        return buffer;
 }
+#endif
 
 /* {{{ proto string pg_unescape_bytea(string data)
    Unescape binary for bytea type  */
 PHP_FUNCTION(pg_unescape_bytea)
 {
-       char *from = NULL, *to = NULL;
+       char *from = NULL, *to = NULL, *tmp = NULL;
        size_t to_len;
        int from_len;
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
@@ -3530,7 +3532,13 @@
                return;
        }
 
+#if HAVE_PQUNESCAPEBYTEA
+       tmp = (char *)PQunescapeBytea((unsigned char*)from, &to_len);
+       to = estrndup(tmp, to_len);
+       PQfreemem(tmp);
+#else
        to = (char *)php_pgsql_unescape_bytea((unsigned char*)from, &to_len);
+#endif
        if (!to) {
                RETURN_FALSE;
        }
http://cvs.php.net/diff.php/php-src/ext/pgsql/tests/08escape.phpt?r1=1.6&r2=1.7&ty=u
Index: php-src/ext/pgsql/tests/08escape.phpt
diff -u php-src/ext/pgsql/tests/08escape.phpt:1.6 
php-src/ext/pgsql/tests/08escape.phpt:1.7
--- php-src/ext/pgsql/tests/08escape.phpt:1.6   Wed Aug 27 20:29:44 2003
+++ php-src/ext/pgsql/tests/08escape.phpt       Fri Mar 25 01:26:31 2005
@@ -51,14 +51,12 @@
 $result = pg_query($db, $sql);
 $row = pg_fetch_array($result, 0, PGSQL_ASSOC);
 
-// Compare
-// Need to wait PostgreSQL 7.3.x for PQunescapeBytea()
-// if ($data === pg_unescape_bytea($row['bin'])) {
-//     echo "pg_escape_bytea() actually works with databse\n";
-// }
-// else {
-//     echo "pg_escape_bytea() is broken\n";
-// }
+if ($data === pg_unescape_bytea($row['bin'])) {
+       echo "pg_escape_bytea() actually works with database\n";
+}
+else {
+       echo "pg_escape_bytea() is broken\n";
+}
 
 ?>
 --EXPECT--
@@ -67,3 +65,4 @@
 string(12) "ABC\\ABC\\''"
 string(10) "ABC\\ABC\'"
 pg_escape_bytea() is Ok
+pg_escape_bytea() actually works with database
http://cvs.php.net/diff.php/php-src/ext/pgsql/tests/25async_query_params.phpt?r1=1.2&r2=1.3&ty=u
Index: php-src/ext/pgsql/tests/25async_query_params.phpt
diff -u php-src/ext/pgsql/tests/25async_query_params.phpt:1.2 
php-src/ext/pgsql/tests/25async_query_params.phpt:1.3
--- php-src/ext/pgsql/tests/25async_query_params.phpt:1.2       Tue Mar 22 
22:24:41 2005
+++ php-src/ext/pgsql/tests/25async_query_params.phpt   Fri Mar 25 01:26:31 2005
@@ -62,7 +62,7 @@
        pg_last_oid($result);
        pg_free_result($result);
 }
-pg_close($db)
+pg_close($db);
 
 echo "OK";
 ?>

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

Reply via email to