Commit:    c666239265048abd3cc0b2c48493a5db1eacc28e
Author:    Matteo Beccati <mbecc...@php.net>         Wed, 19 Jun 2013 11:46:11 
+0200
Parents:   25e9aa6b0a86b2b3b098949b0fe866a5edeff02f
Branches:  PHP-5.4 PHP-5.5 master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=c666239265048abd3cc0b2c48493a5db1eacc28e

Log:
Fixed bug #65047 (Test skip on client / server version)

Bugs:
https://bugs.php.net/65047

Changed paths:
  M  ext/pdo_pgsql/tests/bug46274.phpt
  M  ext/pdo_pgsql/tests/bug46274_2.phpt
  M  ext/pgsql/tests/08escape.phpt
  M  ext/pgsql/tests/10pg_convert.phpt
  D  ext/pgsql/tests/10pg_convert_85.phpt
  A  ext/pgsql/tests/10pg_convert_9.phpt
  M  ext/pgsql/tests/12pg_insert.phpt
  D  ext/pgsql/tests/12pg_insert_85.phpt
  A  ext/pgsql/tests/12pg_insert_9.phpt
  D  ext/pgsql/tests/13pg_select_85.phpt
  A  ext/pgsql/tests/13pg_select_9.phpt
  M  ext/pgsql/tests/14pg_update.phpt
  D  ext/pgsql/tests/14pg_update_85.phpt
  A  ext/pgsql/tests/14pg_update_9.phpt
  D  ext/pgsql/tests/18pg_escape_bytea.phpt
  A  ext/pgsql/tests/18pg_escape_bytea_before.phpt
  A  ext/pgsql/tests/18pg_escape_bytea_esc.phpt
  A  ext/pgsql/tests/18pg_escape_bytea_hex.phpt
  M  ext/pgsql/tests/bug37100.phpt
  D  ext/pgsql/tests/bug37100_85.phpt
  A  ext/pgsql/tests/bug37100_9.phpt
  M  ext/pgsql/tests/skipif.inc

diff --git a/ext/pdo_pgsql/tests/bug46274.phpt 
b/ext/pdo_pgsql/tests/bug46274.phpt
index c34839a..8a85c9f 100644
--- a/ext/pdo_pgsql/tests/bug46274.phpt
+++ b/ext/pdo_pgsql/tests/bug46274.phpt
@@ -14,6 +14,11 @@ $db = PDOTest::test_factory(dirname(__FILE__) . 
'/common.phpt');
 
 $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
 
+try {
+       $db->query("SET bytea_output = 'escape'");
+} catch (Exception $e) {
+}
+
 $db->query('CREATE TABLE test_one_blob (id SERIAL NOT NULL, blob1 BYTEA)');
 
 $stmt = $db->prepare("INSERT INTO test_one_blob (blob1) VALUES (:foo)");
diff --git a/ext/pdo_pgsql/tests/bug46274_2.phpt 
b/ext/pdo_pgsql/tests/bug46274_2.phpt
index eb675af..317160c 100644
--- a/ext/pdo_pgsql/tests/bug46274_2.phpt
+++ b/ext/pdo_pgsql/tests/bug46274_2.phpt
@@ -14,6 +14,11 @@ $db = PDOTest::test_factory(dirname(__FILE__) . 
'/common.phpt');
 
 $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
 
+try {
+        $db->query("SET bytea_output = 'escape'");
+} catch (Exception $e) {
+}
+
 $db->query('CREATE TABLE test_one_blob (id SERIAL NOT NULL, blob1 BYTEA)');
 
 $stmt = $db->prepare("INSERT INTO test_one_blob (blob1) VALUES (:foo)");
diff --git a/ext/pgsql/tests/08escape.phpt b/ext/pgsql/tests/08escape.phpt
index 90b4ed8..1bea35b 100644
--- a/ext/pgsql/tests/08escape.phpt
+++ b/ext/pgsql/tests/08escape.phpt
@@ -48,15 +48,24 @@ $sql = "INSERT INTO ".$table_name." (num, bin) VALUES 
(-9999, CAST ('".$escaped_
 pg_query($db, $sql);
 
 // Retrieve binary from DB
-$sql = "SELECT bin::bytea FROM ".$table_name." WHERE num = -9999";
-$result = pg_query($db, $sql);
-$row = pg_fetch_array($result, 0, PGSQL_ASSOC);
+for ($i = 0; $i < 2; $i++) {
+       $sql = "SELECT bin::bytea FROM ".$table_name." WHERE num = -9999";
+       $result = pg_query($db, $sql);
+       $row = pg_fetch_array($result, 0, PGSQL_ASSOC);
 
-if ($data === pg_unescape_bytea($row['bin'])) {
-       echo "pg_escape_bytea() actually works with database\n";
-}
-else {
-       echo "pg_escape_bytea() is broken\n";
+       if ($data === pg_unescape_bytea($row['bin'])) {
+               echo "pg_escape_bytea() actually works with database\n";
+               break;
+       }
+       elseif (!$i) {
+               // Force bytea escaping and retry
+               @pg_query($db, "SET bytea_output = 'escape'");
+       }
+       else {
+               $result = pg_query($db, $sql);
+               echo "pg_escape_bytea() is broken\n";
+               break;
+       }
 }
 
 // pg_escape_literal/pg_escape_identifier
@@ -92,4 +101,4 @@ pg_escape_string() is Ok
 pg_escape_bytea() is Ok
 pg_escape_bytea() actually works with database
 pg_escape_literal() is Ok
-pg_escape_identifier() is Ok
\ No newline at end of file
+pg_escape_identifier() is Ok
diff --git a/ext/pgsql/tests/10pg_convert.phpt 
b/ext/pgsql/tests/10pg_convert.phpt
index 73bf2b6..fde4c67 100644
--- a/ext/pgsql/tests/10pg_convert.phpt
+++ b/ext/pgsql/tests/10pg_convert.phpt
@@ -3,7 +3,7 @@ PostgreSQL pg_convert()
 --SKIPIF--
 <?php
 include("skipif.inc");
-skip_server_version('8.5dev', '>=');
+skip_bytea_not_escape();
 ?>
 --FILE--
 <?php
diff --git a/ext/pgsql/tests/10pg_convert_85.phpt 
b/ext/pgsql/tests/10pg_convert_85.phpt
deleted file mode 100644
index 8b1cc8f..0000000
--- a/ext/pgsql/tests/10pg_convert_85.phpt
+++ /dev/null
@@ -1,30 +0,0 @@
---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);
-pg_query($db, "SET standard_conforming_strings = 0");
-
-$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/10pg_convert_9.phpt 
b/ext/pgsql/tests/10pg_convert_9.phpt
new file mode 100644
index 0000000..bb2e7e6
--- /dev/null
+++ b/ext/pgsql/tests/10pg_convert_9.phpt
@@ -0,0 +1,30 @@
+--TEST--
+PostgreSQL pg_convert() (9.0+)
+--SKIPIF--
+<?php
+include("skipif.inc");
+skip_bytea_not_hex();
+?>
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+include 'config.inc';
+
+$db = pg_connect($conn_str);
+pg_query($db, "SET standard_conforming_strings = 0");
+
+$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 f5cd868..6630494 100644
--- a/ext/pgsql/tests/12pg_insert.phpt
+++ b/ext/pgsql/tests/12pg_insert.phpt
@@ -3,7 +3,7 @@ PostgreSQL pg_insert()
 --SKIPIF--
 <?php
 include("skipif.inc");
-skip_server_version('8.5dev', '>=');
+skip_bytea_not_escape();
 ?>
 --FILE--
 <?php
diff --git a/ext/pgsql/tests/12pg_insert_85.phpt 
b/ext/pgsql/tests/12pg_insert_85.phpt
deleted file mode 100644
index 5fbbe4b..0000000
--- a/ext/pgsql/tests/12pg_insert_85.phpt
+++ /dev/null
@@ -1,26 +0,0 @@
---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);
-pg_query($db, "SET standard_conforming_strings = 0");
-
-$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/12pg_insert_9.phpt 
b/ext/pgsql/tests/12pg_insert_9.phpt
new file mode 100644
index 0000000..8afae0d
--- /dev/null
+++ b/ext/pgsql/tests/12pg_insert_9.phpt
@@ -0,0 +1,26 @@
+--TEST--
+PostgreSQL pg_insert() (9.0+)
+--SKIPIF--
+<?php
+include("skipif.inc");
+skip_bytea_not_hex();
+?>
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+include 'config.inc';
+
+$db = pg_connect($conn_str);
+pg_query($db, "SET standard_conforming_strings = 0");
+
+$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_85.phpt 
b/ext/pgsql/tests/13pg_select_85.phpt
deleted file mode 100644
index e6d86bd..0000000
--- a/ext/pgsql/tests/13pg_select_85.phpt
+++ /dev/null
@@ -1,37 +0,0 @@
---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/13pg_select_9.phpt 
b/ext/pgsql/tests/13pg_select_9.phpt
new file mode 100644
index 0000000..422c461
--- /dev/null
+++ b/ext/pgsql/tests/13pg_select_9.phpt
@@ -0,0 +1,39 @@
+--TEST--
+PostgreSQL pg_select() (9.0+)
+--SKIPIF--
+<?php
+include("skipif.inc");
+skip_server_version('9.0', '<');
+?>
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+include 'config.inc';
+
+$db = pg_connect($conn_str);
+pg_query("SET bytea_output = 'hex'");
+
+$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 b41dd1a..3260f2b 100644
--- a/ext/pgsql/tests/14pg_update.phpt
+++ b/ext/pgsql/tests/14pg_update.phpt
@@ -3,7 +3,7 @@ PostgreSQL pg_update()
 --SKIPIF--
 <?php
 include("skipif.inc");
-skip_server_version('8.5dev', '>=');
+skip_bytea_not_escape();
 ?>
 --FILE--
 <?php
diff --git a/ext/pgsql/tests/14pg_update_85.phpt 
b/ext/pgsql/tests/14pg_update_85.phpt
deleted file mode 100644
index 06ca8c3..0000000
--- a/ext/pgsql/tests/14pg_update_85.phpt
+++ /dev/null
@@ -1,27 +0,0 @@
---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);
-pg_query($db, "SET standard_conforming_strings = 0");
-
-$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/14pg_update_9.phpt 
b/ext/pgsql/tests/14pg_update_9.phpt
new file mode 100644
index 0000000..bc5cf67
--- /dev/null
+++ b/ext/pgsql/tests/14pg_update_9.phpt
@@ -0,0 +1,27 @@
+--TEST--
+PostgreSQL pg_update() (9.0)
+--SKIPIF--
+<?php
+include("skipif.inc");
+skip_bytea_not_hex();
+?>
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+include 'config.inc';
+
+$db = pg_connect($conn_str);
+pg_query($db, "SET standard_conforming_strings = 0");
+
+$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/18pg_escape_bytea.phpt 
b/ext/pgsql/tests/18pg_escape_bytea.phpt
deleted file mode 100644
index 5f52a17..0000000
--- a/ext/pgsql/tests/18pg_escape_bytea.phpt
+++ /dev/null
@@ -1,29 +0,0 @@
---TEST--
-PostgreSQL pg_escape_bytea() functions
---SKIPIF--
-<?php include("skipif.inc"); ?>
---FILE--
-<?php
-// optional functions
-
-include('config.inc');
-
-$db = pg_connect($conn_str);
-
-$image = file_get_contents(dirname(__FILE__) . '/php.gif');
-$esc_image = pg_escape_bytea($image);
-
-pg_query($db, 'INSERT INTO '.$table_name.' (num, bin) VALUES (9876, 
\''.$esc_image.'\');');
-$result = pg_query($db, 'SELECT * FROM '.$table_name.' WHERE num = 9876');
-$rows = pg_fetch_all($result);
-$unesc_image = pg_unescape_bytea($rows[0]['bin']);
-
-if ($unesc_image !== $image) {
-       echo "NG";
-}
-else {
-       echo "OK";
-}
-?>
---EXPECT--
-OK
diff --git a/ext/pgsql/tests/18pg_escape_bytea_before.phpt 
b/ext/pgsql/tests/18pg_escape_bytea_before.phpt
new file mode 100644
index 0000000..4925177
--- /dev/null
+++ b/ext/pgsql/tests/18pg_escape_bytea_before.phpt
@@ -0,0 +1,30 @@
+--TEST--
+PostgreSQL pg_escape_bytea() functions (before connection)
+--SKIPIF--
+<?php include("skipif.inc"); ?>
+--FILE--
+<?php
+// optional functions
+
+include('config.inc');
+
+$image = file_get_contents(dirname(__FILE__) . '/php.gif');
+$esc_image = pg_escape_bytea($image);
+
+$db = pg_connect($conn_str);
+@pg_query($db, "SET bytea_output = 'escape'");
+
+pg_query($db, 'INSERT INTO '.$table_name.' (num, bin) VALUES (9876, 
E\''.$esc_image.'\');');
+$result = pg_query($db, 'SELECT * FROM '.$table_name.' WHERE num = 9876');
+$rows = pg_fetch_all($result);
+$unesc_image = pg_unescape_bytea($rows[0]['bin']);
+
+if ($unesc_image !== $image) {
+       echo "NG";
+}
+else {
+       echo "OK";
+}
+?>
+--EXPECT--
+OK
diff --git a/ext/pgsql/tests/18pg_escape_bytea_esc.phpt 
b/ext/pgsql/tests/18pg_escape_bytea_esc.phpt
new file mode 100644
index 0000000..38e5777
--- /dev/null
+++ b/ext/pgsql/tests/18pg_escape_bytea_esc.phpt
@@ -0,0 +1,30 @@
+--TEST--
+PostgreSQL pg_escape_bytea() functions (escape format)
+--SKIPIF--
+<?php include("skipif.inc"); ?>
+--FILE--
+<?php
+// optional functions
+
+include('config.inc');
+
+$db = pg_connect($conn_str);
+@pg_query($db, "SET bytea_output = 'escape'");
+
+$image = file_get_contents(dirname(__FILE__) . '/php.gif');
+$esc_image = pg_escape_bytea($image);
+
+pg_query($db, 'INSERT INTO '.$table_name.' (num, bin) VALUES (9876, 
\''.$esc_image.'\');');
+$result = pg_query($db, 'SELECT * FROM '.$table_name.' WHERE num = 9876');
+$rows = pg_fetch_all($result);
+$unesc_image = pg_unescape_bytea($rows[0]['bin']);
+
+if ($unesc_image !== $image) {
+       echo "NG";
+}
+else {
+       echo "OK";
+}
+?>
+--EXPECT--
+OK
diff --git a/ext/pgsql/tests/18pg_escape_bytea_hex.phpt 
b/ext/pgsql/tests/18pg_escape_bytea_hex.phpt
new file mode 100644
index 0000000..04630bb
--- /dev/null
+++ b/ext/pgsql/tests/18pg_escape_bytea_hex.phpt
@@ -0,0 +1,33 @@
+--TEST--
+PostgreSQL pg_escape_bytea() functions (hex format)
+--SKIPIF--
+<?php
+include("skipif.inc");
+skip_bytea_not_hex();
+?>
+--FILE--
+<?php
+// optional functions
+
+include('config.inc');
+
+$db = pg_connect($conn_str);
+@pg_query($db, "SET bytea_output = 'hex'");
+
+$image = file_get_contents(dirname(__FILE__) . '/php.gif');
+$esc_image = pg_escape_bytea($image);
+
+pg_query($db, 'INSERT INTO '.$table_name.' (num, bin) VALUES (9876, 
\''.$esc_image.'\');');
+$result = pg_query($db, 'SELECT * FROM '.$table_name.' WHERE num = 9876');
+$rows = pg_fetch_all($result);
+$unesc_image = pg_unescape_bytea($rows[0]['bin']);
+
+if ($unesc_image !== $image) {
+       echo "NG";
+}
+else {
+       echo "OK";
+}
+?>
+--EXPECT--
+OK
diff --git a/ext/pgsql/tests/bug37100.phpt b/ext/pgsql/tests/bug37100.phpt
index fa6b9ba..3faecc6 100644
--- a/ext/pgsql/tests/bug37100.phpt
+++ b/ext/pgsql/tests/bug37100.phpt
@@ -3,7 +3,7 @@ Bug #37100 (data is returned truncated with BINARY CURSOR)
 --SKIPIF--
 <?php
 include("skipif.inc");
-skip_server_version('8.5dev', '>=');
+skip_bytea_not_escape();
 ?>
 --FILE--
 <?php
@@ -11,6 +11,7 @@ skip_server_version('8.5dev', '>=');
 include 'config.inc';
 
 $db = pg_connect($conn_str);
+@pg_query("SET bytea_output = 'escape'");
 
 @pg_query('DROP TABLE test_bug');
 
diff --git a/ext/pgsql/tests/bug37100_85.phpt b/ext/pgsql/tests/bug37100_85.phpt
deleted file mode 100644
index aa24776..0000000
--- a/ext/pgsql/tests/bug37100_85.phpt
+++ /dev/null
@@ -1,46 +0,0 @@
---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/bug37100_9.phpt b/ext/pgsql/tests/bug37100_9.phpt
new file mode 100644
index 0000000..9f4160d
--- /dev/null
+++ b/ext/pgsql/tests/bug37100_9.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Bug #37100 (data is returned truncated with BINARY CURSOR) (9.0+)
+--SKIPIF--
+<?php
+include("skipif.inc");
+skip_bytea_not_hex();
+?>
+--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 59bd5a3..83904af 100644
--- a/ext/pgsql/tests/skipif.inc
+++ b/ext/pgsql/tests/skipif.inc
@@ -23,6 +23,23 @@ function skip_server_version($version, $op = '<')
        if (version_compare($pg, $version, $op)) {
                die("skip Server version {$pg} is {$op} {$version}\n");
        }
+       return $pg;
+}
+
+function skip_bytea_not_hex()
+{
+       $out = pg_escape_bytea("\xFF");
+       if (strpos($out, '377') !== false) {
+               die("skip libpq or backend < 9.0\n");
+       }
+}
+
+function skip_bytea_not_escape()
+{
+       $out = pg_escape_bytea("\xFF");
+       if (strpos($out, '377') === false) {
+               die("skip libpq or backend >= 9.0\n");
+       }
 }
 
 ?>
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to