diff options
Diffstat (limited to 'ext/pgsql/tests')
25 files changed, 194 insertions, 63 deletions
diff --git a/ext/pgsql/tests/08escape.phpt b/ext/pgsql/tests/08escape.phpt index 90b4ed8a9..1bea35bf1 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/09notice.phpt b/ext/pgsql/tests/09notice.phpt index 316706916..67ef262fc 100644 --- a/ext/pgsql/tests/09notice.phpt +++ b/ext/pgsql/tests/09notice.phpt @@ -10,7 +10,7 @@ _skip_lc_messages(); ?> --INI-- pgsql.log_notice=1 -pgsql.ignore_notices=0 +pgsql.ignore_notice=0 --FILE-- <?php include 'config.inc'; diff --git a/ext/pgsql/tests/10pg_convert.phpt b/ext/pgsql/tests/10pg_convert.phpt index 73bf2b64e..adc2756e2 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 @@ -20,10 +20,10 @@ var_dump($converted); ?> --EXPECT-- array(3) { - ["num"]=> + [""num""]=> string(4) "1234" - ["str"]=> - string(5) "'AAA'" - ["bin"]=> - string(5) "'BBB'" -} + [""str""]=> + string(6) "E'AAA'" + [""bin""]=> + string(6) "E'BBB'" +}
\ No newline at end of file diff --git a/ext/pgsql/tests/10pg_convert_85.phpt b/ext/pgsql/tests/10pg_convert_9.phpt index 4f1c92bf1..827c96250 100644 --- a/ext/pgsql/tests/10pg_convert_85.phpt +++ b/ext/pgsql/tests/10pg_convert_9.phpt @@ -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 @@ -12,6 +12,7 @@ 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); @@ -20,10 +21,10 @@ var_dump($converted); ?> --EXPECT-- array(3) { - ["num"]=> + [""num""]=> string(4) "1234" - ["str"]=> - string(5) "'AAA'" - ["bin"]=> - string(11) "'\\x424242'" -} + [""str""]=> + string(6) "E'AAA'" + [""bin""]=> + string(12) "E'\\x424242'" +}
\ No newline at end of file diff --git a/ext/pgsql/tests/12pg_insert.phpt b/ext/pgsql/tests/12pg_insert.phpt index f5cd868f8..9fd0dd1e3 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 @@ -20,5 +20,5 @@ 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','BBB'); -Ok +INSERT INTO "php_pgsql_test" ("num","str","bin") VALUES (1234,E'AAA',E'BBB'); +Ok
\ No newline at end of file diff --git a/ext/pgsql/tests/12pg_insert_85.phpt b/ext/pgsql/tests/12pg_insert_9.phpt index a85dea036..329364ad6 100644 --- a/ext/pgsql/tests/12pg_insert_85.phpt +++ b/ext/pgsql/tests/12pg_insert_9.phpt @@ -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 @@ -12,6 +12,8 @@ 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"; @@ -20,5 +22,5 @@ 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 +INSERT INTO "php_pgsql_test" ("num","str","bin") VALUES (1234,E'AAA',E'\\x424242'); +Ok
\ No newline at end of file diff --git a/ext/pgsql/tests/13pg_select.phpt b/ext/pgsql/tests/13pg_select.phpt index f1504a8b1..db2ca06bf 100644 --- a/ext/pgsql/tests/13pg_select.phpt +++ b/ext/pgsql/tests/13pg_select.phpt @@ -33,5 +33,5 @@ array(1) { string(3) "BBB" } } -SELECT * FROM php_pgsql_test WHERE num=1234; +SELECT * FROM "php_pgsql_test" WHERE "num"=1234; Ok diff --git a/ext/pgsql/tests/13pg_select_85.phpt b/ext/pgsql/tests/13pg_select_9.phpt index e6d86bd6f..67adc9d21 100644 --- a/ext/pgsql/tests/13pg_select_85.phpt +++ b/ext/pgsql/tests/13pg_select_9.phpt @@ -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'); @@ -33,5 +35,5 @@ array(1) { string(8) "\x424242" } } -SELECT * FROM php_pgsql_test WHERE num=1234; -Ok +SELECT * FROM "php_pgsql_test" WHERE "num"=1234; +Ok
\ No newline at end of file diff --git a/ext/pgsql/tests/14pg_update.phpt b/ext/pgsql/tests/14pg_update.phpt index b41dd1af8..347cac944 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 @@ -21,5 +21,5 @@ 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='XYZ' WHERE num=1234; -Ok +UPDATE "php_pgsql_test" SET "num"=1234,"str"=E'ABC',"bin"=E'XYZ' WHERE "num"=1234; +Ok
\ No newline at end of file diff --git a/ext/pgsql/tests/14pg_update_85.phpt b/ext/pgsql/tests/14pg_update_9.phpt index f1c77eac1..e766c1f38 100644 --- a/ext/pgsql/tests/14pg_update_85.phpt +++ b/ext/pgsql/tests/14pg_update_9.phpt @@ -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 @@ -12,6 +12,8 @@ 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'); @@ -21,5 +23,5 @@ 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 +UPDATE "php_pgsql_test" SET "num"=1234,"str"=E'ABC',"bin"=E'\\x58595a' WHERE "num"=1234; +Ok
\ No newline at end of file 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 000000000..492517733 --- /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.phpt b/ext/pgsql/tests/18pg_escape_bytea_esc.phpt index 43f98c446..38e5777c3 100644 --- a/ext/pgsql/tests/18pg_escape_bytea.phpt +++ b/ext/pgsql/tests/18pg_escape_bytea_esc.phpt @@ -1,5 +1,5 @@ --TEST-- -PostgreSQL pg_escape_bytea() functions +PostgreSQL pg_escape_bytea() functions (escape format) --SKIPIF-- <?php include("skipif.inc"); ?> --FILE-- @@ -8,10 +8,12 @@ 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); -$db = pg_connect($conn_str); 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); 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 000000000..04630bbbf --- /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/80_bug32223.phpt b/ext/pgsql/tests/80_bug32223.phpt index 573742c6e..cad5fb3a1 100644 --- a/ext/pgsql/tests/80_bug32223.phpt +++ b/ext/pgsql/tests/80_bug32223.phpt @@ -15,6 +15,8 @@ end; ' LANGUAGE plpgsql;"); if (!$res) die('skip PLPGSQL not available'); ?> +--INI-- +pgsql.ignore_notice=0 --FILE-- <?php diff --git a/ext/pgsql/tests/80_bug32223b.phpt b/ext/pgsql/tests/80_bug32223b.phpt index aada3f01b..e79685c43 100644 --- a/ext/pgsql/tests/80_bug32223b.phpt +++ b/ext/pgsql/tests/80_bug32223b.phpt @@ -15,6 +15,8 @@ end; ' LANGUAGE plpgsql;"); if (!$res) die('skip PLPGSQL not available'); ?> +--INI-- +pgsql.ignore_notice=0 --FILE-- <?php diff --git a/ext/pgsql/tests/80_bug36625.phpt b/ext/pgsql/tests/80_bug36625.phpt index a95cea711..9cc8a1d4f 100644 --- a/ext/pgsql/tests/80_bug36625.phpt +++ b/ext/pgsql/tests/80_bug36625.phpt @@ -37,6 +37,8 @@ array_walk($trace, 'search_trace_file'); var_dump($found > 0); var_dump(file_exists($tracefile)); +@unlink($tracefile); + ?> ===DONE=== --CLEAN-- diff --git a/ext/pgsql/tests/bug37100.phpt b/ext/pgsql/tests/bug37100.phpt index fa6b9ba9e..3faecc671 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_9.phpt index aa2477626..9f4160d12 100644 --- a/ext/pgsql/tests/bug37100_85.phpt +++ b/ext/pgsql/tests/bug37100_9.phpt @@ -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 diff --git a/ext/pgsql/tests/bug47199.phpt b/ext/pgsql/tests/bug47199.phpt index 5bfac0b1b..faa787fd5 100644 --- a/ext/pgsql/tests/bug47199.phpt +++ b/ext/pgsql/tests/bug47199.phpt @@ -52,8 +52,8 @@ array(2) { string(1) "2" } } -DELETE FROM test_47199 WHERE null_field IS NULL AND not_null_field=2; -UPDATE test_47199 SET null_field=NULL,not_null_field=0 WHERE not_null_field=1 AND null_field IS NULL; +DELETE FROM "test_47199" WHERE "null_field" IS NULL AND "not_null_field"=2; +UPDATE "test_47199" SET "null_field"=NULL,"not_null_field"=0 WHERE "not_null_field"=1 AND "null_field" IS NULL; array(1) { [0]=> array(2) { diff --git a/ext/pgsql/tests/bug64609.phpt b/ext/pgsql/tests/bug64609.phpt new file mode 100644 index 000000000..72fac7648 --- /dev/null +++ b/ext/pgsql/tests/bug64609.phpt @@ -0,0 +1,30 @@ +--TEST-- +Bug #64609 (pg_convert enum type support) +--SKIPIF-- +<?php +include("skipif.inc"); +skip_server_version('8.3', '<'); +?> +--FILE-- +<?php +error_reporting(E_ALL); + +include 'config.inc'; + +$db = pg_connect($conn_str); +pg_query("BEGIN"); +pg_query("CREATE TYPE t_enum AS ENUM ('ok', 'ko')"); +pg_query("CREATE TABLE test_enum (a t_enum)"); + +$fields = array('a' => 'ok'); +$converted = pg_convert($db, 'test_enum', $fields); + +pg_query("ROLLBACK"); + +var_dump($converted); +?> +--EXPECT-- +array(1) { + [""a""]=> + string(5) "E'ok'" +}
\ No newline at end of file diff --git a/ext/pgsql/tests/config.inc b/ext/pgsql/tests/config.inc index 2b5f05a71..d4bbb3382 100644 --- a/ext/pgsql/tests/config.inc +++ b/ext/pgsql/tests/config.inc @@ -2,7 +2,7 @@ // These vars are used to connect db and create test table. // values can be set to meet your environment -$conn_str = "host=localhost dbname=test"; // connection string +$conn_str = "host=localhost dbname=test port=5432"; // connection string $table_name = "php_pgsql_test"; // test table that should be exist $num_test_record = 1000; // Number of records to create diff --git a/ext/pgsql/tests/pg_delete_001.phpt b/ext/pgsql/tests/pg_delete_001.phpt index abb65be14..a98c95dc4 100644 --- a/ext/pgsql/tests/pg_delete_001.phpt +++ b/ext/pgsql/tests/pg_delete_001.phpt @@ -45,8 +45,8 @@ pg_query('DROP SCHEMA phptests'); ?> --EXPECTF-- -string(37) "DELETE FROM foo WHERE id=1 AND id2=2;" -string(46) "DELETE FROM phptests.foo WHERE id=2 AND id2=3;" +string(43) "DELETE FROM "foo" WHERE "id"=1 AND "id2"=2;" +string(54) "DELETE FROM "phptests"."foo" WHERE "id"=2 AND "id2"=3;" array(2) { [0]=> array(2) { diff --git a/ext/pgsql/tests/pg_insert_001.phpt b/ext/pgsql/tests/pg_insert_001.phpt index 7d2721918..626d4d0f8 100644 --- a/ext/pgsql/tests/pg_insert_001.phpt +++ b/ext/pgsql/tests/pg_insert_001.phpt @@ -28,7 +28,7 @@ pg_query('DROP SCHEMA phptests'); --EXPECTF-- Warning: pg_insert(): Table 'foo' doesn't exists in %s on line %d -string(47) "INSERT INTO phptests.foo (id,id2) VALUES (1,2);" +string(55) "INSERT INTO "phptests"."foo" ("id","id2") VALUES (1,2);" array(1) { [0]=> array(2) { diff --git a/ext/pgsql/tests/pg_update_001.phpt b/ext/pgsql/tests/pg_update_001.phpt index 95fa69256..60db35c15 100644 --- a/ext/pgsql/tests/pg_update_001.phpt +++ b/ext/pgsql/tests/pg_update_001.phpt @@ -35,8 +35,8 @@ pg_query('DROP SCHEMA phptests'); ?> --EXPECT-- -string(32) "UPDATE foo SET id=10 WHERE id=1;" -string(43) "UPDATE phptests.foo SET id=100 WHERE id2=2;" +string(38) "UPDATE "foo" SET "id"=10 WHERE "id"=1;" +string(51) "UPDATE "phptests"."foo" SET "id"=100 WHERE "id2"=2;" array(2) { ["id"]=> string(2) "10" diff --git a/ext/pgsql/tests/skipif.inc b/ext/pgsql/tests/skipif.inc index 7c5153e6f..83904af4f 100644 --- a/ext/pgsql/tests/skipif.inc +++ b/ext/pgsql/tests/skipif.inc @@ -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_server_version($version, $op = '<') +{ + $pg = pg_parameter_status('server_version'); + 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_version($type, $version, $op) +function skip_bytea_not_escape() { - $pg = pg_parameter_status($type.'_version'); - if (version_compare($pg, $version, $op)) { - die("skip {$type} version {$pg} is {$op} {$version}\n"); + $out = pg_escape_bytea("\xFF"); + if (strpos($out, '377') === false) { + die("skip libpq or backend >= 9.0\n"); } } |