Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/pgsql/tests/00version.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
26 changes: 18 additions & 8 deletions ext/pgsql/tests/01createdb.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
4 changes: 2 additions & 2 deletions ext/pgsql/tests/02connection.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 14 additions & 3 deletions ext/pgsql/tests/03sync_query.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions ext/pgsql/tests/04async_query.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand All @@ -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
36 changes: 18 additions & 18 deletions ext/pgsql/tests/05large_object.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -34,50 +34,50 @@ 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);
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 {
Expand Down
21 changes: 18 additions & 3 deletions ext/pgsql/tests/06_bug73498.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 12 additions & 2 deletions ext/pgsql/tests/06copy.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
20 changes: 13 additions & 7 deletions ext/pgsql/tests/06copy_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions ext/pgsql/tests/07optional.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading