Skip to content

Commit c666239

Browse files
committed
Fixed bug #65047 (Test skip on client / server version)
1 parent 25e9aa6 commit c666239

16 files changed

+127
-24
lines changed

ext/pdo_pgsql/tests/bug46274.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ $db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
1414

1515
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
1616

17+
try {
18+
$db->query("SET bytea_output = 'escape'");
19+
} catch (Exception $e) {
20+
}
21+
1722
$db->query('CREATE TABLE test_one_blob (id SERIAL NOT NULL, blob1 BYTEA)');
1823

1924
$stmt = $db->prepare("INSERT INTO test_one_blob (blob1) VALUES (:foo)");

ext/pdo_pgsql/tests/bug46274_2.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ $db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
1414

1515
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
1616

17+
try {
18+
$db->query("SET bytea_output = 'escape'");
19+
} catch (Exception $e) {
20+
}
21+
1722
$db->query('CREATE TABLE test_one_blob (id SERIAL NOT NULL, blob1 BYTEA)');
1823

1924
$stmt = $db->prepare("INSERT INTO test_one_blob (blob1) VALUES (:foo)");

ext/pgsql/tests/08escape.phpt

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,24 @@ $sql = "INSERT INTO ".$table_name." (num, bin) VALUES (-9999, CAST ('".$escaped_
4848
pg_query($db, $sql);
4949

5050
// Retrieve binary from DB
51-
$sql = "SELECT bin::bytea FROM ".$table_name." WHERE num = -9999";
52-
$result = pg_query($db, $sql);
53-
$row = pg_fetch_array($result, 0, PGSQL_ASSOC);
51+
for ($i = 0; $i < 2; $i++) {
52+
$sql = "SELECT bin::bytea FROM ".$table_name." WHERE num = -9999";
53+
$result = pg_query($db, $sql);
54+
$row = pg_fetch_array($result, 0, PGSQL_ASSOC);
5455

55-
if ($data === pg_unescape_bytea($row['bin'])) {
56-
echo "pg_escape_bytea() actually works with database\n";
57-
}
58-
else {
59-
echo "pg_escape_bytea() is broken\n";
56+
if ($data === pg_unescape_bytea($row['bin'])) {
57+
echo "pg_escape_bytea() actually works with database\n";
58+
break;
59+
}
60+
elseif (!$i) {
61+
// Force bytea escaping and retry
62+
@pg_query($db, "SET bytea_output = 'escape'");
63+
}
64+
else {
65+
$result = pg_query($db, $sql);
66+
echo "pg_escape_bytea() is broken\n";
67+
break;
68+
}
6069
}
6170

6271
// pg_escape_literal/pg_escape_identifier
@@ -92,4 +101,4 @@ pg_escape_string() is Ok
92101
pg_escape_bytea() is Ok
93102
pg_escape_bytea() actually works with database
94103
pg_escape_literal() is Ok
95-
pg_escape_identifier() is Ok
104+
pg_escape_identifier() is Ok

ext/pgsql/tests/10pg_convert.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ PostgreSQL pg_convert()
33
--SKIPIF--
44
<?php
55
include("skipif.inc");
6-
skip_server_version('8.5dev', '>=');
6+
skip_bytea_not_escape();
77
?>
88
--FILE--
99
<?php

ext/pgsql/tests/10pg_convert_85.phpt renamed to ext/pgsql/tests/10pg_convert_9.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
PostgreSQL pg_convert() (8.5+)
2+
PostgreSQL pg_convert() (9.0+)
33
--SKIPIF--
44
<?php
55
include("skipif.inc");
6-
skip_server_version('8.5dev', '<');
6+
skip_bytea_not_hex();
77
?>
88
--FILE--
99
<?php

ext/pgsql/tests/12pg_insert.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ PostgreSQL pg_insert()
33
--SKIPIF--
44
<?php
55
include("skipif.inc");
6-
skip_server_version('8.5dev', '>=');
6+
skip_bytea_not_escape();
77
?>
88
--FILE--
99
<?php

ext/pgsql/tests/12pg_insert_85.phpt renamed to ext/pgsql/tests/12pg_insert_9.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
PostgreSQL pg_insert() (8.5+)
2+
PostgreSQL pg_insert() (9.0+)
33
--SKIPIF--
44
<?php
55
include("skipif.inc");
6-
skip_server_version('8.5dev', '<');
6+
skip_bytea_not_hex();
77
?>
88
--FILE--
99
<?php

ext/pgsql/tests/13pg_select_85.phpt renamed to ext/pgsql/tests/13pg_select_9.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
PostgreSQL pg_select() (8.5+)
2+
PostgreSQL pg_select() (9.0+)
33
--SKIPIF--
44
<?php
55
include("skipif.inc");
6-
skip_server_version('8.5dev', '<');
6+
skip_server_version('9.0', '<');
77
?>
88
--FILE--
99
<?php
@@ -12,6 +12,8 @@ error_reporting(E_ALL);
1212
include 'config.inc';
1313

1414
$db = pg_connect($conn_str);
15+
pg_query("SET bytea_output = 'hex'");
16+
1517
$fields = array('num'=>'1234', 'str'=>'ABC', 'bin'=>'XYZ');
1618
$ids = array('num'=>'1234');
1719

ext/pgsql/tests/14pg_update.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ PostgreSQL pg_update()
33
--SKIPIF--
44
<?php
55
include("skipif.inc");
6-
skip_server_version('8.5dev', '>=');
6+
skip_bytea_not_escape();
77
?>
88
--FILE--
99
<?php

ext/pgsql/tests/14pg_update_85.phpt renamed to ext/pgsql/tests/14pg_update_9.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
PostgreSQL pg_update() (8.5+)
2+
PostgreSQL pg_update() (9.0)
33
--SKIPIF--
44
<?php
55
include("skipif.inc");
6-
skip_server_version('8.5dev', '<');
6+
skip_bytea_not_hex();
77
?>
88
--FILE--
99
<?php
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
PostgreSQL pg_escape_bytea() functions (before connection)
3+
--SKIPIF--
4+
<?php include("skipif.inc"); ?>
5+
--FILE--
6+
<?php
7+
// optional functions
8+
9+
include('config.inc');
10+
11+
$image = file_get_contents(dirname(__FILE__) . '/php.gif');
12+
$esc_image = pg_escape_bytea($image);
13+
14+
$db = pg_connect($conn_str);
15+
@pg_query($db, "SET bytea_output = 'escape'");
16+
17+
pg_query($db, 'INSERT INTO '.$table_name.' (num, bin) VALUES (9876, E\''.$esc_image.'\');');
18+
$result = pg_query($db, 'SELECT * FROM '.$table_name.' WHERE num = 9876');
19+
$rows = pg_fetch_all($result);
20+
$unesc_image = pg_unescape_bytea($rows[0]['bin']);
21+
22+
if ($unesc_image !== $image) {
23+
echo "NG";
24+
}
25+
else {
26+
echo "OK";
27+
}
28+
?>
29+
--EXPECT--
30+
OK

ext/pgsql/tests/18pg_escape_bytea.phpt renamed to ext/pgsql/tests/18pg_escape_bytea_esc.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
PostgreSQL pg_escape_bytea() functions
2+
PostgreSQL pg_escape_bytea() functions (escape format)
33
--SKIPIF--
44
<?php include("skipif.inc"); ?>
55
--FILE--
@@ -9,6 +9,7 @@ PostgreSQL pg_escape_bytea() functions
99
include('config.inc');
1010

1111
$db = pg_connect($conn_str);
12+
@pg_query($db, "SET bytea_output = 'escape'");
1213

1314
$image = file_get_contents(dirname(__FILE__) . '/php.gif');
1415
$esc_image = pg_escape_bytea($image);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
PostgreSQL pg_escape_bytea() functions (hex format)
3+
--SKIPIF--
4+
<?php
5+
include("skipif.inc");
6+
skip_bytea_not_hex();
7+
?>
8+
--FILE--
9+
<?php
10+
// optional functions
11+
12+
include('config.inc');
13+
14+
$db = pg_connect($conn_str);
15+
@pg_query($db, "SET bytea_output = 'hex'");
16+
17+
$image = file_get_contents(dirname(__FILE__) . '/php.gif');
18+
$esc_image = pg_escape_bytea($image);
19+
20+
pg_query($db, 'INSERT INTO '.$table_name.' (num, bin) VALUES (9876, \''.$esc_image.'\');');
21+
$result = pg_query($db, 'SELECT * FROM '.$table_name.' WHERE num = 9876');
22+
$rows = pg_fetch_all($result);
23+
$unesc_image = pg_unescape_bytea($rows[0]['bin']);
24+
25+
if ($unesc_image !== $image) {
26+
echo "NG";
27+
}
28+
else {
29+
echo "OK";
30+
}
31+
?>
32+
--EXPECT--
33+
OK

ext/pgsql/tests/bug37100.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ Bug #37100 (data is returned truncated with BINARY CURSOR)
33
--SKIPIF--
44
<?php
55
include("skipif.inc");
6-
skip_server_version('8.5dev', '>=');
6+
skip_bytea_not_escape();
77
?>
88
--FILE--
99
<?php
1010

1111
include 'config.inc';
1212

1313
$db = pg_connect($conn_str);
14+
@pg_query("SET bytea_output = 'escape'");
1415

1516
@pg_query('DROP TABLE test_bug');
1617

ext/pgsql/tests/bug37100_85.phpt renamed to ext/pgsql/tests/bug37100_9.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
--TEST--
2-
Bug #37100 (data is returned truncated with BINARY CURSOR) (8.5+)
2+
Bug #37100 (data is returned truncated with BINARY CURSOR) (9.0+)
33
--SKIPIF--
44
<?php
55
include("skipif.inc");
6-
skip_server_version('8.5dev', '<');
6+
skip_bytea_not_hex();
77
?>
88
--FILE--
99
<?php

ext/pgsql/tests/skipif.inc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ function skip_server_version($version, $op = '<')
2323
if (version_compare($pg, $version, $op)) {
2424
die("skip Server version {$pg} is {$op} {$version}\n");
2525
}
26+
return $pg;
27+
}
28+
29+
function skip_bytea_not_hex()
30+
{
31+
$out = pg_escape_bytea("\xFF");
32+
if (strpos($out, '377') !== false) {
33+
die("skip libpq or backend < 9.0\n");
34+
}
35+
}
36+
37+
function skip_bytea_not_escape()
38+
{
39+
$out = pg_escape_bytea("\xFF");
40+
if (strpos($out, '377') === false) {
41+
die("skip libpq or backend >= 9.0\n");
42+
}
2643
}
2744

2845
?>

0 commit comments

Comments
 (0)