]> granicus.if.org Git - php/commitdiff
(PHP pg_unescape_bytea) Use libpq version of PQunescapeBytea if it exists.
authorChristopher Kings-Lynne <chriskl@php.net>
Fri, 25 Mar 2005 06:26:31 +0000 (06:26 +0000)
committerChristopher Kings-Lynne <chriskl@php.net>
Fri, 25 Mar 2005 06:26:31 +0000 (06:26 +0000)
# 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?

NEWS
ext/pgsql/config.m4
ext/pgsql/config.w32
ext/pgsql/pgsql.c
ext/pgsql/tests/08escape.phpt
ext/pgsql/tests/25async_query_params.phpt

diff --git a/NEWS b/NEWS
index d887f07e1c42d8e5325e76db99429f89895b538c..915931d89546d19d0ea76f48d8311fdadb38257c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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)
index da9badb80768a03d007b6f6ace4ad1e780e5a9b2..1da8115c9033642028d6702e66164f4707b3395d 100644 (file)
@@ -69,6 +69,7 @@ if test "$PHP_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, 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]))
index 835883e478f1b7b857b78a27d8f9ce14c329b77b..8f4b8a955b7c88357cd853b920a9ec1e3bf092df 100644 (file)
@@ -8,7 +8,7 @@ if (PHP_PGSQL != "no") {
                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");
        }
index f90f8fa66c6650f6086226fb6c1fcf3e00b67f91..37402cd06a19c4f1e4eb140baa815362dd4ffe6b 100644 (file)
@@ -3414,6 +3414,7 @@ PHP_FUNCTION(pg_escape_bytea)
 }
 /* }}} */
 
+#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 @@ static unsigned char * php_pgsql_unescape_bytea(unsigned char *strtext, size_t *
        *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 @@ PHP_FUNCTION(pg_unescape_bytea)
                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;
        }
index c5a3877e3726c10da86815b10aa759a988c98b3a..cf23b50e3a80f3da4305cc575bb7873fef0f0d00 100644 (file)
@@ -51,14 +51,12 @@ $sql = "SELECT bin::bytea FROM ".$table_name." WHERE num = -9999";
 $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(9) "ABC\ABC\'"
 string(12) "ABC\\ABC\\''"
 string(10) "ABC\\ABC\'"
 pg_escape_bytea() is Ok
+pg_escape_bytea() actually works with database
index 3244532094415ab00688cb48601bf11175985895..6e7dafe34b348691c0ebca9e37bd5413bc58cb0b 100644 (file)
@@ -62,7 +62,7 @@ if ($version['protocol'] >= 3) {
        pg_last_oid($result);
        pg_free_result($result);
 }
-pg_close($db)
+pg_close($db);
 
 echo "OK";
 ?>