summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorChristopher Kings-Lynne <chriskl@php.net>2005-03-25 06:26:31 (GMT)
committerChristopher Kings-Lynne <chriskl@php.net>2005-03-25 06:26:31 (GMT)
commit030ebaaa458f534871fe62a20fcea7e8ee1d5a57 (patch)
tree335b349faeb4013067f3f12ccd6c98b6d9ac2ae8 /ext
parent8817f64457abbe28d03b37503dd03c83535430c5 (diff)
downloadphp-030ebaaa458f534871fe62a20fcea7e8ee1d5a57.tar.gz
(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?
Diffstat (limited to 'ext')
-rw-r--r--ext/pgsql/config.m41
-rw-r--r--ext/pgsql/config.w322
-rw-r--r--ext/pgsql/pgsql.c10
-rw-r--r--ext/pgsql/tests/08escape.phpt15
-rw-r--r--ext/pgsql/tests/25async_query_params.phpt2
5 files changed, 19 insertions, 11 deletions
diff --git a/ext/pgsql/config.m4 b/ext/pgsql/config.m4
index da9badb..1da8115 100644
--- a/ext/pgsql/config.m4
+++ b/ext/pgsql/config.m4
@@ -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]))
diff --git a/ext/pgsql/config.w32 b/ext/pgsql/config.w32
index 835883e..8f4b8a9 100644
--- a/ext/pgsql/config.w32
+++ b/ext/pgsql/config.w32
@@ -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");
}
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index f90f8fa..37402cd 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -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;
}
diff --git a/ext/pgsql/tests/08escape.phpt b/ext/pgsql/tests/08escape.phpt
index c5a3877..cf23b50 100644
--- a/ext/pgsql/tests/08escape.phpt
+++ b/ext/pgsql/tests/08escape.phpt
@@ -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
diff --git a/ext/pgsql/tests/25async_query_params.phpt b/ext/pgsql/tests/25async_query_params.phpt
index 3244532..6e7dafe 100644
--- a/ext/pgsql/tests/25async_query_params.phpt
+++ b/ext/pgsql/tests/25async_query_params.phpt
@@ -62,7 +62,7 @@ if ($version['protocol'] >= 3) {
pg_last_oid($result);
pg_free_result($result);
}
-pg_close($db)
+pg_close($db);
echo "OK";
?>