mirror of
https://github.com/php/php-src.git
synced 2025-08-16 14:08:47 +02:00
(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?
This commit is contained in:
parent
8817f64457
commit
030ebaaa45
6 changed files with 21 additions and 11 deletions
2
NEWS
2
NEWS
|
@ -1,6 +1,8 @@
|
||||||
PHP NEWS
|
PHP NEWS
|
||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||
?? ??? 2004, PHP 5.1.0
|
?? ??? 2004, PHP 5.1.0
|
||||||
|
- Changed pg_unescape_bytea() to use the libpq version of PQunescapeBytea if
|
||||||
|
it is available.
|
||||||
- Moved extensions to PECL:
|
- Moved extensions to PECL:
|
||||||
. ext/cpdf (Tony, Derick)
|
. ext/cpdf (Tony, Derick)
|
||||||
. ext/dio (Jani, Derick)
|
. ext/dio (Jani, Derick)
|
||||||
|
|
|
@ -69,6 +69,7 @@ if test "$PHP_PGSQL" != "no"; then
|
||||||
old_LDFLAGS=$LDFLAGS
|
old_LDFLAGS=$LDFLAGS
|
||||||
LDFLAGS="$LDFLAGS -L$PGSQL_LIBDIR"
|
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, 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, 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, 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, PQoidValue,AC_DEFINE(HAVE_PQOIDVALUE,1,[Older PostgreSQL]))
|
||||||
|
|
|
@ -8,7 +8,7 @@ if (PHP_PGSQL != "no") {
|
||||||
CHECK_HEADER_ADD_INCLUDE("libpq-fe.h", "CFLAGS_PGSQL", PHP_PHP_BUILD + "\\include\\pgsql;" + PHP_PGSQL)) {
|
CHECK_HEADER_ADD_INCLUDE("libpq-fe.h", "CFLAGS_PGSQL", PHP_PHP_BUILD + "\\include\\pgsql;" + PHP_PGSQL)) {
|
||||||
EXTENSION("pgsql", "pgsql.c");
|
EXTENSION("pgsql", "pgsql.c");
|
||||||
AC_DEFINE('HAVE_PGSQL', 1, 'Have PostgreSQL library');
|
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 {
|
} else {
|
||||||
WARNING("pgsql not enabled; libraries and headers not found");
|
WARNING("pgsql not enabled; libraries and headers not found");
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
/* PQunescapeBytea() from PostgreSQL 7.3 to provide bytea unescape feature to 7.2 users.
|
||||||
Renamed to php_pgsql_unescape_bytea() */
|
Renamed to php_pgsql_unescape_bytea() */
|
||||||
/*
|
/*
|
||||||
|
@ -3517,12 +3518,13 @@ static unsigned char * php_pgsql_unescape_bytea(unsigned char *strtext, size_t *
|
||||||
*retbuflen = buflen;
|
*retbuflen = buflen;
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* {{{ proto string pg_unescape_bytea(string data)
|
/* {{{ proto string pg_unescape_bytea(string data)
|
||||||
Unescape binary for bytea type */
|
Unescape binary for bytea type */
|
||||||
PHP_FUNCTION(pg_unescape_bytea)
|
PHP_FUNCTION(pg_unescape_bytea)
|
||||||
{
|
{
|
||||||
char *from = NULL, *to = NULL;
|
char *from = NULL, *to = NULL, *tmp = NULL;
|
||||||
size_t to_len;
|
size_t to_len;
|
||||||
int from_len;
|
int from_len;
|
||||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
|
||||||
|
@ -3530,7 +3532,13 @@ PHP_FUNCTION(pg_unescape_bytea)
|
||||||
return;
|
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);
|
to = (char *)php_pgsql_unescape_bytea((unsigned char*)from, &to_len);
|
||||||
|
#endif
|
||||||
if (!to) {
|
if (!to) {
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,14 +51,12 @@ $sql = "SELECT bin::bytea FROM ".$table_name." WHERE num = -9999";
|
||||||
$result = pg_query($db, $sql);
|
$result = pg_query($db, $sql);
|
||||||
$row = pg_fetch_array($result, 0, PGSQL_ASSOC);
|
$row = pg_fetch_array($result, 0, PGSQL_ASSOC);
|
||||||
|
|
||||||
// Compare
|
if ($data === pg_unescape_bytea($row['bin'])) {
|
||||||
// Need to wait PostgreSQL 7.3.x for PQunescapeBytea()
|
echo "pg_escape_bytea() actually works with database\n";
|
||||||
// if ($data === pg_unescape_bytea($row['bin'])) {
|
}
|
||||||
// echo "pg_escape_bytea() actually works with databse\n";
|
else {
|
||||||
// }
|
echo "pg_escape_bytea() is broken\n";
|
||||||
// else {
|
}
|
||||||
// echo "pg_escape_bytea() is broken\n";
|
|
||||||
// }
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
|
@ -67,3 +65,4 @@ string(9) "ABC\ABC\'"
|
||||||
string(12) "ABC\\ABC\\''"
|
string(12) "ABC\\ABC\\''"
|
||||||
string(10) "ABC\\ABC\'"
|
string(10) "ABC\\ABC\'"
|
||||||
pg_escape_bytea() is Ok
|
pg_escape_bytea() is Ok
|
||||||
|
pg_escape_bytea() actually works with database
|
||||||
|
|
|
@ -62,7 +62,7 @@ if ($version['protocol'] >= 3) {
|
||||||
pg_last_oid($result);
|
pg_last_oid($result);
|
||||||
pg_free_result($result);
|
pg_free_result($result);
|
||||||
}
|
}
|
||||||
pg_close($db)
|
pg_close($db);
|
||||||
|
|
||||||
echo "OK";
|
echo "OK";
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue