summaryrefslogtreecommitdiff
path: root/ext/pgsql
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2006-10-04 23:27:17 +0000
committerIlia Alshanetsky <iliaa@php.net>2006-10-04 23:27:17 +0000
commitdbc2dc9dcf3bdc8237137d4ec8f2f299422ec8d1 (patch)
treeecb72062e1eb17f802b52d49d7a3c5320f27f4ec /ext/pgsql
parent4492d8f089d3db2d53cd91fa632ce94e6b697002 (diff)
downloadphp-git-dbc2dc9dcf3bdc8237137d4ec8f2f299422ec8d1.tar.gz
MFB: Added support for character sets in pg_escape_string() for PostgreSQL
8.1.4 and higher.
Diffstat (limited to 'ext/pgsql')
-rw-r--r--ext/pgsql/config.m41
-rw-r--r--ext/pgsql/pgsql.c28
2 files changed, 23 insertions, 6 deletions
diff --git a/ext/pgsql/config.m4 b/ext/pgsql/config.m4
index 4ec031693b..38dd3813d4 100644
--- a/ext/pgsql/config.m4
+++ b/ext/pgsql/config.m4
@@ -91,6 +91,7 @@ if test "$PHP_PGSQL" != "no"; then
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, 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
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index c7f53f2c4e..a057cb999f 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -3534,20 +3534,36 @@ PHP_FUNCTION(pg_copy_from)
/* }}} */
#ifdef HAVE_PQESCAPE
-/* {{{ proto string pg_escape_string(string data)
+/* {{{ proto string pg_escape_string([resource connection,] string data)
Escape string for text/char type */
PHP_FUNCTION(pg_escape_string)
{
char *from = NULL, *to = NULL;
+ zval *pgsql_link;
+ PGconn *pgsql;
int to_len;
int from_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
- &from, &from_len) == FAILURE) {
- return;
+ int id;
+
+ if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "rs", &pgsql_link, &from, &from_len) == SUCCESS) {
+ id = -1;
+ } else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &from, &from_len) == SUCCESS) {
+ pgsql_link = NULL;
+ id = PGG(default_link);
+ } else {
+ WRONG_PARAM_COUNT;
}
- to = (char *)safe_emalloc(from_len, 2, 1);
- to_len = (int)PQescapeString(to, from, from_len);
+ to = (char *) safe_emalloc(from_len, 2, 1);
+
+#ifdef HAVE_PQESCAPE_CONN
+ if (pgsql_link != NULL || id != -1) {
+ ZEND_FETCH_RESOURCE2(pgsql, PGconn *, &pgsql_link, id, "PostgreSQL link", le_link, le_plink);
+ to_len = (int) PQescapeStringConn(pgsql, to, from, (size_t)from_len, NULL);
+ } else
+#endif
+ to_len = (int) PQescapeString(to, from, (size_t)from_len);
+
RETURN_STRINGL(to, to_len, 0);
}
/* }}} */