Merge branch 'PHP-5.4' into PHP-5.5

* PHP-5.4:
  Fixed bug #65047 (Test skip on client / server version)
  Remove broken client version checking
  Clean up leftover file after the test
This commit is contained in:
Matteo Beccati 2013-06-19 11:53:05 +02:00
commit 9b8259cdfa
17 changed files with 132 additions and 31 deletions

View File

@ -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)");

View File

@ -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)");

View File

@ -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
pg_escape_identifier() is Ok

View File

@ -3,7 +3,7 @@ PostgreSQL pg_convert()
--SKIPIF--
<?php
include("skipif.inc");
skip_server_version('8.5dev', '>=');
skip_bytea_not_escape();
?>
--FILE--
<?php

View File

@ -1,9 +1,9 @@
--TEST--
PostgreSQL pg_convert() (8.5+)
PostgreSQL pg_convert() (9.0+)
--SKIPIF--
<?php
include("skipif.inc");
skip_server_version('8.5dev', '<');
skip_bytea_not_hex();
?>
--FILE--
<?php

View File

@ -3,7 +3,7 @@ PostgreSQL pg_insert()
--SKIPIF--
<?php
include("skipif.inc");
skip_server_version('8.5dev', '>=');
skip_bytea_not_escape();
?>
--FILE--
<?php

View File

@ -1,9 +1,9 @@
--TEST--
PostgreSQL pg_insert() (8.5+)
PostgreSQL pg_insert() (9.0+)
--SKIPIF--
<?php
include("skipif.inc");
skip_server_version('8.5dev', '<');
skip_bytea_not_hex();
?>
--FILE--
<?php

View File

@ -1,9 +1,9 @@
--TEST--
PostgreSQL pg_select() (8.5+)
PostgreSQL pg_select() (9.0+)
--SKIPIF--
<?php
include("skipif.inc");
skip_server_version('8.5dev', '<');
skip_server_version('9.0', '<');
?>
--FILE--
<?php
@ -12,6 +12,8 @@ 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');

View File

@ -3,7 +3,7 @@ PostgreSQL pg_update()
--SKIPIF--
<?php
include("skipif.inc");
skip_server_version('8.5dev', '>=');
skip_bytea_not_escape();
?>
--FILE--
<?php

View File

@ -1,9 +1,9 @@
--TEST--
PostgreSQL pg_update() (8.5+)
PostgreSQL pg_update() (9.0)
--SKIPIF--
<?php
include("skipif.inc");
skip_server_version('8.5dev', '<');
skip_bytea_not_hex();
?>
--FILE--
<?php

View File

@ -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

View File

@ -1,5 +1,5 @@
--TEST--
PostgreSQL pg_escape_bytea() functions
PostgreSQL pg_escape_bytea() functions (escape format)
--SKIPIF--
<?php include("skipif.inc"); ?>
--FILE--
@ -9,6 +9,7 @@ PostgreSQL pg_escape_bytea() 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);

View File

@ -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

View File

@ -37,6 +37,8 @@ array_walk($trace, 'search_trace_file');
var_dump($found > 0);
var_dump(file_exists($tracefile));
@unlink($tracefile);
?>
===DONE===
--CLEAN--

View File

@ -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');

View File

@ -1,9 +1,9 @@
--TEST--
Bug #37100 (data is returned truncated with BINARY CURSOR) (8.5+)
Bug #37100 (data is returned truncated with BINARY CURSOR) (9.0+)
--SKIPIF--
<?php
include("skipif.inc");
skip_server_version('8.5dev', '<');
skip_bytea_not_hex();
?>
--FILE--
<?php

View File

@ -17,15 +17,28 @@ if (!is_resource($conn)) {
die("skip could not connect\n");
}
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)
function skip_server_version($version, $op = '<')
{
$pg = pg_parameter_status($type.'_version');
$pg = pg_parameter_status('server_version');
if (version_compare($pg, $version, $op)) {
die("skip {$type} version {$pg} is {$op} {$version}\n");
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");
}
}