summaryrefslogtreecommitdiff
path: root/ext/pgsql
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2013-09-27 11:27:58 +0200
committerOndřej Surý <ondrej@sury.org>2013-09-27 11:27:58 +0200
commit1fd24dd3e14010b82febd3e300599f8d8f9c592c (patch)
tree60d089e947831184a569c1db6c23e45e18d46723 /ext/pgsql
parent9989e8bb3d7b37e3b3b351feece5ed4346174ccf (diff)
downloadphp-1fd24dd3e14010b82febd3e300599f8d8f9c592c.tar.gz
New upstream version 5.5.4+dfsgupstream/5.5.4+dfsg
Diffstat (limited to 'ext/pgsql')
-rw-r--r--ext/pgsql/pgsql.c46
-rw-r--r--ext/pgsql/tests/09notice.phpt5
-rw-r--r--ext/pgsql/tests/80_bug32223.phpt6
-rw-r--r--ext/pgsql/tests/80_bug32223b.phpt6
4 files changed, 44 insertions, 19 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index f0e1780a7..35eb09e58 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -63,6 +63,7 @@
#define PGSQL_MAX_LENGTH_OF_LONG 30
#define PGSQL_MAX_LENGTH_OF_DOUBLE 60
+#if LONG_MAX < UINT_MAX
#define PGSQL_RETURN_OID(oid) do { \
if (oid > LONG_MAX) { \
smart_str s = {0}; \
@@ -72,7 +73,9 @@
} \
RETURN_LONG((long)oid); \
} while(0)
-
+#else
+#define PGSQL_RETURN_OID(oid) (RETURN_LONG((long)oid))
+#endif
#if HAVE_PQSETNONBLOCKING
#define PQ_SETNONBLOCKING(pg_link, flag) PQsetnonblocking(pg_link, flag)
@@ -4152,7 +4155,7 @@ PHP_FUNCTION(pg_escape_bytea)
#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);
+ to = (char *)PQescapeByteaConn(pgsql, (unsigned char *)from, (size_t)from_len, &to_len);
} else
#endif
to = (char *)PQescapeBytea((unsigned char*)from, from_len, &to_len);
@@ -4347,7 +4350,7 @@ static char* php_pgsql_PQescapeInternal(PGconn *conn, const char *str, size_t le
#endif
static void php_pgsql_escape_internal(INTERNAL_FUNCTION_PARAMETERS, int escape_literal) {
- char *from = NULL, *to = NULL, *tmp = NULL;
+ char *from = NULL, *to = NULL;
zval *pgsql_link = NULL;
PGconn *pgsql;
int from_len;
@@ -4380,17 +4383,22 @@ static void php_pgsql_escape_internal(INTERNAL_FUNCTION_PARAMETERS, int escape_l
RETURN_FALSE;
}
#ifdef HAVE_PQESCAPELITERAL
- if (escape_literal) {
- tmp = PQescapeLiteral(pgsql, from, (size_t)from_len);
- } else {
- tmp = PQescapeIdentifier(pgsql, from, (size_t)from_len);
- }
- if (!tmp) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,"Failed to escape");
- RETURN_FALSE;
+ /* Use a block with a local var to avoid unused variable warnings */
+ {
+ char *tmp;
+
+ if (escape_literal) {
+ tmp = PQescapeLiteral(pgsql, from, (size_t)from_len);
+ } else {
+ tmp = PQescapeIdentifier(pgsql, from, (size_t)from_len);
+ }
+ if (!tmp) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING,"Failed to escape");
+ RETURN_FALSE;
+ }
+ to = estrdup(tmp);
+ PQfreemem(tmp);
}
- to = estrdup(tmp);
- PQfreemem(tmp);
#else
to = php_pgsql_PQescapeInternal(pgsql, from, (size_t)from_len, escape_literal);
if (!to) {
@@ -5121,7 +5129,9 @@ PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, z
#else
new_len = PQescapeString(escaped, tmp_name2, strlen(tmp_name2));
#endif
- smart_str_appends(&querystr, escaped);
+ if (new_len) {
+ smart_str_appends(&querystr, escaped);
+ }
efree(escaped);
smart_str_appends(&querystr, "' AND c.relnamespace = n.oid AND n.nspname = '");
@@ -5131,7 +5141,9 @@ PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, z
#else
new_len = PQescapeString(escaped, tmp_name, strlen(tmp_name));
#endif
- smart_str_appends(&querystr, escaped);
+ if (new_len) {
+ smart_str_appends(&querystr, escaped);
+ }
efree(escaped);
smart_str_appends(&querystr, "' AND a.atttypid = t.oid ORDER BY a.attnum;");
@@ -5924,9 +5936,9 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
size_t to_len;
smart_str s = {0};
#ifdef HAVE_PQESCAPE_BYTEA_CONN
- tmp = PQescapeByteaConn(pg_link, Z_STRVAL_PP(val), Z_STRLEN_PP(val), &to_len);
+ tmp = PQescapeByteaConn(pg_link, (unsigned char *)Z_STRVAL_PP(val), Z_STRLEN_PP(val), &to_len);
#else
- tmp = PQescapeBytea(Z_STRVAL_PP(val), Z_STRLEN_PP(val), &to_len);
+ tmp = PQescapeBytea(Z_STRVAL_PP(val), (unsigned char *)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' */
diff --git a/ext/pgsql/tests/09notice.phpt b/ext/pgsql/tests/09notice.phpt
index 67ef262fc..db671016e 100644
--- a/ext/pgsql/tests/09notice.phpt
+++ b/ext/pgsql/tests/09notice.phpt
@@ -20,6 +20,9 @@ $db = pg_connect($conn_str);
_set_lc_messages();
+$res = pg_query($db, 'SET client_min_messages TO NOTICE;');
+var_dump($res);
+
pg_query($db, "BEGIN;");
pg_query($db, "BEGIN;");
@@ -33,6 +36,8 @@ echo "pg_last_notice() is Ok\n";
?>
--EXPECTF--
+resource(%d) of type (pgsql result)
+
Notice: pg_query(): %s already a transaction in progress in %s on line %d
%s already a transaction in progress
pg_last_notice() is Ok
diff --git a/ext/pgsql/tests/80_bug32223.phpt b/ext/pgsql/tests/80_bug32223.phpt
index cad5fb3a1..b9bbbf86e 100644
--- a/ext/pgsql/tests/80_bug32223.phpt
+++ b/ext/pgsql/tests/80_bug32223.phpt
@@ -37,8 +37,10 @@ begin
end;
' LANGUAGE plpgsql;");
-
+$res = pg_query($dbh, 'SET client_min_messages TO NOTICE;');
+var_dump($res);
$res = pg_query($dbh, 'SELECT test_notice()');
+var_dump($res);
$row = pg_fetch_row($res, 0);
var_dump($row);
pg_free_result($res);
@@ -52,6 +54,8 @@ pg_close($dbh);
?>
===DONE===
--EXPECTF--
+resource(%d) of type (pgsql result)
+resource(%d) of type (pgsql result)
array(1) {
[0]=>
string(1) "f"
diff --git a/ext/pgsql/tests/80_bug32223b.phpt b/ext/pgsql/tests/80_bug32223b.phpt
index e79685c43..418ccfc9a 100644
--- a/ext/pgsql/tests/80_bug32223b.phpt
+++ b/ext/pgsql/tests/80_bug32223b.phpt
@@ -37,10 +37,13 @@ begin
end;
' LANGUAGE plpgsql;");
+$res = pg_query(dbh, 'SET client_min_messages TO NOTICE;');
+var_dump($res);
+
function tester() {
$res = pg_query(dbh, 'SELECT test_notice()');
$row = pg_fetch_row($res, 0);
- var_dump($row);
+ var_dump($row);
pg_free_result($res);
if ($row[0] == 'f')
{
@@ -54,6 +57,7 @@ pg_close(dbh);
?>
===DONE===
--EXPECTF--
+resource(%d) of type (pgsql result)
array(1) {
[0]=>
string(1) "f"