iliaa Fri Oct 6 21:45:10 2006 UTC
Modified files: (Branch: PHP_5_2)
/php-src/ext/pgsql config.m4 pgsql.c
Log:
Make pg_escape_bytea() use PQescapeByteaConn() whenever possible.
http://cvs.php.net/viewvc.cgi/php-src/ext/pgsql/config.m4?r1=1.46.2.1.2.2&r2=1.46.2.1.2.3&diff_format=u
Index: php-src/ext/pgsql/config.m4
diff -u php-src/ext/pgsql/config.m4:1.46.2.1.2.2
php-src/ext/pgsql/config.m4:1.46.2.1.2.3
--- php-src/ext/pgsql/config.m4:1.46.2.1.2.2 Wed Oct 4 23:27:03 2006
+++ php-src/ext/pgsql/config.m4 Fri Oct 6 21:45:10 2006
@@ -1,5 +1,5 @@
dnl
-dnl $Id: config.m4,v 1.46.2.1.2.2 2006/10/04 23:27:03 iliaa Exp $
+dnl $Id: config.m4,v 1.46.2.1.2.3 2006/10/06 21:45:10 iliaa Exp $
dnl
AC_DEFUN([PHP_PGSQL_CHECK_FUNCTIONS],[
@@ -91,7 +91,8 @@
AC_CHECK_LIB(pq, PQgetCopyData,AC_DEFINE(HAVE_PQGETCOPYDATA,1,[PostgreSQL
7.4 or later]))
AC_CHECK_LIB(pq,
PQsetErrorVerbosity,AC_DEFINE(HAVE_PQSETERRORVERBOSITY,1,[PostgreSQL 7.4 or
later]))
AC_CHECK_LIB(pq, PQftable,AC_DEFINE(HAVE_PQFTABLE,1,[PostgreSQL 7.4 or
later]))
- AC_CHECK_LIB(pq, PQescapeStringConn,
AC_DEFINE(HAVE_PQESCAPE_CONN,1,[PostgreSQL 8.1 or later]))
+ AC_CHECK_LIB(pq, PQescapeStringConn,
AC_DEFINE(HAVE_PQESCAPE_CONN,1,[PostgreSQL 8.1.4 or later]))
+ AC_CHECK_LIB(pq, PQescapeByteaConn,
AC_DEFINE(HAVE_PQESCAPE_BYTEA_CONN,1,[PostgreSQL 8.1.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/viewvc.cgi/php-src/ext/pgsql/pgsql.c?r1=1.331.2.13.2.8&r2=1.331.2.13.2.9&diff_format=u
Index: php-src/ext/pgsql/pgsql.c
diff -u php-src/ext/pgsql/pgsql.c:1.331.2.13.2.8
php-src/ext/pgsql/pgsql.c:1.331.2.13.2.9
--- php-src/ext/pgsql/pgsql.c:1.331.2.13.2.8 Thu Oct 5 16:02:29 2006
+++ php-src/ext/pgsql/pgsql.c Fri Oct 6 21:45:10 2006
@@ -20,7 +20,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: pgsql.c,v 1.331.2.13.2.8 2006/10/05 16:02:29 bjori Exp $ */
+/* $Id: pgsql.c,v 1.331.2.13.2.9 2006/10/06 21:45:10 iliaa Exp $ */
#include <stdlib.h>
@@ -3581,19 +3581,33 @@
}
/* }}} */
-/* {{{ proto string pg_escape_bytea(string data)
+/* {{{ proto string pg_escape_bytea([resource connection,] string data)
Escape binary for bytea type */
PHP_FUNCTION(pg_escape_bytea)
{
char *from = NULL, *to = NULL;
size_t to_len;
- int from_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
- &from, &from_len) ==
FAILURE) {
+ int from_len, id = -1;
+#ifdef HAVE_PQESCAPE_BYTEA_CONN
+ PGconn *pgsql;
+#endif
+ zval *pgsql_link;
+
+ if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS()
TSRMLS_CC, "s", &from, &from_len) == SUCCESS) {
+ pgsql_link = NULL;
+ id = PGG(default_link);
+ } else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs",
&pgsql_link, &from, &from_len) == FAILURE) {
return;
}
- to = (char *)PQescapeBytea((unsigned char*)from, from_len, &to_len);
+#ifdef HAVE_PQESCAPE_BYTEA_CONN
+ if (pgsql_link != NULL || id != -1) {
+ ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id,
"PostgreSQL link", le_link, le_plink);
+ to = (char *)PQescapeByteaConn(pgsql, from, (size_t)from_len,
&to_len);
+ } else
+#endif
+ to = (char *)PQescapeBytea((unsigned char*)from, from_len,
&to_len);
+
RETVAL_STRINGL(to, to_len-1, 1); /* to_len includes addtional '\0' */
free(to);
}
@@ -5129,7 +5143,11 @@
else {
unsigned char *tmp;
size_t to_len;
+#ifdef HAVE_PQESCAPE_BYTEA_CONN
+ tmp =
PQescapeByteaConn(pg_link, Z_STRVAL_PP(val), Z_STRLEN_PP(val), &to_len);
+#else
tmp =
PQescapeBytea(Z_STRVAL_PP(val), Z_STRLEN_PP(val), &to_len);
+#endif
Z_TYPE_P(new_val) =
IS_STRING;
Z_STRLEN_P(new_val) =
to_len-1; /* PQescapeBytea's to_len includes additional '\0' */
Z_STRVAL_P(new_val) =
emalloc(to_len);
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php