Skip to content

Commit daded6e

Browse files
committed
Reorganized tests
1 parent 4a11372 commit daded6e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+488
-634
lines changed

ext/pgsql/tests/01createdb.phpt

+19-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,25 @@ PostgreSQL create db
44
<?php include("skipif.inc"); ?>
55
--FILE--
66
<?php
7-
include("createdb.inc");
7+
// create test table
8+
9+
include('config.inc');
10+
11+
$db = pg_connect($conn_str);
12+
if (!@pg_num_rows(@pg_query($db, "SELECT * FROM ".$table_name)))
13+
{
14+
@pg_query($db,$table_def); // Create table here
15+
for ($i=0; $i < $num_test_record; $i++) {
16+
pg_query($db,"INSERT INTO ".$table_name." VALUES ($i, 'ABC');");
17+
}
18+
}
19+
else {
20+
echo pg_last_error()."\n";
21+
}
22+
23+
pg_close($db);
24+
25+
echo "OK";
826
?>
927
--EXPECT--
1028
OK

ext/pgsql/tests/02connection.phpt

+41-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,47 @@ PostgreSQL connection
44
<?php include("skipif.inc"); ?>
55
--FILE--
66
<?php
7-
include("connection.inc");
7+
// connection function tests
8+
9+
include('config.inc');
10+
11+
$db = pg_pconnect($conn_str);
12+
if (pg_connection_status($db) != PGSQL_CONNECTION_OK)
13+
{
14+
echo "pg_connection_status() error\n";
15+
}
16+
if (!pg_connection_reset($db))
17+
{
18+
echo "pg_connection_reset() error\n";
19+
}
20+
if (pg_connection_busy($db))
21+
{
22+
echo "pg_connection_busy() error\n";
23+
}
24+
if (!pg_host($db))
25+
{
26+
echo "pg_host() error\n";
27+
}
28+
if (!pg_dbname($db))
29+
{
30+
echo "pg_dbname() error\n";
31+
}
32+
if (!pg_port($db))
33+
{
34+
echo "pg_port() error\n";
35+
}
36+
if (pg_tty($db))
37+
{
38+
echo "pg_tty() error\n";
39+
}
40+
if (pg_options($db))
41+
{
42+
echo "pg_options() error\n";
43+
}
44+
45+
pg_close($db);
46+
47+
echo "OK";
848
?>
949
--EXPECT--
1050
OK

ext/pgsql/tests/03sync_query.phpt

+44-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,50 @@ PostgreSQL sync query
44
<?php include("skipif.inc"); ?>
55
--FILE--
66
<?php
7-
include("sync_query.inc");
7+
8+
include('config.inc');
9+
10+
$db = pg_connect($conn_str);
11+
12+
$result = pg_query($db, "SELECT * FROM ".$table_name.";");
13+
if (!($rows = pg_num_rows($result)))
14+
{
15+
echo "pg_num_row() error\n";
16+
}
17+
for ($i=0; $i < $rows; $i++)
18+
{
19+
pg_fetch_array($result, $i, PGSQL_NUM);
20+
}
21+
for ($i=0; $i < $rows; $i++)
22+
{
23+
pg_fetch_object($result, $i, PGSQL_ASSOC);
24+
}
25+
for ($i=0; $i < $rows; $i++)
26+
{
27+
pg_fetch_row($result, $i);
28+
}
29+
for ($i=0; $i < $rows; $i++)
30+
{
31+
pg_fetch_result($result, $i, 0);
32+
}
33+
34+
pg_result_error($result);
35+
pg_num_rows(pg_query($db, "SELECT * FROM ".$table_name.";"));
36+
pg_num_fields(pg_query($db, "SELECT * FROM ".$table_name.";"));
37+
pg_field_name($result, 0);
38+
pg_field_num($result, $field_name);
39+
pg_field_size($result, 0);
40+
pg_field_type($result, 0);
41+
pg_field_prtlen($result, 0);
42+
pg_field_is_null($result, 0);
43+
44+
$result = pg_query($db, "INSERT INTO ".$table_name." VALUES (9999, 'ABC');");
45+
pg_last_oid($result);
46+
47+
pg_free_result($result);
48+
pg_close($db);
49+
50+
echo "OK";
851
?>
952
--EXPECT--
1053
OK

ext/pgsql/tests/04async_query.phpt

+56-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,62 @@ PostgreSQL async query
44
<?php include("skipif.inc"); ?>
55
--FILE--
66
<?php
7-
include("async_query.inc");
7+
8+
include('config.inc');
9+
10+
$db = pg_connect($conn_str);
11+
12+
if (!pg_send_query($db, "SELECT * FROM ".$table_name.";")) {
13+
echo "pg_send_query() error\n";
14+
}
15+
while(pg_connection_busy($db)); // busy wait: intended
16+
if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
17+
echo "pg_connection_status() error\n";
18+
}
19+
if (!($result = pg_get_result($db)))
20+
{
21+
echo "pg_get_result() error\n";
22+
}
23+
24+
if (!($rows = pg_num_rows($result))) {
25+
echo "pg_num_rows() error\n";
26+
}
27+
for ($i=0; $i < $rows; $i++)
28+
{
29+
pg_fetch_array($result, $i, PGSQL_NUM);
30+
}
31+
for ($i=0; $i < $rows; $i++)
32+
{
33+
pg_fetch_object($result, $i, PGSQL_ASSOC);
34+
}
35+
for ($i=0; $i < $rows; $i++)
36+
{
37+
pg_fetch_row($result, $i);
38+
}
39+
for ($i=0; $i < $rows; $i++)
40+
{
41+
pg_fetch_result($result, $i, 0);
42+
}
43+
44+
pg_num_rows(pg_query($db, "SELECT * FROM ".$table_name.";"));
45+
pg_num_fields(pg_query($db, "SELECT * FROM ".$table_name.";"));
46+
pg_field_name($result, 0);
47+
pg_field_num($result, $field_name);
48+
pg_field_size($result, 0);
49+
pg_field_type($result, 0);
50+
pg_field_prtlen($result, 0);
51+
pg_field_is_null($result, 0);
52+
53+
if (!pg_send_query($db, "INSERT INTO ".$table_name." VALUES (8888, 'GGG');"))
54+
{
55+
echo "pg_send_query() error\n";
56+
}
57+
58+
pg_last_oid($result);
59+
pg_free_result($result);
60+
61+
62+
echo "OK";
863
?>
964
--EXPECT--
1065
OK

ext/pgsql/tests/05large_object.phpt

+64-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,70 @@ PostgreSQL large object
44
<?php include("skipif.inc"); ?>
55
--FILE--
66
<?php
7-
include("large_object.inc");
7+
8+
include('config.inc');
9+
10+
$db = pg_connect($conn_str);
11+
12+
// create/write/close LO
13+
pg_exec ($db, "begin");
14+
$oid = pg_lo_create ($db);
15+
if (!$oid) echo ("pg_lo_create() error\n");
16+
$handle = pg_lo_open ($db, $oid, "w");
17+
if (!$handle) echo ("pg_lo_open() error\n");
18+
pg_lo_write ($handle, "large object data\n");
19+
pg_lo_close ($handle);
20+
pg_exec ($db, "commit");
21+
22+
// open/read/tell/seek/close LO
23+
pg_exec ($db, "begin");
24+
$handle = pg_lo_open ($db, $oid, "w");
25+
pg_lo_read($handle, 100);
26+
pg_lo_tell($handle);
27+
pg_lo_seek($handle, 2);
28+
pg_lo_close($handle);
29+
pg_exec ($db, "commit");
30+
31+
// open/read_all/close LO
32+
pg_exec ($db, "begin");
33+
$handle = pg_lo_open ($db, $oid, "w");
34+
pg_lo_read_all($handle);
35+
if (pg_last_error()) echo "pg_lo_read_all() error\n".pg_last_error();
36+
pg_lo_close($handle);
37+
pg_exec ($db, "commit");
38+
39+
// unlink LO
40+
pg_exec ($db, "begin");
41+
pg_lo_unlink($db, $oid) or print("pg_lo_unlink() error\n");
42+
pg_exec ($db, "commit");
43+
44+
// more pg_lo_unlink() tests
45+
// Test without connection
46+
pg_exec ($db, "begin");
47+
$oid = pg_lo_create ($db) or print("pg_lo_create() error\n");
48+
pg_lo_unlink($oid) or print("pg_lo_unlink() error\n");
49+
pg_exec ($db, "commit");
50+
51+
// Test with string oid value
52+
pg_exec ($db, "begin");
53+
$oid = pg_lo_create ($db) or print("pg_lo_create() error\n");
54+
pg_lo_unlink($db, (string)$oid) or print("pg_lo_unlink() error\n");
55+
pg_exec ($db, "commit");
56+
57+
// import/export LO
58+
pg_query($db, 'begin');
59+
$oid = pg_lo_import($db, 'php.gif');
60+
pg_query($db, 'commit');
61+
pg_query($db, 'begin');
62+
@unlink('php.gif.exported');
63+
pg_lo_export($oid, 'php.gif.exported', $db);
64+
if (!file_exists('php.gif.exported')) {
65+
echo "Export failed\n";
66+
}
67+
@unlink('php.gif.exported');
68+
pg_query($db, 'commit');
69+
70+
echo "OK";
871
?>
972
--EXPECT--
1073
large object data

ext/pgsql/tests/06copy.phpt

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ PostgreSQL copy functions
44
<?php include("skipif.inc"); ?>
55
--FILE--
66
<?php
7-
include("copy.inc");
7+
8+
include('config.inc');
9+
10+
11+
echo "OK";
12+
813
?>
914
--EXPECT--
1015
OK

ext/pgsql/tests/07optional.phpt

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@ PostgreSQL optional functions
44
<?php include("skipif.inc"); ?>
55
--FILE--
66
<?php
7-
include("optional.inc");
7+
// optional functions
8+
9+
include('config.inc');
10+
11+
$db = pg_connect($conn_str);
12+
$enc = pg_client_encoding($db);
13+
14+
pg_set_client_encoding($db, $enc);
15+
16+
echo "OK";
817
?>
918
--EXPECT--
1019
OK

ext/pgsql/tests/08escape.phpt

+57-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,63 @@ PostgreSQL escape functions
44
<?php include("skipif.inc"); ?>
55
--FILE--
66
<?php
7-
include("escape.inc");
7+
8+
include 'config.inc';
9+
define('FILE_NAME', './php.gif');
10+
11+
// pg_escape_string() test
12+
$before = "ABC\\ABC\'";
13+
$expect = "ABC\\\\ABC\\'";
14+
$after = pg_escape_string($before);
15+
if ($expect === $after) {
16+
echo "pg_escape_string() is Ok\n";
17+
}
18+
else {
19+
echo "pg_escape_string() is NOT Ok\n";
20+
var_dump($before);
21+
var_dump($after);
22+
var_dump($expect);
23+
}
24+
25+
// pg_escape_bytea() test
26+
$before = "ABC\\ABC";
27+
$expect = "ABC\\\\\\\\ABC";
28+
$after = pg_escape_bytea($before);
29+
if ($expect === $after) {
30+
echo "pg_escape_bytea() is Ok\n";
31+
}
32+
else {
33+
echo "pg_escape_byte() is NOT Ok\n";
34+
var_dump($before);
35+
var_dump($after);
36+
var_dump($expect);
37+
}
38+
39+
// Test using database
40+
$fp = fopen(FILE_NAME,'r');
41+
$data = fread($fp, filesize(FILE_NAME));
42+
$db = pg_connect($conn_str);
43+
44+
// Insert binary to DB
45+
$escaped_data = pg_escape_bytea($data);
46+
pg_query("DELETE FROM ".$table_name." WHERE num = -9999;");
47+
$sql = "INSERT INTO ".$table_name." (num, bin) VALUES (-9999, CAST ('".$escaped_data."' AS BYTEA));";
48+
pg_query($db, $sql);
49+
50+
// Retrieve binary from DB
51+
$sql = "SELECT bin::bytea FROM ".$table_name." WHERE num = -9999";
52+
$result = pg_query($db, $sql);
53+
$row = pg_fetch_array($result, 0, PGSQL_ASSOC);
54+
55+
// Compare
56+
// Need to wait PostgreSQL 7.3.x for PQunescapeBytea()
57+
// if ($data === pg_unescape_bytea($row['bin'])) {
58+
// echo "pg_escape_bytea() actually works with databse\n";
59+
// }
60+
// else {
61+
// echo "pg_escape_bytea() is broken\n";
62+
// }
63+
864
?>
965
--EXPECT--
1066
pg_escape_string() is NOT Ok

ext/pgsql/tests/09notice.phpt

+16-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,22 @@ PostgreSQL notice function
44
<?php include("skipif.inc"); ?>
55
--FILE--
66
<?php
7-
include("notice.inc");
7+
include 'config.inc';
8+
9+
ini_set('pgsql.log_notice',1);
10+
11+
$db = pg_connect($conn_str);
12+
pg_query($db, "BEGIN;");
13+
pg_query($db, "BEGIN;");
14+
15+
$msg = pg_last_notice($db);
16+
if ($msg === FALSE) {
17+
echo "Cannot find notice message in hash\n";
18+
var_dump($msg);
19+
}
20+
echo $msg;
21+
echo "pg_last_notice() is Ok\n";
22+
823
?>
924
--EXPECT--
1025
NOTICE: BEGIN: already a transaction in progress

0 commit comments

Comments
 (0)