ext/pgsql: Refactor tests (#12608)

This makes the tests independent of each other and allows them to be run in parallel.

Co-authored-by: Gina Peter Banyard <girgias@php.net>
This commit is contained in:
KentarouTakeda 2023-11-07 07:36:52 +09:00 committed by GitHub
parent 6537811527
commit c15988aab3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
88 changed files with 873 additions and 412 deletions

View file

@ -3,12 +3,12 @@ PostgreSQL version
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
// Get postgresql version for easier debugging.
// Execute run-test.php with --keep-all to get version string in 00version.log or 00version.out
include('config.inc');
include('inc/config.inc');
$db = pg_connect($conn_str);
var_dump(pg_version($db));

View file

@ -3,20 +3,20 @@ PostgreSQL create db
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
// create test table
include('config.inc');
include('inc/config.inc');
$table_name = 'table_01createdb';
$table_name_92 = 'table_01createdb_92';
$view_name = "view_01createdb";
$db = pg_connect($conn_str);
if (!($q = @pg_query($db, "SELECT * FROM ".$table_name)) || !@pg_num_rows($q))
{
pg_query($db,$table_def); // Create table here
for ($i=0; $i < $num_test_record; $i++) {
pg_query($db,"INSERT INTO ".$table_name." VALUES ($i, 'ABC');");
}
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)"); // Create table here
}
else {
echo pg_last_error()."\n";
@ -25,18 +25,28 @@ else {
$v = pg_version($db);
if (version_compare($v['server'], '9.2', '>=') && (!($q = @pg_query($db, "SELECT * FROM ".$table_name_92)) || !@pg_num_rows($q)))
{
pg_query($db,$table_def_92); // Create table here
pg_query($db, "CREATE TABLE {$table_name_92} (textary text[], jsn json)"); // Create table here
}
else {
echo pg_last_error()."\n";
}
// Create view here
pg_query($db,$view_def);
pg_query($db, "CREATE VIEW {$view_name} AS SELECT * FROM {$table_name}");
pg_close($db);
echo "OK";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = 'table_01createdb';
$table_name_92 = 'table_01createdb_92';
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name} cascade");
pg_query($db, "DROP TABLE IF EXISTS {$table_name_92} cascade");
?>
--EXPECT--
OK

View file

@ -3,12 +3,12 @@ PostgreSQL connection
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
// connection function tests
include('config.inc');
include('inc/config.inc');
$db = pg_pconnect($conn_str);
var_dump($db);

View file

@ -3,13 +3,16 @@ PostgreSQL sync query
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$table_name = "table_03sync_query";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
pg_query($db, "INSERT INTO {$table_name} DEFAULT VALUES");
$result = pg_query($db, "SELECT * FROM ".$table_name.";");
if (!($rows = pg_num_rows($result)))
@ -83,7 +86,7 @@ if (function_exists('pg_result_error_field')) {
pg_num_rows(pg_query($db, "SELECT * FROM ".$table_name.";"));
pg_num_fields(pg_query($db, "SELECT * FROM ".$table_name.";"));
pg_field_name($result, 0);
pg_field_num($result, $field_name);
pg_field_num($result, "num");
pg_field_size($result, 0);
pg_field_type($result, 0);
pg_field_prtlen($result, 0);
@ -134,6 +137,14 @@ pg_close($db);
echo "OK";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_03sync_query";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
Argument #3 must be greater than or equal to 0
Argument #3 must be less than the number of fields for this result set

View file

@ -3,13 +3,16 @@ PostgreSQL async query
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$table_name = "table_04async_query";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
pg_query($db, "INSERT INTO {$table_name} DEFAULT VALUES");
if (!pg_send_query($db, "SELECT * FROM ".$table_name.";")) {
echo "pg_send_query() error\n";
@ -46,7 +49,7 @@ for ($i=0; $i < $rows; $i++)
pg_num_rows(pg_query($db, "SELECT * FROM ".$table_name.";"));
pg_num_fields(pg_query($db, "SELECT * FROM ".$table_name.";"));
pg_field_name($result, 0);
pg_field_num($result, $field_name);
pg_field_num($result, "num");
pg_field_size($result, 0);
pg_field_type($result, 0);
pg_field_prtlen($result, 0);
@ -63,5 +66,13 @@ pg_free_result($result);
echo "OK";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_04async_query";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
OK

View file

@ -3,26 +3,26 @@ PostgreSQL large object
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$db = pg_connect($conn_str);
echo "create/write/close LO\n";
pg_exec ($db, "begin");
pg_exec ($db, "BEGIN");
$oid = pg_lo_create ($db);
if (!$oid) echo ("pg_lo_create() error\n");
$handle = pg_lo_open ($db, $oid, "w");
if (!$handle) echo ("pg_lo_open() error\n");
pg_lo_write ($handle, "large object data");
pg_lo_close ($handle);
pg_exec ($db, "commit");
pg_exec ($db, "COMMIT");
echo "open/read/tell/seek/close LO\n";
pg_exec ($db, "begin");
pg_exec ($db, "BEGIN");
$handle = pg_lo_open ($db, $oid, "w");
var_dump(pg_lo_read($handle, 5));
var_dump(pg_lo_tell($handle));
@ -34,10 +34,10 @@ var_dump(pg_lo_read($handle));
var_dump(pg_lo_seek($handle, -4, PGSQL_SEEK_END)); /* Seek from the end */
var_dump(pg_lo_read($handle));
pg_lo_close($handle);
pg_exec ($db, "commit");
pg_exec ($db, "COMMIT");
echo "open/read_all/close LO\n";
pg_exec ($db, "begin");
pg_exec ($db, "BEGIN");
$handle = pg_lo_open ($db, $oid, "w");
/* Will write to stdout */
$bytesWritten = pg_lo_read_all($handle);
@ -45,39 +45,39 @@ echo "\n";
var_dump($bytesWritten);
if (pg_last_error($db)) echo "pg_lo_read_all() error\n".pg_last_error();
pg_lo_close($handle);
pg_exec ($db, "commit");
pg_exec ($db, "COMMIT");
echo "unlink LO\n";
pg_exec ($db, "begin");
pg_exec ($db, "BEGIN");
pg_lo_unlink($db, $oid) or print("pg_lo_unlink() error 1\n");
pg_exec ($db, "commit");
pg_exec ($db, "COMMIT");
// more pg_lo_unlink() tests
echo "Test without connection\n";
pg_exec ($db, "begin");
pg_exec ($db, "BEGIN");
$oid = pg_lo_create ($db) or print("pg_lo_create() error\n");
pg_lo_unlink($oid) or print("pg_lo_unlink() error 2\n");
pg_exec ($db, "commit");
pg_exec ($db, "COMMIT");
echo "Test with string oid value\n";
pg_exec ($db, "begin");
pg_exec ($db, "BEGIN");
$oid = pg_lo_create ($db) or print("pg_lo_create() error\n");
pg_lo_unlink($db, (string)$oid) or print("pg_lo_unlink() error 3\n");
pg_exec ($db, "commit");
pg_exec ($db, "COMMIT");
echo "import/export LO\n";
$path = __DIR__ . '/';
pg_query($db, 'begin');
pg_query($db, 'BEGIN');
$oid = pg_lo_import($db, $path . 'php.gif');
pg_query($db, 'commit');
pg_query($db, 'begin');
pg_query($db, 'COMMIT');
pg_query($db, 'BEGIN');
@unlink($path . 'php.gif.exported');
pg_lo_export($db, $oid, $path . 'php.gif.exported');
if (!file_exists($path . 'php.gif.exported')) {
echo "Export failed\n";
}
@unlink($path . 'php.gif.exported');
pg_query($db, 'commit');
pg_query($db, 'COMMIT');
/* invalid OID values */
try {

View file

@ -3,19 +3,34 @@ Bug 73498 Incorrect DELIMITER syntax for pg_copy_to()
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$table_name = "table_06_bug73498";
$view_name = "view_06_bug73498";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
pg_query($db, "CREATE VIEW {$view_name} as SELECT * FROM {$table_name}");
pg_query($db, "INSERT INTO {$table_name} DEFAULT VALUES");
$rows = pg_copy_to($db, "(select * from {$view_name})");
$rows = pg_copy_to($db, "(SELECT * FROM {$view_name})");
var_dump(gettype($rows));
var_dump(count($rows) > 0);
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_06_bug73498";
$view_name = "view_06_bug73498";
$db = pg_connect($conn_str);
pg_query($db, "DROP VIEW IF EXISTS {$view_name}");
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
string(5) "array"

View file

@ -3,13 +3,15 @@ PostgreSQL copy functions
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$table_name = "table_06copy";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
$rows = pg_copy_to($db, $table_name);
@ -19,6 +21,14 @@ pg_copy_from($db, $table_name, $rows);
echo "OK";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_06copy";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
OK

View file

@ -3,27 +3,33 @@ PostgreSQL copy functions, part 2
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$table_name = 'table_06copy_2';
$db = pg_connect($conn_str);
pg_query($db, 'CREATE TABLE test_copy (x int)');
pg_query($db, "CREATE TABLE {$table_name} (x int)");
pg_query($db, 'COPY test_copy FROM STDIN');
pg_query($db, "COPY {$table_name} FROM STDIN");
pg_put_line($db, "1\n");
pg_put_line($db, "\\N\n");
pg_put_line($db, "\\.\n");
pg_end_copy($db);
var_dump(pg_fetch_all_columns(pg_query($db, 'SELECT * FROM test_copy ORDER BY 1')));
pg_query($db, 'DROP TABLE test_copy');
var_dump(pg_fetch_all_columns(pg_query($db, "SELECT * FROM {$table_name} ORDER BY 1")));
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = 'table_06copy_2';
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
array(2) {

View file

@ -3,12 +3,12 @@ PostgreSQL optional functions
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
// optional functions
include('config.inc');
include('inc/config.inc');
$db = pg_connect($conn_str);
$enc = pg_client_encoding($db);

View file

@ -3,11 +3,13 @@ PostgreSQL escape functions
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include 'config.inc';
include 'inc/config.inc';
$table_name = "table_08escape";
define('FILE_NAME', __DIR__ . '/php.gif');
// pg_escape_string() test
@ -42,6 +44,7 @@ else {
// Test using database
$data = file_get_contents(FILE_NAME);
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
// Insert binary to DB
$escaped_data = pg_escape_bytea($db, $data);
@ -97,6 +100,14 @@ else {
var_dump($expect);
}
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_08escape";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECTF--
Deprecated: pg_escape_string(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d

View file

@ -5,15 +5,15 @@ pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
_skip_lc_messages($conn);
?>
--FILE--
<?php
include 'config.inc';
include 'lcmess.inc';
include 'inc/config.inc';
include 'inc/lcmess.inc';
ini_set('pgsql.log_notice', TRUE);
ini_set('pgsql.ignore_notice', FALSE);

View file

@ -4,14 +4,14 @@ PostgreSQL pg_convert()
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
skip_bytea_not_escape();
?>
--FILE--
<?php
error_reporting(E_ALL);
include 'config.inc';
include 'inc/config.inc';
$db = pg_connect($conn_str);

View file

@ -4,16 +4,19 @@ PostgreSQL pg_convert() (9.0+)
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
skip_bytea_not_hex();
?>
--FILE--
<?php
error_reporting(E_ALL);
include 'config.inc';
include 'inc/config.inc';
$table_name = "table_10pg_convert_9";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
pg_query($db, "SET standard_conforming_strings = 0");
$fields = array('num'=>'1234', 'str'=>'AAA', 'bin'=>'BBB');
@ -49,6 +52,14 @@ try {
echo $e->getMessage(), \PHP_EOL;
}
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_10pg_convert_9";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
array(3) {
[""num""]=>

View file

@ -4,16 +4,18 @@ PostgreSQL pg_convert() and JSON/Array
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
skip_server_version('9.2');
?>
--FILE--
<?php
error_reporting(E_ALL);
include 'config.inc';
include 'inc/config.inc';
$table_name_92 = "table_10pg_convert_json_array_92";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name_92} (textary text[], jsn json)");
$fields = array(
'textary'=>'{"meeting", "lunch", "training", "presentation"}',
@ -28,6 +30,14 @@ if (!pg_insert($db, $table_name_92, $fields)) {
echo "OK\n";
}
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name_92 = "table_10pg_convert_json_array_92";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name_92}");
?>
--EXPECT--
array(2) {

View file

@ -3,19 +3,29 @@ PostgreSQL pg_metadata()
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
error_reporting(E_ALL);
include 'config.inc';
include 'inc/config.inc';
$table_name = "table_11pg_meta_data";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
$meta = pg_meta_data($db, $table_name);
var_dump($meta);
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_11pg_meta_data";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
array(3) {
["num"]=>

View file

@ -4,14 +4,14 @@ PostgreSQL pg_insert()
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
skip_bytea_not_escape();
?>
--FILE--
<?php
error_reporting(E_ALL);
include 'config.inc';
include 'inc/config.inc';
$db = pg_connect($conn_str);
$fields = array('num'=>'1234', 'str'=>'AAA', 'bin'=>'BBB');

View file

@ -4,16 +4,19 @@ PostgreSQL pg_insert() (9.0+)
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
skip_bytea_not_hex();
?>
--FILE--
<?php
error_reporting(E_ALL);
include 'config.inc';
include 'inc/config.inc';
$table_name = "table_12pg_insert_9";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
pg_query($db, "SET standard_conforming_strings = 0");
$fields = array('num'=>'1234', 'str'=>'AAA', 'bin'=>'BBB');
@ -53,9 +56,17 @@ try {
echo "Ok\n";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_12pg_insert_9";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECTF--
INSERT INTO "php_pgsql_test" ("num","str","bin") VALUES (1234,E'AAA',E'\\x424242');
INSERT INTO "php_pgsql_test" ("num","str","bin") VALUES ('1234','AAA','BBB');
INSERT INTO "table_12pg_insert_9" ("num","str","bin") VALUES (1234,E'AAA',E'\\x424242');
INSERT INTO "table_12pg_insert_9" ("num","str","bin") VALUES ('1234','AAA','BBB');
object(PgSql\Result)#%d (0) {
}
Array of values must be an associative array with string keys

View file

@ -4,14 +4,14 @@ PostgreSQL pg_select()
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
skip_server_version('8.5dev', '>=');
?>
--FILE--
<?php
error_reporting(E_ALL);
include 'config.inc';
include 'inc/config.inc';
$db = pg_connect($conn_str);
$fields = array('num'=>'1234', 'str'=>'ABC', 'bin'=>'XYZ');

View file

@ -4,19 +4,23 @@ PostgreSQL pg_select() (9.0+)
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
skip_server_version('9.0', '<');
?>
--FILE--
<?php
error_reporting(E_ALL);
include 'config.inc';
include 'inc/config.inc';
$table_name = "table_13pg_select_9";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
pg_query($db, "INSERT INTO {$table_name} VALUES(1234, 'AAA', 'BBB')");
pg_query($db, "INSERT INTO {$table_name} VALUES(1234, 'AAA', 'BBB')");
pg_query($db, "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";
@ -54,6 +58,14 @@ try {
echo "Ok\n";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_13pg_select_9";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
array(2) {
@ -76,8 +88,8 @@ array(2) {
string(8) "\x424242"
}
}
SELECT * FROM "php_pgsql_test" WHERE "num"=1234;
SELECT * FROM "php_pgsql_test" WHERE "num"='1234';
SELECT * FROM "table_13pg_select_9" WHERE "num"=1234;
SELECT * FROM "table_13pg_select_9" WHERE "num"='1234';
Array of values must be an associative array with string keys
Array of values must be an associative array with string keys
Values must be of type string|int|float|bool|null, array given

View file

@ -4,14 +4,14 @@ PostgreSQL pg_update()
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
skip_bytea_not_escape();
?>
--FILE--
<?php
error_reporting(E_ALL);
include 'config.inc';
include 'inc/config.inc';
$db = pg_connect($conn_str);
$fields = array('num'=>'1234', 'str'=>'ABC', 'bin'=>'XYZ');

View file

@ -4,16 +4,21 @@ PostgreSQL pg_update() (9.0+)
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
skip_bytea_not_hex();
?>
--FILE--
<?php
error_reporting(E_ALL);
include 'config.inc';
include 'inc/config.inc';
$table_name = "table_14pg_update_9";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
pg_query($db, "INSERT INTO {$table_name} VALUES(1, 'ABC', null)");
pg_query($db, "INSERT INTO {$table_name} VALUES(1, 'ABC', null)");
pg_query($db, "SET standard_conforming_strings = 0");
$fields = array('num'=>'1234', 'str'=>'ABC', 'bin'=>'XYZ');
@ -25,7 +30,15 @@ echo pg_update($db, $table_name, $fields, $ids, PGSQL_DML_STRING|PGSQL_DML_ESCAP
echo "Ok\n";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_14pg_update_9";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
UPDATE "php_pgsql_test" SET "num"=1234,"str"=E'ABC',"bin"=E'\\x58595a' WHERE "num"=1234;
UPDATE "php_pgsql_test" SET "num"='1234',"str"='ABC',"bin"='XYZ' WHERE "num"='1234';
UPDATE "table_14pg_update_9" SET "num"=1234,"str"=E'ABC',"bin"=E'\\x58595a' WHERE "num"=1234;
UPDATE "table_14pg_update_9" SET "num"='1234',"str"='ABC',"bin"='XYZ' WHERE "num"='1234';
Ok

View file

@ -3,14 +3,18 @@ PostgreSQL pg_delete()
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
error_reporting(E_ALL);
include 'config.inc';
include 'inc/config.inc';
$table_name = "table_15pg_delete";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
pg_query($db, "INSERT INTO {$table_name} VALUES(1, 'ABC', null)");
pg_query($db, "INSERT INTO {$table_name} VALUES(1, 'ABC', null)");
$fields = array('num'=>'1234', 'str'=>'XXX', 'bin'=>'YYY');
$ids = array('num'=>'1234');
@ -23,7 +27,15 @@ else {
echo "Ok\n";
}
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_15pg_delete";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
DELETE FROM "php_pgsql_test" WHERE "num"=1234;
DELETE FROM "php_pgsql_test" WHERE "num"='1234';
DELETE FROM "table_15pg_delete" WHERE "num"=1234;
DELETE FROM "table_15pg_delete" WHERE "num"='1234';
Ok

View file

@ -3,12 +3,14 @@ PostgreSQL pg_result_status()
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include 'config.inc';
include 'inc/config.inc';
$table_name = "table_16pg_result_status";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
$sql = "SELECT * FROM ".$table_name." WHERE num = -2";
$result = pg_query($db, "BEGIN;END");
@ -16,6 +18,14 @@ $result = pg_query($db, "BEGIN;END");
echo pg_result_status($result)."\n";
echo pg_result_status($result, PGSQL_STATUS_STRING)."\n";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_16pg_result_status";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
1
COMMIT

View file

@ -3,14 +3,18 @@ PostgreSQL pg_fetch_*() functions
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
error_reporting(E_ALL);
include 'config.inc';
include 'inc/config.inc';
$table_name = "table_17result";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
pg_query($db, "INSERT INTO {$table_name} VALUES(1, 'ABC', null)");
pg_query($db, "INSERT INTO {$table_name} VALUES(1, 'ABC', null)");
$sql = "SELECT * FROM $table_name ORDER BY num";
$result = pg_query($db, $sql) or die('Cannot query db');
@ -25,6 +29,14 @@ var_dump(pg_result_seek($result, 0));
echo "Ok\n";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_17result";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECTF--
bool(true)
object(stdClass)#%d (3) {

View file

@ -3,17 +3,20 @@ PostgreSQL pg_escape_bytea() functions (before connection)
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
// optional functions
include('config.inc');
include('inc/config.inc');
$table_name = "table_18pg_escape_bytea_before";
$image = file_get_contents(__DIR__ . '/php.gif');
$esc_image = pg_escape_bytea($image);
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
@pg_query($db, "SET bytea_output = 'escape'");
pg_query($db, 'INSERT INTO '.$table_name.' (num, bin) VALUES (9876, E\''.$esc_image.'\');');
@ -28,6 +31,14 @@ else {
echo "OK";
}
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_18pg_escape_bytea_before";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECTF--
Deprecated: pg_escape_bytea(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
OK

View file

@ -3,14 +3,17 @@ PostgreSQL pg_escape_bytea() functions (escape format)
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
// optional functions
include('config.inc');
include('inc/config.inc');
$table_name = "table_18pg_escape_bytea_esc";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
@pg_query($db, "SET bytea_output = 'escape'");
$image = file_get_contents(__DIR__ . '/php.gif');
@ -28,5 +31,13 @@ else {
echo "OK";
}
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_18pg_escape_bytea_esc";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
OK

View file

@ -4,16 +4,19 @@ PostgreSQL pg_escape_bytea() functions (hex format)
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
skip_bytea_not_hex();
?>
--FILE--
<?php
// optional functions
include('config.inc');
include('inc/config.inc');
$table_name = "table_18pg_escape_bytea_hex";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
@pg_query($db, "SET bytea_output = 'hex'");
$image = file_get_contents(__DIR__ . '/php.gif');
@ -31,5 +34,13 @@ else {
echo "OK";
}
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_18pg_escape_bytea_hex";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
OK

View file

@ -3,12 +3,12 @@ PostgreSQL pg_ping() functions
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
// optional functions
include('config.inc');
include('inc/config.inc');
$db = pg_connect($conn_str);
var_dump(pg_ping($db));

View file

@ -3,12 +3,12 @@ PostgreSQL pg_get_pid() functions
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
// optional functions
include('config.inc');
include('inc/config.inc');
$db = pg_connect($conn_str);
$pid = pg_get_pid($db);

View file

@ -3,12 +3,12 @@ PostgreSQL pg_get_notify() functions
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
// optional functions
include('config.inc');
include('inc/config.inc');
$db = pg_connect($conn_str);
pg_query($db, 'LISTEN test_msg');

View file

@ -3,12 +3,13 @@ PostgreSQL pg_fetch_object()
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
error_reporting(E_ALL);
include 'config.inc';
include 'inc/config.inc';
$table_name = "table_22pg_fetch_object";
class test_class {
function __construct($arg1, $arg2) {
@ -17,6 +18,8 @@ class test_class {
}
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
pg_query($db, "INSERT INTO {$table_name} VALUES(0, 'ABC', null)");
$sql = "SELECT * FROM $table_name WHERE num = 0";
$result = pg_query($db, $sql) or die('Cannot query db');
@ -32,6 +35,14 @@ try {
echo "Ok\n";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_22pg_fetch_object";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECTF--
test_class::__construct(1,2)
object(test_class)#%d (3) {

View file

@ -4,15 +4,19 @@ PostgreSQL sync query params
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
if (!function_exists('pg_query_params')) die('skip function pg_query_params() does not exist');
?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$table_name = "table_23sync_query_params";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
pg_query($db, "INSERT INTO {$table_name} (num) VALUES(1000)");
$result = pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100));
if (!($rows = pg_num_rows($result)))
{
@ -39,7 +43,7 @@ pg_result_error($result);
pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
pg_field_name($result, 0);
pg_field_num($result, $field_name);
pg_field_num($result, "num");
pg_field_size($result, 0);
pg_field_type($result, 0);
pg_field_prtlen($result, null, 0);
@ -53,5 +57,13 @@ pg_close($db);
echo "OK";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_23sync_query_params";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
OK

View file

@ -4,15 +4,18 @@ PostgreSQL sync prepared queries
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
if (!function_exists('pg_prepare')) die('skip function pg_prepare() does not exist');
?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$table_name = "table_24sync_query_prepared";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
pg_query($db, "INSERT INTO {$table_name} (num) VALUES(1000)");
$result = pg_prepare($db, "php_test", "SELECT * FROM ".$table_name." WHERE num > \$1;");
pg_result_error($result);
@ -43,7 +46,7 @@ pg_result_error($result);
pg_num_rows(pg_execute($db, "php_test", array(100)));
pg_num_fields(pg_execute($db, "php_test", array(100)));
pg_field_name($result, 0);
pg_field_num($result, $field_name);
pg_field_num($result, "num");
pg_field_size($result, 0);
pg_field_type($result, 0);
pg_field_prtlen($result, 0);
@ -60,5 +63,13 @@ pg_close($db);
echo "OK";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_24sync_query_prepared";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
OK

View file

@ -4,15 +4,19 @@ PostgreSQL async query params
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
if (!function_exists('pg_send_query_params')) die('skip function pg_send_query_params() does not exist');
?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$table_name = "table_25async_query_params";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
pg_query($db, "INSERT INTO {$table_name} (num) VALUES(1000)");
if (!pg_send_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100))) {
echo "pg_send_query_params() error\n";
}
@ -47,7 +51,7 @@ for ($i=0; $i < $rows; $i++)
pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
pg_field_name($result, 0);
pg_field_num($result, $field_name);
pg_field_num($result, "num");
pg_field_size($result, 0);
pg_field_type($result, 0);
pg_field_prtlen($result, 0);
@ -64,5 +68,13 @@ pg_close($db);
echo "OK";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_25async_query_params";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
OK

View file

@ -4,15 +4,19 @@ PostgreSQL async prepared queries
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
if (!function_exists('pg_send_prepare')) die('skip function pg_send_prepare() does not exist');
?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$table_name = "table_26async_query_prepared";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
pg_query($db, "INSERT INTO {$table_name} (num) VALUES(1000)");
if (!pg_send_prepare($db, 'php_test', "SELECT * FROM ".$table_name." WHERE num > \$1;")) {
echo "pg_send_prepare() error\n";
}
@ -61,7 +65,7 @@ for ($i=0; $i < $rows; $i++)
pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
pg_field_name($result, 0);
pg_field_num($result, $field_name);
pg_field_num($result, "num");
pg_field_size($result, 0);
pg_field_type($result, 0);
pg_field_prtlen($result, 0);
@ -100,5 +104,13 @@ pg_close($db);
echo "OK";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_26async_query_prepared";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
OK

View file

@ -4,7 +4,7 @@ PostgreSQL create large object with given oid
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
$v = pg_version($conn);
if (version_compare("8.3", $v["client"]) > 0) die("skip - requires pg client >= 8.3\n");
if (version_compare("8.3", $v["server"]) > 0) die("skip - requires pg server >= 8.3\n");
@ -12,33 +12,33 @@ if (version_compare("8.3", $v["server"]) > 0) die("skip - requires pg server >=
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$db = pg_connect($conn_str);
echo "create LO from int\n";
pg_exec ($db, "begin");
pg_exec ($db, "BEGIN");
$oid = pg_lo_create ($db, 21000);
if (!$oid) echo ("pg_lo_create() error\n");
if ($oid != 21000) echo ("pg_lo_create() wrong id\n");
pg_lo_unlink ($db, $oid);
pg_exec ($db, "commit");
pg_exec ($db, "COMMIT");
echo "create LO from string\n";
pg_exec ($db, "begin");
pg_exec ($db, "BEGIN");
$oid = pg_lo_create ($db, "21001");
if (!$oid) echo ("pg_lo_create() error\n");
if ($oid != 21001) echo ("pg_lo_create() wrong id\n");
pg_lo_unlink ($db, $oid);
pg_exec ($db, "commit");
pg_exec ($db, "COMMIT");
echo "create LO using default connection\n";
pg_exec ("begin");
pg_exec ("BEGIN");
$oid = pg_lo_create (21002);
if (!$oid) echo ("pg_lo_create() error\n");
if ($oid != 21002) echo ("pg_lo_create() wrong id\n");
pg_lo_unlink ($oid);
pg_exec ("commit");
pg_exec ("COMMIT");
echo "OK";
?>

View file

@ -4,7 +4,7 @@ PostgreSQL import large object with given oid
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
$v = pg_version($conn);
if (version_compare("8.4devel", $v["client"]) > 0) die("skip - requires pg client >= 8.4\n");
if (version_compare("8.4devel", $v["server"]) > 0) die("skip - requires pg server >= 8.4\n");
@ -12,33 +12,33 @@ if (version_compare("8.4devel", $v["server"]) > 0) die("skip - requires pg serve
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$db = pg_connect($conn_str);
echo "import LO from int\n";
pg_exec($db, 'begin');
pg_exec($db, 'BEGIN');
$oid = pg_lo_import($db, __FILE__, 21003);
if (!$oid) echo ("pg_lo_import() error\n");
if ($oid != 21003) echo ("pg_lo_import() wrong id\n");
pg_lo_unlink ($db, $oid);
pg_exec($db, 'commit');
pg_exec($db, 'COMMIT');
echo "import LO from string\n";
pg_exec($db, 'begin');
pg_exec($db, 'BEGIN');
$oid = pg_lo_import($db, __FILE__, "21004");
if (!$oid) echo ("pg_lo_import() error\n");
if ($oid != 21004) echo ("pg_lo_import() wrong id\n");
pg_lo_unlink ($db, $oid);
pg_exec($db, 'commit');
pg_exec($db, 'COMMIT');
echo "import LO using default connection\n";
pg_exec('begin');
pg_exec('BEGIN');
$oid = pg_lo_import($db, __FILE__, 21005);
if (!$oid) echo ("pg_lo_import() error\n");
if ($oid != 21005) echo ("pg_lo_import() wrong id\n");
pg_lo_unlink ($oid);
pg_exec('commit');
pg_exec('COMMIT');
/* Invalide OID */
try {

View file

@ -4,13 +4,13 @@ PostgreSQL non-blocking async connect
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
?>
--FILE--
<?php
include('config.inc');
include('nonblocking.inc');
include('inc/config.inc');
include('inc/nonblocking.inc');
if (!$db = pg_connect($conn_str, PGSQL_CONNECT_ASYNC)) {
die("pg_connect() error");

View file

@ -4,16 +4,20 @@ PostgreSQL non-blocking async query params
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
if (!function_exists('pg_send_query_params')) die('skip function pg_send_query_params() does not exist');
?>
--FILE--
<?php
include('config.inc');
include('nonblocking.inc');
include('inc/config.inc');
include('inc/nonblocking.inc');
$table_name = "table_30nb_async_query_params";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
pg_query($db, "INSERT INTO {$table_name} (num) VALUES(1000)");
$db_socket = pg_socket($db);
stream_set_blocking($db_socket, false);
@ -48,7 +52,7 @@ for ($i=0; $i < $rows; $i++) {
pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
pg_field_name($result, 0);
pg_field_num($result, $field_name);
pg_field_num($result, "num");
pg_field_size($result, 0);
pg_field_type($result, 0);
pg_field_prtlen($result, 0);
@ -69,5 +73,13 @@ pg_close($db);
echo "OK";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_30nb_async_query_params";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
OK

View file

@ -4,16 +4,20 @@ PostgreSQL non-blocking async prepared queries
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
if (!function_exists('pg_send_prepare')) die('skip function pg_send_prepare() does not exist');
?>
--FILE--
<?php
include('config.inc');
include('nonblocking.inc');
include('inc/config.inc');
include('inc/nonblocking.inc');
$table_name = "table_31nb_async_query_prepared";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
pg_query($db, "INSERT INTO {$table_name} (num) VALUES(1000)");
$db_socket = pg_socket($db);
stream_set_blocking($db_socket, false);
@ -63,7 +67,7 @@ for ($i=0; $i < $rows; $i++) {
pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
pg_field_name($result, 0);
pg_field_num($result, $field_name);
pg_field_num($result, "num");
pg_field_size($result, 0);
pg_field_type($result, 0);
pg_field_prtlen($result, 0);
@ -102,5 +106,13 @@ pg_close($db);
echo "OK";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_31nb_async_query_prepared";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
OK

View file

@ -4,16 +4,20 @@ PostgreSQL non-blocking async queries
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
if (!function_exists('pg_send_prepare')) die('skip function pg_send_prepare() does not exist');
?>
--FILE--
<?php
include('config.inc');
include('nonblocking.inc');
include('inc/config.inc');
include('inc/nonblocking.inc');
$table_name = "table_32nb_async_query";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
pg_query($db, "INSERT INTO {$table_name} DEFAULT VALUES");
$db_socket = pg_socket($db);
stream_set_blocking($db_socket, false);
@ -49,7 +53,7 @@ for ($i=0; $i < $rows; $i++) {
pg_num_rows(pg_query($db, "SELECT * FROM ".$table_name.";"));
pg_num_fields(pg_query($db, "SELECT * FROM ".$table_name.";"));
pg_field_name($result, 0);
pg_field_num($result, $field_name);
pg_field_num($result, "num");
pg_field_size($result, 0);
pg_field_type($result, 0);
pg_field_prtlen($result, null, 0);
@ -74,5 +78,13 @@ pg_close($db);
echo "OK";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_32nb_async_query";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
OK

View file

@ -7,11 +7,11 @@ pgsql
<?php
require_once dirname(__DIR__, 2) . '/dba/tests/setup/setup_dba_tests.inc';
check_skip_any();
require_once('skipif.inc');
require_once('inc/skipif.inc');
?>
--FILE--
<?php
require_once('config.inc');
require_once('inc/config.inc');
$dbh = @pg_connect($conn_str);
if (!$dbh) {

View file

@ -4,24 +4,23 @@ Bug #24499 (Notice: Undefined property: stdClass::)
pgsql
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('inc/skipif.inc');
?>
--FILE--
<?php
require_once('config.inc');
require_once('inc/config.inc');
$table_name = 'table_80_bug24499';
$dbh = @pg_connect($conn_str);
if (!$dbh) {
die ("Could not connect to the server");
}
@pg_query($dbh, "DROP SEQUENCE id_id_seq");
@pg_query($dbh, "DROP TABLE id");
pg_query($dbh, "CREATE TABLE id (id SERIAL, t INT)");
pg_query($dbh, "CREATE TABLE {$table_name} (id SERIAL, t INT)");
for ($i=0; $i<4; $i++) {
pg_query($dbh, "INSERT INTO id (t) VALUES ($i)");
pg_query($dbh, "INSERT INTO {$table_name} (t) VALUES ($i)");
}
class Id
@ -31,8 +30,9 @@ class Id
public function getId()
{
global $dbh;
global $table_name;
$q = pg_query($dbh, "SELECT id FROM id");
$q = pg_query($dbh, "SELECT id FROM {$table_name}");
print_r(pg_fetch_array($q));
print_r(pg_fetch_array($q));
$id = pg_fetch_object($q);
@ -48,6 +48,14 @@ pg_close($dbh);
echo "Done\n";
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$table_name = 'table_80_bug24499';
$dbh = pg_connect($conn_str);
pg_query($dbh, "DROP TABLE IF EXISTS {$table_name} CASCADE");
?>
--EXPECTF--
Array

View file

@ -4,23 +4,23 @@ Bug #27597 (pg_fetch_array not returning false)
pgsql
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('inc/skipif.inc');
?>
--FILE--
<?php
require_once(__DIR__ . '/config.inc');
require_once(__DIR__ . '/inc/config.inc');
$table_name = 'table_80_bug27597';
$dbh = @pg_connect($conn_str);
if (!$dbh) {
die ("Could not connect to the server");
}
@pg_query($dbh, "DROP TABLE id");
pg_query($dbh, "CREATE TABLE id (id INT)");
pg_query($dbh, "CREATE TABLE {$table_name} (id INT)");
for ($i=0; $i<4; $i++) {
pg_query($dbh, "INSERT INTO id (id) VALUES ($i)");
pg_query($dbh, "INSERT INTO {$table_name} (id) VALUES ($i)");
}
function xi_fetch_array($res, $type = PGSQL_ASSOC) {
@ -28,7 +28,7 @@ function xi_fetch_array($res, $type = PGSQL_ASSOC) {
return $a ;
}
$res = pg_query($dbh, "SELECT * FROM id");
$res = pg_query($dbh, "SELECT * FROM {$table_name}");
$i = 0; // endless-loop protection
while($row = xi_fetch_array($res)) {
print_r($row);
@ -40,6 +40,14 @@ while($row = xi_fetch_array($res)) {
pg_close($dbh);
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$table_name = 'table_80_bug27597';
$dbh = pg_connect($conn_str);
pg_query($dbh, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
Array

View file

@ -4,7 +4,7 @@ Bug #32223 (weird behaviour of pg_last_notice)
pgsql
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('inc/skipif.inc');
_skip_lc_messages($conn);
@ -22,8 +22,8 @@ pgsql.ignore_notice=0
--FILE--
<?php
require_once('config.inc');
require_once('lcmess.inc');
require_once('inc/config.inc');
require_once('inc/lcmess.inc');
$dbh = @pg_connect($conn_str);
if (!$dbh) {

View file

@ -4,7 +4,7 @@ Bug #32223 (weird behaviour of pg_last_notice using define)
pgsql
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('inc/skipif.inc');
_skip_lc_messages($conn);
@ -22,8 +22,8 @@ pgsql.ignore_notice=0
--FILE--
<?php
require_once('config.inc');
require_once('lcmess.inc');
require_once('inc/config.inc');
require_once('inc/lcmess.inc');
$dbh = pg_connect($conn_str);
if (!$dbh) {

View file

@ -4,12 +4,12 @@ Bug #36625 (8.0+) (pg_trace() does not work)
pgsql
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('inc/skipif.inc');
?>
--FILE--
<?php
require_once('config.inc');
require_once('inc/config.inc');
$dbh = @pg_connect($conn_str);
if (!$dbh) {
@ -22,14 +22,14 @@ $tracefile = __DIR__ . '/trace.tmp';
var_dump(file_exists($tracefile));
pg_trace($tracefile, 'w', $dbh);
$res = pg_query($dbh, 'select 1');
$res = pg_query($dbh, 'SELECT 1');
var_dump($res);
pg_close($dbh);
$found = 0;
function search_trace_file($line)
{
if (strpos($line, '"select 1"') !== false || strpos($line, "'select 1'") !== false) {
if (strpos($line, '"SELECT 1"') !== false || strpos($line, "'SELECT 1'") !== false) {
$GLOBALS['found']++;
}
}

View file

@ -4,29 +4,34 @@ Bug #39971 (8.0+) (pg_insert/pg_update do not allow now() to be used for timesta
pgsql
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('inc/skipif.inc');
?>
--FILE--
<?php
require_once('config.inc');
require_once('inc/config.inc');
$table_name = 'table_80_bug39971';
$dbh = @pg_connect($conn_str);
if (!$dbh) {
die ("Could not connect to the server");
}
$dbh = pg_connect($conn_str);
pg_query($dbh, "CREATE TABLE php_test (id SERIAL, tm timestamp NOT NULL)");
pg_query($dbh, "CREATE TABLE {$table_name} (id SERIAL, tm timestamp NOT NULL)");
$values = array('tm' => 'now()');
pg_insert($dbh, 'php_test', $values);
pg_insert($dbh, $table_name, $values);
$ids = array('id' => 1);
pg_update($dbh, 'php_test', $values, $ids);
pg_update($dbh, $table_name, $values, $ids);
pg_query($dbh, "DROP TABLE php_test");
pg_close($dbh);
?>
===DONE===
--CLEAN--
<?php
require_once('inc/config.inc');
$table_name = 'table_80_bug39971';
$dbh = pg_connect($conn_str);
pg_query($dbh, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
===DONE===

View file

@ -4,27 +4,35 @@ Bug #42783 (pg_insert() does not support an empty value array)
pgsql
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('inc/skipif.inc');
?>
--FILE--
<?php
require_once('config.inc');
require_once('inc/config.inc');
$table_name = 'table_80_bug42783';
$dbh = @pg_connect($conn_str);
if (!$dbh) {
die ("Could not connect to the server");
}
pg_query($dbh, "CREATE TABLE php_test (id SERIAL PRIMARY KEY, time TIMESTAMP NOT NULL DEFAULT now())");
pg_query($dbh, "CREATE TABLE {$table_name} (id SERIAL PRIMARY KEY, time TIMESTAMP NOT NULL DEFAULT now())");
pg_insert($dbh, 'php_test', array());
pg_insert($dbh, $table_name, array());
var_dump(pg_fetch_assoc(pg_query($dbh, "SELECT * FROM php_test")));
var_dump(pg_fetch_assoc(pg_query($dbh, "SELECT * FROM {$table_name}")));
pg_query($dbh, "DROP TABLE php_test");
pg_close($dbh);
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$table_name = 'table_80_bug42783';
$dbh = pg_connect($conn_str);
pg_query($dbh, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECTF--
array(2) {
["id"]=>

View file

@ -3,13 +3,17 @@ PostgreSQL old api
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$table_name = "table_98old_api";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
pg_query($db, "INSERT INTO {$table_name} DEFAULT VALUES");
$result = pg_exec($db, "SELECT * FROM ".$table_name);
pg_numrows($result);
pg_numfields($result);
@ -30,10 +34,16 @@ pg_errormessage($db);
$result = pg_exec($db, "UPDATE ".$table_name." SET str = 'QQQ' WHERE str like 'RGD';");
pg_cmdtuples($result);
echo "OK";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_98old_api";
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECTF--
Deprecated: Function pg_numrows() is deprecated in %s on line %d

View file

@ -3,20 +3,41 @@ PostgreSQL drop db
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
// drop test table
include('config.inc');
include('inc/config.inc');
$table_name = "table_9999dropdb";
$table_name_92 = "table_9999dropdb_92";
$view_name = "view_9999dropdb";
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)");
pg_query($db, "CREATE TABLE {$table_name_92} (textary text[], jsn json)");
pg_query($db, "CREATE VIEW {$view_name} as SELECT * FROM {$table_name}");
pg_query($db, "DROP VIEW {$view_name}");
pg_query($db, "DROP TABLE ".$table_name);
@pg_query($db, "DROP TABLE ".$table_name_92);
pg_query($db, "DROP TABLE {$table_name}");
pg_query($db, "DROP TABLE {$table_name_92}");
echo "OK";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "table_9999dropdb";
$table_name_92 = "table_9999dropdb_92";
$view_name = "view_9999dropdb";
$db = pg_connect($conn_str);
pg_query($db, "DROP VIEW IF EXISTS {$view_name}");
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
pg_query($db, "DROP TABLE IF EXISTS {$table_name_92}");
?>
--EXPECT--
OK

View file

@ -4,29 +4,28 @@ Bug #37100 (data is returned truncated with BINARY CURSOR)
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
skip_bytea_not_escape();
?>
--FILE--
<?php
include 'config.inc';
include 'inc/config.inc';
$table_name = 'table_bug37100';
$db = pg_connect($conn_str);
@pg_query("SET bytea_output = 'escape'");
@pg_query('DROP TABLE test_bug');
pg_query('CREATE TABLE test_bug (binfield byteA) ;');
pg_query("INSERT INTO test_bug VALUES (decode('0103AA000812','hex'))");
pg_query("CREATE TABLE {$table_name} (binfield byteA) ;");
pg_query("INSERT INTO {$table_name} VALUES (decode('0103AA000812','hex'))");
$data = pg_query("SELECT binfield FROM test_bug");
$data = pg_query("SELECT binfield FROM {$table_name}");
$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;";
$sql = "BEGIN; DECLARE mycursor BINARY CURSOR FOR SELECT binfield FROM {$table_name}; FETCH ALL IN mycursor;";
$data = pg_query($sql);
$res = pg_fetch_result($data,0);
@ -35,12 +34,14 @@ var_dump(strlen($res));
var_dump(bin2hex($res));
pg_close($db);
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$table_name = 'table_bug37100';
$db = pg_connect($conn_str);
pg_query('DROP TABLE test_bug');
pg_close($db);
pg_query("DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
string(24) "\001\003\252\000\010\022"

View file

@ -4,28 +4,27 @@ Bug #37100 (data is returned truncated with BINARY CURSOR) (9.0+)
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
skip_bytea_not_hex();
?>
--FILE--
<?php
include 'config.inc';
include 'inc/config.inc';
$table_name = 'table_bug37100_9';
$db = pg_connect($conn_str);
@pg_query($db, 'DROP TABLE test_bug');
pg_query($db, 'CREATE TABLE test_bug (binfield byteA) ;');
pg_query($db, "INSERT INTO test_bug VALUES (decode('0103AA000812','hex'))");
pg_query($db, "CREATE TABLE {$table_name} (binfield byteA) ;");
pg_query($db, "INSERT INTO {$table_name} VALUES (decode('0103AA000812','hex'))");
$data = pg_query($db, "SELECT binfield FROM test_bug");
$data = pg_query($db, "SELECT binfield FROM {$table_name}");
$res = pg_fetch_result($data, null, 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;";
$sql = "BEGIN; DECLARE mycursor BINARY CURSOR FOR SELECT binfield FROM {$table_name}; FETCH ALL IN mycursor;";
$data = pg_query($db, $sql);
$res = pg_fetch_result($data, null, 0);
@ -36,10 +35,17 @@ var_dump(bin2hex($res));
pg_close($db);
$db = pg_connect($conn_str);
pg_query($db, 'DROP TABLE test_bug');
pg_close($db);
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$table_name = 'table_bug37100_9';
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
string(14) "\x0103aa000812"

View file

@ -4,7 +4,7 @@ Bug #46408 (Locale number format settings can cause pg_query_params to break wit
pgsql
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('inc/skipif.inc');
if (false === setlocale(LC_ALL, "de", "de_DE", "de_DE.ISO8859-1", "de_DE.ISO_8859-1", "de_DE.UTF-8")) {
echo "skip Locale de-DE not present";
}
@ -12,7 +12,7 @@ if (false === setlocale(LC_ALL, "de", "de_DE", "de_DE.ISO8859-1", "de_DE.ISO_885
--FILE--
<?php
require_once('config.inc');
require_once('inc/config.inc');
$dbh = pg_connect($conn_str);
setlocale(LC_ALL, "de", "de_DE", "de_DE.ISO8859-1", "de_DE.ISO_8859-1", "de_DE.UTF-8");

View file

@ -4,16 +4,15 @@ Bug #47199 (pg_delete fails on NULL)
pgsql
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('inc/skipif.inc');
?>
--FILE--
<?php
require_once('config.inc');
require_once('inc/config.inc');
$dbh = pg_connect($conn_str);
$tbl_name = 'test_47199';
@pg_query($dbh, "DROP TABLE $tbl_name");
pg_query($dbh, "CREATE TABLE $tbl_name (null_field INT, not_null_field INT NOT NULL)");
pg_insert($dbh, $tbl_name, array('null_field' => null, 'not_null_field' => 1));
@ -31,11 +30,18 @@ echo $query, "\n";
var_dump(pg_fetch_all(pg_query($dbh, 'SELECT * FROM '. $tbl_name)));
@pg_query($dbh, "DROP TABLE $tbl_name");
pg_close($dbh);
echo PHP_EOL."Done".PHP_EOL;
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$dbh = pg_connect($conn_str);
$tbl_name = 'test_47199';
pg_query($dbh, "DROP TABLE IF EXISTS $tbl_name");
?>
--EXPECT--
array(2) {

View file

@ -4,15 +4,15 @@ Bug #60244 (pg_fetch_* functions do not validate that row param is >0)
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
?>
--FILE--
<?php
include 'config.inc';
include 'inc/config.inc';
$db = pg_connect($conn_str);
$result = pg_query($db, "select 'a' union select 'b'");
$result = pg_query($db, "SELECT 'a' UNION SELECT 'b'");
try {
var_dump(pg_fetch_array($result, -1));

View file

@ -4,22 +4,24 @@ Bug #64609 (pg_convert enum type support)
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
skip_server_version('8.3', '<');
?>
--FILE--
<?php
error_reporting(E_ALL);
include 'config.inc';
include 'inc/config.inc';
$table_name = 'table_bug64609';
$type_name = 'type_bug64609';
$db = pg_connect($conn_str);
pg_query($db, "BEGIN");
pg_query($db, "CREATE TYPE t_enum AS ENUM ('ok', 'ko')");
pg_query($db, "CREATE TABLE test_enum (a t_enum)");
pg_query($db, "CREATE TYPE {$type_name} AS ENUM ('ok', 'ko')");
pg_query($db, "CREATE TABLE {$table_name} (a {$type_name})");
$fields = array('a' => 'ok');
$converted = pg_convert($db, 'test_enum', $fields);
$converted = pg_convert($db, $table_name, $fields);
pg_query($db, "ROLLBACK");

View file

@ -4,18 +4,20 @@ Bug #65119 (pg_copy_from() modifies input array variable)
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
?>
--FILE--
<?php
include 'config.inc';
include 'inc/config.inc';
$table_name = 'table_bug65119';
function test(Array $values, $conn_str) {
global $table_name;
$connection = pg_pconnect($conn_str, PGSQL_CONNECT_FORCE_NEW);
pg_query($connection, "begin");
pg_query($connection, "CREATE TABLE bug65119 (i INTEGER)");
pg_copy_from($connection, "bug65119", $values, "\t", "NULL");
pg_query($connection, "rollback");
pg_query($connection, "BEGIN");
pg_query($connection, "CREATE TABLE {$table_name} (i INTEGER)");
pg_copy_from($connection, $table_name, $values, "\t", "NULL");
pg_query($connection, "ROLLBACK");
}
$values = Array(1,2,3);

View file

@ -3,11 +3,11 @@ Bug #68638 pg_update() fails to store infinite values
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$conn = pg_connect($conn_str);
@ -30,8 +30,15 @@ while ($row = pg_fetch_assoc($rs)) {
var_dump($row);
}
pg_query($conn, "DROP TABLE $table");
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$conn = pg_connect($conn_str);
$table='test_68638';
pg_query($conn, "DROP TABLE IF EXISTS $table");
?>
--EXPECT--
string(52) "UPDATE "test_68638" SET "value"=E'inf' WHERE "id"=1;"

View file

@ -3,11 +3,11 @@ Bug #71062 pg_convert() doesn't accept ISO 8601 for datatype timestamp
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$db = pg_connect($conn_str);
@ -30,10 +30,16 @@ pg_convert($db, $table, ['test_field' => $date_string_modified_iso8601]);
print "done\n";
pg_query($db, "DROP TABLE $table");
?>
==OK==
--CLEAN--
<?php
require_once('inc/config.inc');
$db = @pg_connect($conn_str);
$table = "public.test_table_bug71062_bug71062";
pg_query($db, "DROP TABLE IF EXISTS $table");
?>
--EXPECT--
trying format Y-m-d\TH:i:sO
trying format Y-m-d H:i:sO

View file

@ -3,17 +3,18 @@ Bug #71998 Function pg_insert does not insert when column type = inet
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
// Kudos for the IP regex to
// http://stackoverflow.com/a/17871737/3358424
include('config.inc');
include('inc/config.inc');
$table_name = 'table_bug71998';
$db = pg_connect($conn_str);
pg_query($db, "CREATE TABLE tmp_statistics (id integer NOT NULL, remote_addr inet);");
pg_query($db, "CREATE TABLE {$table_name} (id integer NOT NULL, remote_addr inet);");
$ips = array(
/* IPv4*/
@ -59,7 +60,7 @@ foreach ($ips as $ip) {
$data = array("id" => ++$i, "remote_addr" => $ip);
$r = true;
try {
@pg_insert($db, 'tmp_statistics', $data);
@pg_insert($db, $table_name, $data);
} catch (\ValueError $e) {
echo $e->getMessage() . PHP_EOL;
$r = false;
@ -70,19 +71,27 @@ foreach ($ips as $ip) {
//echo pg_last_error($db);
}
//pg_query($db, "INSERT INTO tmp_statistics (id, remote_addr) VALUES (2, '127.0.0.1')"); // OK, record inserted
//pg_query($db, "INSERT INTO {$table_name} (id, remote_addr) VALUES (2, '127.0.0.1')"); // OK, record inserted
}
$r = pg_query($db, "SELECT * FROM tmp_statistics");
$r = pg_query($db, "SELECT * FROM {$table_name}");
while (false != ($row = pg_fetch_row($r))) {
var_dump($row);
}
echo $errors, " errors caught\n";
pg_query($db, "DROP TABLE tmp_statistics");
pg_close($db);
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$table_name = 'table_bug71998';
$db = @pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
pg_insert(): Field "remote_addr" must be a valid IPv4 or IPv6 address string, "256.257.258.259" given

View file

@ -3,16 +3,16 @@ Bug #72028 pg_query_params(): NULL converts to empty string
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
// create test table
include('config.inc');
include('inc/config.inc');
$conn = pg_connect($conn_str);
$table = "bug72028_" . md5(uniqid(time()));
$table = "bug72028";
pg_query($conn, "CREATE TABLE $table (value TEXT, details TEXT);");
@ -33,9 +33,14 @@ $r = pg_query($conn, "SELECT * FROM $table");
while (false !== ($i = pg_fetch_assoc($r))) {
var_dump($i);
}
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$table = "bug72028";;
$conn = pg_connect($conn_str);
pg_query($conn, "DROP TABLE $table");
pg_query($conn, "DROP TABLE IF EXISTS $table");
?>
--EXPECT--
array(2) {

View file

@ -3,7 +3,7 @@ Bug #72195 (pg_pconnect/pg_connect cause use-after-free)
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
$val = [];

View file

@ -3,7 +3,7 @@ Bug #72197 pg_lo_create arbitrary read
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
/* This shouldn't crash. */
@ -16,7 +16,7 @@ try {
}
/* This should work correctly. */
include('config.inc');
include('inc/config.inc');
/* Check with explicit link. */
$conn = pg_connect($conn_str);

View file

@ -3,10 +3,10 @@ Bug #75419 Default link leaked via pg_close()
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$db1 = pg_connect($conn_str, PGSQL_CONNECT_FORCE_NEW);
$db2 = pg_connect($conn_str, PGSQL_CONNECT_FORCE_NEW);

View file

@ -3,10 +3,10 @@ Bug #76548 pg_fetch_result did not fetch the next row
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$conn = pg_connect($conn_str);

View file

@ -4,41 +4,49 @@ Bug #77047 pg_insert has a broken regex for the 'TIME WITHOUT TIMEZONE' data typ
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
?>
--FILE--
<?php
error_reporting(E_ALL);
include 'config.inc';
include 'inc/config.inc';
$table_name = 'table_bug77047';
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS bug77047");
pg_query($db, "CREATE TABLE bug77047 (
pg_query($db, "CREATE TABLE {$table_name} (
t TIME WITHOUT TIME ZONE
)");
try {
pg_insert($db, "bug77047", array("t" => "13:31"));
pg_insert($db, $table_name, array("t" => "13:31"));
} catch (\TypeError $e) {
echo $e->getMessage();
}
pg_insert($db, "bug77047", array("t" => "13:31:13"));
pg_insert($db, "bug77047", array("t" => "1:2:3"));
pg_insert($db, $table_name, array("t" => "13:31:13"));
pg_insert($db, $table_name, array("t" => "1:2:3"));
try {
pg_insert($db, "bug77047", array("t" => "xyz"));
pg_insert($db, $table_name, array("t" => "xyz"));
} catch (\TypeError $e) {
echo $e->getMessage() . PHP_EOL;
}
pg_insert($db, "bug77047", array("t" => NULL));
pg_insert($db, "bug77047", array("t" => ""));
pg_insert($db, $table_name, array("t" => NULL));
pg_insert($db, $table_name, array("t" => ""));
$res = pg_query($db, "SELECT t FROM bug77047");
$res = pg_query($db, "SELECT t FROM {$table_name}");
while (false !== ($row = pg_fetch_row($res))) {
var_dump(array_pop($row));
}
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$table_name = 'table_bug77047';
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECTF--
pg_insert(): Field "t" must be of type string|null, time given

View file

@ -3,10 +3,10 @@ Bug #81720 (Uninitialized array in pg_query_params() leading to RCE)
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$conn = pg_connect($conn_str);

View file

@ -3,10 +3,10 @@ pg_close() default link after connection variable has been dropped
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
/* Run me under valgrind */
$db1 = pg_connect($conn_str);

View file

@ -1,23 +0,0 @@
<?php
// These vars are used to connect db and create test table.
// values can be set to meet your environment with the
// environment var PGSQL_TEST_CONNSTR
// "test" database must exist. i.e. "createdb test" before testing
$conn_str = getenv('PGSQL_TEST_CONNSTR') ?: "host=localhost dbname=test port=5432 user=postgres password=postgres"; // connection string
$table_name = "php_pgsql_test"; // test table that will be created
$table_name_92 = "php_pgsql_test_92"; // test table that will be created
$num_test_record = 1000; // Number of records to create
// Test view
$view_name = "php_pgsql_viewtest";
$view_def = "CREATE VIEW {$view_name} AS SELECT * FROM {$table_name};";
// Test table
$table_def = "CREATE TABLE {$table_name} (num int, str text, bin bytea);";
$table_def_92 = "CREATE TABLE {$table_name_92} (textary text[], jsn json);";
$field_name = "num"; // For pg_field_num()
?>

View file

@ -3,10 +3,10 @@ Reopen connection after it was closed
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
/* Run me under valgrind */
$db1 = pg_connect($conn_str);

View file

@ -3,10 +3,10 @@ Reusing connection with same connection string
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$db1 = pg_connect($conn_str);
$db2 = pg_connect($conn_str);

View file

@ -3,11 +3,11 @@ PostgreSQL fetching default link automatically is deprecated
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$db = pg_connect($conn_str);
// We don't care about warnings

View file

@ -4,17 +4,17 @@ GH-10672 (pg_lo_open segfaults in the strict_types mode)
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
?>
--FILE--
<?php
declare(strict_types=1);
include "config.inc";
include "inc/config.inc";
$table_name = 'table_gh10672';
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS gh10672");
pg_query($db, "CREATE TABLE gh10672 (bar text);");
pg_query($db, "CREATE TABLE {$table_name} (bar text);");
// Begin a transaction
pg_query($db, 'BEGIN');
@ -35,5 +35,13 @@ if ($oid === false) {
echo 'The large object has been opened successfully.', PHP_EOL;
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$table_name = 'table_gh10672';
$dbh = pg_connect($conn_str);
pg_query($dbh, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
The large object has been opened successfully.

View file

@ -4,23 +4,31 @@ pg_insert() fails for references
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
?>
--FILE--
<?php
include "config.inc";
include "inc/config.inc";
$table_name = 'table_gh8253';
function fee(&$a) {}
$a = ["bar" => "testing"];
fee($a["bar"]);
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS gh8253");
pg_query($db, "CREATE TABLE gh8253 (bar text);");
pg_insert($db, "gh8253", $a);
$res = pg_query($db, "SELECT * FROM gh8253");
pg_query($db, "CREATE TABLE {$table_name} (bar text);");
pg_insert($db, $table_name, $a);
$res = pg_query($db, "SELECT * FROM {$table_name}");
var_dump(pg_fetch_all($res));
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$table_name = 'table_gh8253';
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECT--
array(1) {
[0]=>

View file

@ -0,0 +1,9 @@
<?php
// These vars are used to connect db.
// values can be set to meet your environment with the
// environment var PGSQL_TEST_CONNSTR
// "test" database must exist. i.e. "createdb test" before testing
$conn_str = getenv('PGSQL_TEST_CONNSTR') ?: "host=localhost dbname=test port=5432 user=postgres password=postgres"; // connection string
?>

View file

@ -3,52 +3,62 @@ PostgreSQL pg_delete() - basic test using schema
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$schema_name = 'schema_pg_delete_001';
$table_name = 'table_pg_delete_001';
$conn = pg_connect($conn_str);
pg_query($conn, 'CREATE SCHEMA phptests');
pg_query($conn, "CREATE SCHEMA {$schema_name}");
pg_query($conn, 'CREATE TABLE foo (id INT, id2 INT)');
pg_query($conn, 'CREATE TABLE phptests.foo (id INT, id2 INT)');
pg_query($conn, "CREATE TABLE {$table_name} (id INT, id2 INT)");
pg_query($conn, "CREATE TABLE {$schema_name}.{$table_name} (id INT, id2 INT)");
pg_insert($conn, 'foo', array('id' => 1, 'id2' => 1));
pg_insert($conn, 'foo', array('id' => 1, 'id2' => 2));
pg_insert($conn, 'foo', array('id' => 1, 'id2' => 2));
pg_insert($conn, 'foo', array('id' => 3, 'id2' => 3));
pg_insert($conn, $table_name, array('id' => 1, 'id2' => 1));
pg_insert($conn, $table_name, array('id' => 1, 'id2' => 2));
pg_insert($conn, $table_name, array('id' => 1, 'id2' => 2));
pg_insert($conn, $table_name, array('id' => 3, 'id2' => 3));
pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 1));
pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 2));
pg_insert($conn, 'phptests.foo', array('id' => 2, 'id2' => 3));
pg_insert($conn, 'phptests.foo', array('id' => 2, 'id2' => 3));
pg_insert($conn, "{$schema_name}.{$table_name}", array('id' => 1, 'id2' => 1));
pg_insert($conn, "{$schema_name}.{$table_name}", array('id' => 1, 'id2' => 2));
pg_insert($conn, "{$schema_name}.{$table_name}", array('id' => 2, 'id2' => 3));
pg_insert($conn, "{$schema_name}.{$table_name}", array('id' => 2, 'id2' => 3));
pg_delete($conn, 'foo', array('id' => 1, 'id2' => 0));
pg_delete($conn, 'foo', array('id' => 1, 'id2' => 2));
var_dump(pg_delete($conn, 'foo', array('id' => 1, 'id2' => 2), PGSQL_DML_STRING));
pg_delete($conn, $table_name, array('id' => 1, 'id2' => 0));
pg_delete($conn, $table_name, array('id' => 1, 'id2' => 2));
var_dump(pg_delete($conn, $table_name, array('id' => 1, 'id2' => 2), PGSQL_DML_STRING));
pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 1));
pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 3));
var_dump(pg_delete($conn, 'phptests.foo', array('id' => 2, 'id2' => 3), PGSQL_DML_STRING));
pg_delete($conn, "{$schema_name}.{$table_name}", array('id' => 2, 'id2' => 1));
pg_delete($conn, "{$schema_name}.{$table_name}", array('id' => 2, 'id2' => 3));
var_dump(pg_delete($conn, "{$schema_name}.{$table_name}", array('id' => 2, 'id2' => 3), PGSQL_DML_STRING));
var_dump(pg_fetch_all(pg_query($conn, 'SELECT * FROM foo')));
var_dump(pg_fetch_all(pg_query($conn, 'SELECT * FROM phptests.foo')));
var_dump(pg_fetch_all(pg_query($conn, "SELECT * FROM {$table_name}")));
var_dump(pg_fetch_all(pg_query($conn, "SELECT * FROM {$schema_name}.{$table_name}")));
/* Inexistent */
pg_delete($conn, 'bar', array('id' => 1, 'id2' => 2));
var_dump(pg_delete($conn, 'bar', array('id' => 1, 'id2' => 2), PGSQL_DML_STRING));
pg_query($conn, 'DROP TABLE foo');
pg_query($conn, 'DROP TABLE phptests.foo');
pg_query($conn, 'DROP SCHEMA phptests');
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$schema_name = 'schema_pg_delete_001';
$table_name = 'table_pg_delete_001';
$conn = pg_connect($conn_str);
pg_query($conn, "DROP TABLE IF EXISTS {$table_name}");
pg_query($conn, "DROP TABLE IF EXISTS {$schema_name}.{$table_name}");
pg_query($conn, "DROP SCHEMA IF EXISTS {$schema_name}");
?>
--EXPECTF--
string(43) "DELETE FROM "foo" WHERE "id"=1 AND "id2"=2;"
string(54) "DELETE FROM "phptests"."foo" WHERE "id"=2 AND "id2"=3;"
string(59) "DELETE FROM "table_pg_delete_001" WHERE "id"=1 AND "id2"=2;"
string(82) "DELETE FROM "schema_pg_delete_001"."table_pg_delete_001" WHERE "id"=2 AND "id2"=3;"
array(2) {
[0]=>
array(2) {

View file

@ -3,33 +3,42 @@ PostgreSQL pg_select() - basic test using schema
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$schema_name = 'schema_pg_insert_001';
$table_name = 'table_pg_insert_001';
$conn = pg_connect($conn_str);
pg_query($conn, 'CREATE SCHEMA phptests');
pg_query($conn, 'CREATE TABLE phptests.foo (id INT, id2 INT)');
pg_query($conn, "CREATE SCHEMA {$schema_name}");
pg_query($conn, "CREATE TABLE {$schema_name}.{$table_name} (id INT, id2 INT)");
pg_insert($conn, 'foo', array('id' => 1, 'id2' => 1));
pg_insert($conn, $table_name, array('id' => 1, 'id2' => 1));
pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 2));
pg_insert($conn, "{$schema_name}.{$table_name}", array('id' => 1, 'id2' => 2));
var_dump(pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 2), PGSQL_DML_STRING));
var_dump(pg_insert($conn, "{$schema_name}.{$table_name}", array('id' => 1, 'id2' => 2), PGSQL_DML_STRING));
var_dump(pg_select($conn, 'phptests.foo', array('id' => 1)));
pg_query($conn, 'DROP TABLE phptests.foo');
pg_query($conn, 'DROP SCHEMA phptests');
var_dump(pg_select($conn, "{$schema_name}.{$table_name}", array('id' => 1)));
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$schema_name = 'schema_pg_insert_001';
$table_name = 'table_pg_insert_001';
$conn = pg_connect($conn_str);
pg_query($conn, "DROP TABLE IF EXISTS {$schema_name}.{$table_name}");
pg_query($conn, "DROP SCHEMA IF EXISTS {$schema_name}");
?>
--EXPECTF--
Warning: pg_insert(): Table 'foo' doesn't exists in %s on line %d
string(55) "INSERT INTO "phptests"."foo" ("id","id2") VALUES (1,2);"
Warning: pg_insert(): Table 'table_pg_insert_001' doesn't exists in %s on line %d
string(83) "INSERT INTO "schema_pg_insert_001"."table_pg_insert_001" ("id","id2") VALUES (1,2);"
array(1) {
[0]=>
array(2) {

View file

@ -3,11 +3,11 @@ PostgreSQL pg_insert() - test for CVE-2015-1532
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$conn = pg_connect($conn_str);

View file

@ -3,30 +3,38 @@ PostgreSQL pg_meta_data() - basic test using schema
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$schema_name = 'schema_pg_meta_data_001';
$table_name = 'table_pg_meta_data_001';
$conn = pg_connect($conn_str);
pg_query($conn, 'CREATE SCHEMA phptests');
pg_query($conn, "CREATE SCHEMA {$schema_name}");
pg_query($conn, 'CREATE TABLE phptests.foo (id INT, id2 INT)');
pg_query($conn, "CREATE TABLE {$schema_name}.{$table_name} (id INT, id2 INT)");
pg_query($conn, 'CREATE TABLE foo (id INT, id3 INT)');
pg_query($conn, "CREATE TABLE {$table_name} (id INT, id3 INT)");
var_dump(pg_meta_data($conn, 'foo'));
var_dump(pg_meta_data($conn, 'phptests.foo'));
var_dump(pg_meta_data($conn, 'phptests.foo', TRUE));
var_dump(pg_meta_data($conn, $table_name));
var_dump(pg_meta_data($conn, "{$schema_name}.{$table_name}"));
var_dump(pg_meta_data($conn, "{$schema_name}.{$table_name}", TRUE));
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$schema_name = 'schema_pg_meta_data_001';
$table_name = 'table_pg_meta_data_001';
pg_query($conn, 'DROP TABLE foo');
pg_query($conn, 'DROP TABLE phptests.foo');
pg_query($conn, 'DROP SCHEMA phptests');
$conn = pg_connect($conn_str);
pg_query($conn, "DROP TABLE IF EXISTS {$table_name}");
pg_query($conn, "DROP TABLE IF EXISTS {$schema_name}.{$table_name}");
pg_query($conn, "DROP SCHEMA IF EXISTS {$schema_name}");
?>
--EXPECT--
array(2) {

View file

@ -4,7 +4,7 @@ PostgreSQL pipeline mode
pgsql
--SKIPIF--
<?php
include("skipif.inc");
include("inc/skipif.inc");
if (!defined('PGSQL_PIPELINE_SYNC') || !function_exists('pg_send_query_params')) {
die('skip pipeline mode not available');
}
@ -12,8 +12,8 @@ if (!defined('PGSQL_PIPELINE_SYNC') || !function_exists('pg_send_query_params'))
--FILE--
<?php
include('config.inc');
include('nonblocking.inc');
include('inc/config.inc');
include('inc/nonblocking.inc');
if (!$db = pg_connect($conn_str, PGSQL_CONNECT_ASYNC)) {
die("pg_connect() error");
@ -46,7 +46,7 @@ if (!pg_enter_pipeline_mode($db)) {
die('pg_enter_pipeline_mode{}');
}
if (!pg_send_query_params($db, "select $1 as index, now() + ($1||' day')::interval as time", array(1))) {
if (!pg_send_query_params($db, "SELECT $1 as index, now() + ($1||' day')::interval as time", array(1))) {
die('pg_send_query_params failed');
}

View file

@ -3,49 +3,57 @@ PostgreSQL pg_select() - basic test using schema
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$schema_name = 'schema_pg_select_001';
$conn = pg_connect($conn_str);
pg_query($conn, 'CREATE SCHEMA phptests');
pg_query($conn, "CREATE SCHEMA {$schema_name}");
pg_query($conn, 'CREATE TABLE phptests.foo (id INT, id2 INT)');
pg_query($conn, 'INSERT INTO phptests.foo VALUES (1,2)');
pg_query($conn, 'INSERT INTO phptests.foo VALUES (2,3)');
pg_query($conn, "CREATE TABLE {$schema_name}.foo (id INT, id2 INT)");
pg_query($conn, "INSERT INTO {$schema_name}.foo VALUES (1,2)");
pg_query($conn, "INSERT INTO {$schema_name}.foo VALUES (2,3)");
pg_query($conn, 'CREATE TABLE phptests.bar (id4 INT, id3 INT)');
pg_query($conn, 'INSERT INTO phptests.bar VALUES (4,5)');
pg_query($conn, 'INSERT INTO phptests.bar VALUES (6,7)');
pg_query($conn, "CREATE TABLE {$schema_name}.bar (id4 INT, id3 INT)");
pg_query($conn, "INSERT INTO {$schema_name}.bar VALUES (4,5)");
pg_query($conn, "INSERT INTO {$schema_name}.bar VALUES (6,7)");
/* Nonexistent table */
var_dump(pg_select($conn, 'foo', array('id' => 1)));
/* Existent column */
var_dump(pg_select($conn, 'phptests.foo', array('id' => 1)));
var_dump(pg_select($conn, "{$schema_name}.foo", array('id' => 1)));
/* Testing with inexistent column */
var_dump(pg_select($conn, 'phptests.bar', array('id' => 1)));
var_dump(pg_select($conn, "{$schema_name}.bar", array('id' => 1)));
/* Existent column */
var_dump(pg_select($conn, 'phptests.bar', array('id4' => 4)));
var_dump(pg_select($conn, "{$schema_name}.bar", array('id4' => 4)));
/* Use a different result type */
var_dump(pg_select($conn, 'phptests.bar', array('id4' => 4), 0, PGSQL_NUM));
var_dump(pg_select($conn, "{$schema_name}.bar", array('id4' => 4), 0, PGSQL_NUM));
/* Empty array */
var_dump(pg_select($conn, 'phptests.bar', array()));
var_dump(pg_select($conn, "{$schema_name}.bar", array()));
/* No array */
var_dump(pg_select($conn, 'phptests.bar'));
var_dump(pg_select($conn, "{$schema_name}.bar"));
pg_query($conn, 'DROP TABLE phptests.foo');
pg_query($conn, 'DROP TABLE phptests.bar');
pg_query($conn, 'DROP SCHEMA phptests');
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$schema_name = 'schema_pg_select_001';
$conn = pg_connect($conn_str);
pg_query($conn, "DROP TABLE IF EXISTS {$schema_name}.foo");
pg_query($conn, "DROP TABLE IF EXISTS {$schema_name}.bar");
pg_query($conn, "DROP SCHEMA IF EXISTS {$schema_name}");
?>
--EXPECTF--
Warning: pg_select(): Table 'foo' doesn't exists in %s on line %d

View file

@ -3,11 +3,11 @@ pg_trace
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$db = pg_connect($conn_str);
$tracefile = __DIR__ . '/trace.tmp';
@ -18,7 +18,7 @@ try {
echo $e->getMessage() . PHP_EOL;
}
var_dump(pg_trace($tracefile, 'w', $db, 0));
$res = pg_query($db, 'select 1');
$res = pg_query($db, 'SELECT 1');
?>
--EXPECTF--

View file

@ -3,42 +3,52 @@ PostgreSQL pg_update() - basic test using schema
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("skipif.inc"); ?>
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
include('config.inc');
include('inc/config.inc');
$schema_name = 'schema_pg_update_001';
$table_name = 'table_pg_update_001';
$conn = pg_connect($conn_str);
pg_query($conn, 'CREATE SCHEMA phptests');
pg_query($conn, "CREATE SCHEMA {$schema_name}");
pg_query($conn, 'CREATE TABLE foo (id INT, id2 INT)');
pg_query($conn, 'CREATE TABLE phptests.foo (id INT, id2 INT)');
pg_query($conn, "CREATE TABLE {$table_name} (id INT, id2 INT)");
pg_query($conn, "CREATE TABLE {$schema_name}.{$table_name} (id INT, id2 INT)");
pg_insert($conn, 'foo', array('id' => 1, 'id2' => 1));
pg_insert($conn, 'phptests.foo', array('id' => 1, 'id2' => 2));
pg_insert($conn, $table_name, array('id' => 1, 'id2' => 1));
pg_insert($conn, "{$schema_name}.{$table_name}", array('id' => 1, 'id2' => 2));
pg_update($conn, 'foo', array('id' => 10), array('id' => 1));
var_dump(pg_update($conn, 'foo', array('id' => 10), array('id' => 1), PGSQL_DML_STRING));
pg_update($conn, $table_name, array('id' => 10), array('id' => 1));
var_dump(pg_update($conn, $table_name, array('id' => 10), array('id' => 1), PGSQL_DML_STRING));
pg_update($conn, 'phptests.foo', array('id' => 100), array('id2' => 2));
var_dump(pg_update($conn, 'phptests.foo', array('id' => 100), array('id2' => 2), PGSQL_DML_STRING));
pg_update($conn, "{$schema_name}.{$table_name}", array('id' => 100), array('id2' => 2));
var_dump(pg_update($conn, "{$schema_name}.{$table_name}", array('id' => 100), array('id2' => 2), PGSQL_DML_STRING));
$rs = pg_query($conn, 'SELECT * FROM foo UNION SELECT * FROM phptests.foo ORDER BY id');
$rs = pg_query($conn, "SELECT * FROM {$table_name} UNION SELECT * FROM {$schema_name}.{$table_name} ORDER BY id");
while ($row = pg_fetch_assoc($rs)) {
var_dump($row);
}
pg_query($conn, 'DROP TABLE foo');
pg_query($conn, 'DROP TABLE phptests.foo');
pg_query($conn, 'DROP SCHEMA phptests');
?>
--CLEAN--
<?php
require_once('inc/config.inc');
$schema_name = 'schema_pg_update_001';
$table_name = 'table_pg_update_001';
$conn = pg_connect($conn_str);
pg_query($conn, "DROP TABLE IF EXISTS {$table_name}");
pg_query($conn, "DROP TABLE IF EXISTS {$schema_name}.{$table_name}");
pg_query($conn, "DROP SCHEMA IF EXISTS {$schema_name}");
?>
--EXPECT--
string(38) "UPDATE "foo" SET "id"=10 WHERE "id"=1;"
string(51) "UPDATE "phptests"."foo" SET "id"=100 WHERE "id2"=2;"
string(54) "UPDATE "table_pg_update_001" SET "id"=10 WHERE "id"=1;"
string(79) "UPDATE "schema_pg_update_001"."table_pg_update_001" SET "id"=100 WHERE "id2"=2;"
array(2) {
["id"]=>
string(2) "10"