summaryrefslogtreecommitdiff
path: root/ext/pgsql
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2010-03-09 11:57:54 +0100
committerOndřej Surý <ondrej@sury.org>2010-03-09 11:57:54 +0100
commit855a09f4eded707941180c9d90acd17c25e29447 (patch)
treea40947efaa9876f31b6ee3956c3f3775768143bb /ext/pgsql
parentc852c28a88fccf6e34a2cb091fdfa72bce2b59c7 (diff)
downloadphp-855a09f4eded707941180c9d90acd17c25e29447.tar.gz
Imported Upstream version 5.3.2upstream/5.3.2
Diffstat (limited to 'ext/pgsql')
-rw-r--r--ext/pgsql/pgsql.c28
-rw-r--r--ext/pgsql/php_pgsql.h4
-rw-r--r--ext/pgsql/tests/10pg_convert.phpt5
-rw-r--r--ext/pgsql/tests/10pg_convert_85.phpt29
-rw-r--r--ext/pgsql/tests/12pg_insert.phpt5
-rw-r--r--ext/pgsql/tests/12pg_insert_85.phpt24
-rw-r--r--ext/pgsql/tests/13pg_select.phpt5
-rw-r--r--ext/pgsql/tests/13pg_select_85.phpt37
-rw-r--r--ext/pgsql/tests/14pg_update.phpt5
-rw-r--r--ext/pgsql/tests/14pg_update_85.phpt25
-rw-r--r--ext/pgsql/tests/bug37100.phpt5
-rw-r--r--ext/pgsql/tests/bug37100_85.phpt46
-rw-r--r--ext/pgsql/tests/skipif.inc15
13 files changed, 215 insertions, 18 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index c8cf494e3..273bee058 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2009 The PHP Group |
+ | Copyright (c) 1997-2010 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -20,7 +20,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: pgsql.c 280789 2009-05-19 16:03:36Z kalle $ */
+/* $Id: pgsql.c 293036 2010-01-03 09:23:27Z sebastian $ */
#include <stdlib.h>
@@ -819,7 +819,7 @@ static void _php_pgsql_notice_handler(void *resource_id, const char *message)
if (PGG(log_notices)) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s", notice->message);
}
- zend_hash_index_update(&PGG(notices), (int)resource_id, (void **)&notice, sizeof(php_pgsql_notice *), NULL);
+ zend_hash_index_update(&PGG(notices), (ulong)resource_id, (void **)&notice, sizeof(php_pgsql_notice *), NULL);
}
}
/* }}} */
@@ -1217,13 +1217,14 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
*/
if (!(connect_type & PGSQL_CONNECT_FORCE_NEW)
&& zend_hash_find(&EG(regular_list),str.c,str.len+1,(void **) &index_ptr)==SUCCESS) {
- int type,link;
+ int type;
+ ulong link;
void *ptr;
if (Z_TYPE_P(index_ptr) != le_index_ptr) {
RETURN_FALSE;
}
- link = (int) index_ptr->ptr;
+ link = (ulong) index_ptr->ptr;
ptr = zend_list_find(link,&type); /* check if the link is still there */
if (ptr && (type==le_link || type==le_plink)) {
Z_LVAL_P(return_value) = link;
@@ -2166,14 +2167,15 @@ PHP_FUNCTION(pg_field_table)
if (return_oid) {
+#if UINT_MAX > LONG_MAX /* Oid is unsigned int, we don't need this code, where LONG is wider */
if (oid > LONG_MAX) {
smart_str oidstr = {0};
smart_str_append_unsigned(&oidstr, oid);
smart_str_0(&oidstr);
RETURN_STRINGL(oidstr.c, oidstr.len, 0);
- } else {
+ } else
+#endif
RETURN_LONG((long)oid);
- }
}
/* try to lookup the table name in the resource list */
@@ -2271,7 +2273,7 @@ static void php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_typ
case PHP_PG_FIELD_TYPE_OID:
oid = PQftype(pgsql_result, field);
-
+#if UINT_MAX > LONG_MAX
if (oid > LONG_MAX) {
smart_str s = {0};
smart_str_append_unsigned(&s, oid);
@@ -2279,7 +2281,9 @@ static void php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_typ
Z_STRVAL_P(return_value) = s.c;
Z_STRLEN_P(return_value) = s.len;
Z_TYPE_P(return_value) = IS_STRING;
- } else {
+ } else
+#endif
+ {
Z_LVAL_P(return_value) = (long)oid;
Z_TYPE_P(return_value) = IS_LONG;
}
@@ -3760,7 +3764,11 @@ PHP_FUNCTION(pg_copy_to)
pg_null_as = safe_estrdup("\\\\N");
}
- spprintf(&query, 0, "COPY \"%s\" TO STDOUT DELIMITERS '%c' WITH NULL AS '%s'", table_name, *pg_delim, pg_null_as);
+ if (memchr(table_name, '.', table_name_len)) {
+ spprintf(&query, 0, "COPY %s TO STDOUT DELIMITERS '%c' WITH NULL AS '%s'", table_name, *pg_delim, pg_null_as);
+ } else {
+ spprintf(&query, 0, "COPY \"%s\" TO STDOUT DELIMITERS '%c' WITH NULL AS '%s'", table_name, *pg_delim, pg_null_as);
+ }
while ((pgsql_result = PQgetResult(pgsql))) {
PQclear(pgsql_result);
diff --git a/ext/pgsql/php_pgsql.h b/ext/pgsql/php_pgsql.h
index efc804098..09a53c173 100644
--- a/ext/pgsql/php_pgsql.h
+++ b/ext/pgsql/php_pgsql.h
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2009 The PHP Group |
+ | Copyright (c) 1997-2010 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_pgsql.h 272370 2008-12-31 11:15:49Z sebastian $ */
+/* $Id: php_pgsql.h 293036 2010-01-03 09:23:27Z sebastian $ */
#ifndef PHP_PGSQL_H
#define PHP_PGSQL_H
diff --git a/ext/pgsql/tests/10pg_convert.phpt b/ext/pgsql/tests/10pg_convert.phpt
index b88b8e579..73bf2b64e 100644
--- a/ext/pgsql/tests/10pg_convert.phpt
+++ b/ext/pgsql/tests/10pg_convert.phpt
@@ -1,7 +1,10 @@
--TEST--
PostgreSQL pg_convert()
--SKIPIF--
-<?php include("skipif.inc"); ?>
+<?php
+include("skipif.inc");
+skip_server_version('8.5dev', '>=');
+?>
--FILE--
<?php
error_reporting(E_ALL);
diff --git a/ext/pgsql/tests/10pg_convert_85.phpt b/ext/pgsql/tests/10pg_convert_85.phpt
new file mode 100644
index 000000000..4f1c92bf1
--- /dev/null
+++ b/ext/pgsql/tests/10pg_convert_85.phpt
@@ -0,0 +1,29 @@
+--TEST--
+PostgreSQL pg_convert() (8.5+)
+--SKIPIF--
+<?php
+include("skipif.inc");
+skip_server_version('8.5dev', '<');
+?>
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+include 'config.inc';
+
+$db = pg_connect($conn_str);
+
+$fields = array('num'=>'1234', 'str'=>'AAA', 'bin'=>'BBB');
+$converted = pg_convert($db, $table_name, $fields);
+
+var_dump($converted);
+?>
+--EXPECT--
+array(3) {
+ ["num"]=>
+ string(4) "1234"
+ ["str"]=>
+ string(5) "'AAA'"
+ ["bin"]=>
+ string(11) "'\\x424242'"
+}
diff --git a/ext/pgsql/tests/12pg_insert.phpt b/ext/pgsql/tests/12pg_insert.phpt
index 8d98f220f..f5cd868f8 100644
--- a/ext/pgsql/tests/12pg_insert.phpt
+++ b/ext/pgsql/tests/12pg_insert.phpt
@@ -1,7 +1,10 @@
--TEST--
PostgreSQL pg_insert()
--SKIPIF--
-<?php include("skipif.inc"); ?>
+<?php
+include("skipif.inc");
+skip_server_version('8.5dev', '>=');
+?>
--FILE--
<?php
error_reporting(E_ALL);
diff --git a/ext/pgsql/tests/12pg_insert_85.phpt b/ext/pgsql/tests/12pg_insert_85.phpt
new file mode 100644
index 000000000..a85dea036
--- /dev/null
+++ b/ext/pgsql/tests/12pg_insert_85.phpt
@@ -0,0 +1,24 @@
+--TEST--
+PostgreSQL pg_insert() (8.5+)
+--SKIPIF--
+<?php
+include("skipif.inc");
+skip_server_version('8.5dev', '<');
+?>
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+include 'config.inc';
+
+$db = pg_connect($conn_str);
+$fields = array('num'=>'1234', 'str'=>'AAA', 'bin'=>'BBB');
+
+pg_insert($db, $table_name, $fields) or print "Error in test 1\n";
+echo pg_insert($db, $table_name, $fields, PGSQL_DML_STRING)."\n";
+
+echo "Ok\n";
+?>
+--EXPECT--
+INSERT INTO php_pgsql_test (num,str,bin) VALUES (1234,'AAA','\\x424242');
+Ok
diff --git a/ext/pgsql/tests/13pg_select.phpt b/ext/pgsql/tests/13pg_select.phpt
index 55e88db73..f1504a8b1 100644
--- a/ext/pgsql/tests/13pg_select.phpt
+++ b/ext/pgsql/tests/13pg_select.phpt
@@ -1,7 +1,10 @@
--TEST--
PostgreSQL pg_select()
--SKIPIF--
-<?php include("skipif.inc"); ?>
+<?php
+include("skipif.inc");
+skip_server_version('8.5dev', '>=');
+?>
--FILE--
<?php
error_reporting(E_ALL);
diff --git a/ext/pgsql/tests/13pg_select_85.phpt b/ext/pgsql/tests/13pg_select_85.phpt
new file mode 100644
index 000000000..e6d86bd6f
--- /dev/null
+++ b/ext/pgsql/tests/13pg_select_85.phpt
@@ -0,0 +1,37 @@
+--TEST--
+PostgreSQL pg_select() (8.5+)
+--SKIPIF--
+<?php
+include("skipif.inc");
+skip_server_version('8.5dev', '<');
+?>
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+include 'config.inc';
+
+$db = pg_connect($conn_str);
+$fields = array('num'=>'1234', 'str'=>'ABC', 'bin'=>'XYZ');
+$ids = array('num'=>'1234');
+
+$res = pg_select($db, $table_name, $ids) or print "Error\n";
+var_dump($res);
+echo pg_select($db, $table_name, $ids, PGSQL_DML_STRING)."\n";
+echo "Ok\n";
+
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ array(3) {
+ ["num"]=>
+ string(4) "1234"
+ ["str"]=>
+ string(3) "AAA"
+ ["bin"]=>
+ string(8) "\x424242"
+ }
+}
+SELECT * FROM php_pgsql_test WHERE num=1234;
+Ok
diff --git a/ext/pgsql/tests/14pg_update.phpt b/ext/pgsql/tests/14pg_update.phpt
index ef8d7e49b..b41dd1af8 100644
--- a/ext/pgsql/tests/14pg_update.phpt
+++ b/ext/pgsql/tests/14pg_update.phpt
@@ -1,7 +1,10 @@
--TEST--
PostgreSQL pg_update()
--SKIPIF--
-<?php include("skipif.inc"); ?>
+<?php
+include("skipif.inc");
+skip_server_version('8.5dev', '>=');
+?>
--FILE--
<?php
error_reporting(E_ALL);
diff --git a/ext/pgsql/tests/14pg_update_85.phpt b/ext/pgsql/tests/14pg_update_85.phpt
new file mode 100644
index 000000000..f1c77eac1
--- /dev/null
+++ b/ext/pgsql/tests/14pg_update_85.phpt
@@ -0,0 +1,25 @@
+--TEST--
+PostgreSQL pg_update() (8.5+)
+--SKIPIF--
+<?php
+include("skipif.inc");
+skip_server_version('8.5dev', '<');
+?>
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+include 'config.inc';
+
+$db = pg_connect($conn_str);
+$fields = array('num'=>'1234', 'str'=>'ABC', 'bin'=>'XYZ');
+$ids = array('num'=>'1234');
+
+pg_update($db, $table_name, $fields, $ids) or print "Error in test 1\n";
+echo pg_update($db, $table_name, $fields, $ids, PGSQL_DML_STRING)."\n";
+
+echo "Ok\n";
+?>
+--EXPECT--
+UPDATE php_pgsql_test SET num=1234,str='ABC',bin='\\x58595a' WHERE num=1234;
+Ok
diff --git a/ext/pgsql/tests/bug37100.phpt b/ext/pgsql/tests/bug37100.phpt
index b66149e4a..fa6b9ba9e 100644
--- a/ext/pgsql/tests/bug37100.phpt
+++ b/ext/pgsql/tests/bug37100.phpt
@@ -1,7 +1,10 @@
--TEST--
Bug #37100 (data is returned truncated with BINARY CURSOR)
--SKIPIF--
-<?php include("skipif.inc"); ?>
+<?php
+include("skipif.inc");
+skip_server_version('8.5dev', '>=');
+?>
--FILE--
<?php
diff --git a/ext/pgsql/tests/bug37100_85.phpt b/ext/pgsql/tests/bug37100_85.phpt
new file mode 100644
index 000000000..aa2477626
--- /dev/null
+++ b/ext/pgsql/tests/bug37100_85.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Bug #37100 (data is returned truncated with BINARY CURSOR) (8.5+)
+--SKIPIF--
+<?php
+include("skipif.inc");
+skip_server_version('8.5dev', '<');
+?>
+--FILE--
+<?php
+
+include 'config.inc';
+
+$db = pg_connect($conn_str);
+
+@pg_query('DROP TABLE test_bug');
+
+pg_query('CREATE TABLE test_bug (binfield byteA) ;');
+pg_query("INSERT INTO test_bug VALUES (decode('0103AA000812','hex'))");
+
+
+$data = pg_query("SELECT binfield FROM test_bug");
+$res = pg_fetch_result($data,0);
+var_dump($res);
+var_dump(bin2hex(pg_unescape_bytea($res)));
+
+$sql = "BEGIN; DECLARE mycursor BINARY CURSOR FOR SELECT binfield FROM test_bug; FETCH ALL IN mycursor;";
+
+$data = pg_query($sql);
+$res = pg_fetch_result($data,0);
+
+var_dump(strlen($res));
+var_dump(bin2hex($res));
+
+pg_close($db);
+
+$db = pg_connect($conn_str);
+pg_query('DROP TABLE test_bug');
+pg_close($db);
+
+
+?>
+--EXPECT--
+string(14) "\x0103aa000812"
+string(12) "0103aa000812"
+int(6)
+string(12) "0103aa000812"
diff --git a/ext/pgsql/tests/skipif.inc b/ext/pgsql/tests/skipif.inc
index 043a0bd8d..74b27b3ad 100644
--- a/ext/pgsql/tests/skipif.inc
+++ b/ext/pgsql/tests/skipif.inc
@@ -15,4 +15,17 @@ $conn = @pg_connect($conn_str);
if (!is_resource($conn)) {
die("skip could not connect\n");
}
-?> \ No newline at end of file
+
+function skip_server_version($version, $op = '<') { _skip_version('server', $version, $op); }
+function skip_client_version($version, $op = '<') { _skip_version('client', $version, $op); }
+
+
+function _skip_version($type, $version, $op)
+{
+ $pg = pg_parameter_status($type.'_version');
+ if (version_compare($pg, $version, $op)) {
+ die("skip {$type} version {$pg} is {$op} {$version}\n");
+ }
+}
+
+?>