Skip to content

Commit 63ed4a1

Browse files
author
Christopher Kings-Lynne
committed
- Ensure that ext/pgsql tests work when linked against 7.2 or lower libpq
1 parent 9b1c989 commit 63ed4a1

6 files changed

+239
-215
lines changed

ext/pgsql/tests/02connection.phpt

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ if (pg_connection_busy($db))
2323
{
2424
echo "pg_connection_busy() error\n";
2525
}
26-
if (pg_transaction_status($db) != PGSQL_TRANSACTION_IDLE)
27-
{
28-
echo "pg_transaction_status() error\n";
26+
if (function_exists('pg_transaction_status')) {
27+
if (pg_transaction_status($db) != PGSQL_TRANSACTION_IDLE)
28+
{
29+
echo "pg_transaction_status() error\n";
30+
}
2931
}
3032
if (!pg_host($db))
3133
{

ext/pgsql/tests/03sync_query.phpt

+19-17
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,26 @@ for ($i=0; $i < $rows; $i++)
3232
}
3333

3434
pg_result_error($result);
35-
pg_result_error_field($result, PGSQL_DIAG_SEVERITY);
36-
pg_result_error_field($result, PGSQL_DIAG_SQLSTATE);
37-
pg_result_error_field($result, PGSQL_DIAG_MESSAGE_PRIMARY);
38-
pg_result_error_field($result, PGSQL_DIAG_MESSAGE_DETAIL);
39-
pg_result_error_field($result, PGSQL_DIAG_MESSAGE_HINT);
40-
pg_result_error_field($result, PGSQL_DIAG_STATEMENT_POSITION);
41-
if (defined('PGSQL_DIAG_INTERNAL_POSITION'))
42-
{
43-
pg_result_error_field($result, PGSQL_DIAG_INTERNAL_POSITION);
44-
}
45-
if (defined('PGSQL_DIAG_INTERNAL_QUERY'))
46-
{
47-
pg_result_error_field($result, PGSQL_DIAG_INTERNAL_QUERY);
35+
if (function_exists('pg_result_error_field')) {
36+
pg_result_error_field($result, PGSQL_DIAG_SEVERITY);
37+
pg_result_error_field($result, PGSQL_DIAG_SQLSTATE);
38+
pg_result_error_field($result, PGSQL_DIAG_MESSAGE_PRIMARY);
39+
pg_result_error_field($result, PGSQL_DIAG_MESSAGE_DETAIL);
40+
pg_result_error_field($result, PGSQL_DIAG_MESSAGE_HINT);
41+
pg_result_error_field($result, PGSQL_DIAG_STATEMENT_POSITION);
42+
if (defined('PGSQL_DIAG_INTERNAL_POSITION'))
43+
{
44+
pg_result_error_field($result, PGSQL_DIAG_INTERNAL_POSITION);
45+
}
46+
if (defined('PGSQL_DIAG_INTERNAL_QUERY'))
47+
{
48+
pg_result_error_field($result, PGSQL_DIAG_INTERNAL_QUERY);
49+
}
50+
pg_result_error_field($result, PGSQL_DIAG_CONTEXT);
51+
pg_result_error_field($result, PGSQL_DIAG_SOURCE_FILE);
52+
pg_result_error_field($result, PGSQL_DIAG_SOURCE_LINE);
53+
pg_result_error_field($result, PGSQL_DIAG_SOURCE_FUNCTION);
4854
}
49-
pg_result_error_field($result, PGSQL_DIAG_CONTEXT);
50-
pg_result_error_field($result, PGSQL_DIAG_SOURCE_FILE);
51-
pg_result_error_field($result, PGSQL_DIAG_SOURCE_LINE);
52-
pg_result_error_field($result, PGSQL_DIAG_SOURCE_FUNCTION);
5355
pg_num_rows(pg_query($db, "SELECT * FROM ".$table_name.";"));
5456
pg_num_fields(pg_query($db, "SELECT * FROM ".$table_name.";"));
5557
pg_field_name($result, 0);

ext/pgsql/tests/23sync_query_params.phpt

+40-34
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,56 @@
11
--TEST--
22
PostgreSQL sync query params
33
--SKIPIF--
4-
<?php include("skipif.inc"); ?>
4+
<?php
5+
include("skipif.inc");
6+
if (!function_exists('pg_query_params')) die('skip function pg_query_params() does not exist');
7+
?>
58
--FILE--
69
<?php
710

811
include('config.inc');
912

1013
$db = pg_connect($conn_str);
1114

12-
$result = pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100));
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);
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-
}
15+
$version = pg_version($db);
16+
if ($version['protocol'] >= 3) {
17+
$result = pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100));
18+
if (!($rows = pg_num_rows($result)))
19+
{
20+
echo "pg_num_row() error\n";
21+
}
22+
for ($i=0; $i < $rows; $i++)
23+
{
24+
pg_fetch_array($result, $i, PGSQL_NUM);
25+
}
26+
for ($i=0; $i < $rows; $i++)
27+
{
28+
pg_fetch_object($result);
29+
}
30+
for ($i=0; $i < $rows; $i++)
31+
{
32+
pg_fetch_row($result, $i);
33+
}
34+
for ($i=0; $i < $rows; $i++)
35+
{
36+
pg_fetch_result($result, $i, 0);
37+
}
3338

34-
pg_result_error($result);
35-
pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
36-
pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
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);
39+
pg_result_error($result);
40+
pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
41+
pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
42+
pg_field_name($result, 0);
43+
pg_field_num($result, $field_name);
44+
pg_field_size($result, 0);
45+
pg_field_type($result, 0);
46+
pg_field_prtlen($result, 0);
47+
pg_field_is_null($result, 0);
4348

44-
$result = pg_query_params($db, "INSERT INTO ".$table_name." VALUES (\$1, \$2);", array(9999, "A'BC"));
45-
pg_last_oid($result);
49+
$result = pg_query_params($db, "INSERT INTO ".$table_name." VALUES (\$1, \$2);", array(9999, "A'BC"));
50+
pg_last_oid($result);
4651

47-
pg_free_result($result);
52+
pg_free_result($result);
53+
}
4854
pg_close($db);
4955

5056
echo "OK";

ext/pgsql/tests/24sync_query_prepared.phpt

+42-39
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,51 @@ include('config.inc');
1212

1313
$db = pg_connect($conn_str);
1414

15-
$result = pg_prepare($db, "php_test", "SELECT * FROM ".$table_name." WHERE num > \$1;");
16-
pg_result_error($result);
17-
pg_free_result($result);
18-
$result = pg_execute($db, "php_test", array(100));
19-
if (!($rows = pg_num_rows($result)))
20-
{
21-
echo "pg_num_row() error\n";
22-
}
23-
for ($i=0; $i < $rows; $i++)
24-
{
25-
pg_fetch_array($result, $i, PGSQL_NUM);
26-
}
27-
for ($i=0; $i < $rows; $i++)
28-
{
29-
pg_fetch_object($result);
30-
}
31-
for ($i=0; $i < $rows; $i++)
32-
{
33-
pg_fetch_row($result, $i);
34-
}
35-
for ($i=0; $i < $rows; $i++)
36-
{
37-
pg_fetch_result($result, $i, 0);
38-
}
15+
$version = pg_version($db);
16+
if ($version['protocol'] >= 3) {
17+
$result = pg_prepare($db, "php_test", "SELECT * FROM ".$table_name." WHERE num > \$1;");
18+
pg_result_error($result);
19+
pg_free_result($result);
20+
$result = pg_execute($db, "php_test", array(100));
21+
if (!($rows = pg_num_rows($result)))
22+
{
23+
echo "pg_num_row() error\n";
24+
}
25+
for ($i=0; $i < $rows; $i++)
26+
{
27+
pg_fetch_array($result, $i, PGSQL_NUM);
28+
}
29+
for ($i=0; $i < $rows; $i++)
30+
{
31+
pg_fetch_object($result);
32+
}
33+
for ($i=0; $i < $rows; $i++)
34+
{
35+
pg_fetch_row($result, $i);
36+
}
37+
for ($i=0; $i < $rows; $i++)
38+
{
39+
pg_fetch_result($result, $i, 0);
40+
}
3941

40-
pg_result_error($result);
41-
pg_num_rows(pg_execute($db, "php_test", array(100)));
42-
pg_num_fields(pg_execute($db, "php_test", array(100)));
43-
pg_field_name($result, 0);
44-
pg_field_num($result, $field_name);
45-
pg_field_size($result, 0);
46-
pg_field_type($result, 0);
47-
pg_field_prtlen($result, 0);
48-
pg_field_is_null($result, 0);
42+
pg_result_error($result);
43+
pg_num_rows(pg_execute($db, "php_test", array(100)));
44+
pg_num_fields(pg_execute($db, "php_test", array(100)));
45+
pg_field_name($result, 0);
46+
pg_field_num($result, $field_name);
47+
pg_field_size($result, 0);
48+
pg_field_type($result, 0);
49+
pg_field_prtlen($result, 0);
50+
pg_field_is_null($result, 0);
4951

50-
$result = pg_prepare($db, "php_test2", "INSERT INTO ".$table_name." VALUES (\$1, \$2);");
51-
pg_result_error($result);
52-
pg_free_result($result);
53-
$result = pg_execute($db, "php_test2", array(9999, "A'BC"));
54-
pg_last_oid($result);
52+
$result = pg_prepare($db, "php_test2", "INSERT INTO ".$table_name." VALUES (\$1, \$2);");
53+
pg_result_error($result);
54+
pg_free_result($result);
55+
$result = pg_execute($db, "php_test2", array(9999, "A'BC"));
56+
pg_last_oid($result);
5557

56-
pg_free_result($result);
58+
pg_free_result($result);
59+
}
5760
pg_close($db);
5861

5962
echo "OK";

ext/pgsql/tests/25async_query_params.phpt

+52-45
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,68 @@
11
--TEST--
22
PostgreSQL async query params
33
--SKIPIF--
4-
<?php include("skipif.inc"); ?>
4+
<?php
5+
include("skipif.inc");
6+
if (!function_exists('pg_send_query_params')) die('skip function pg_send_query_params() does not exist');
7+
?>
58
--FILE--
69
<?php
710

811
include('config.inc');
912

1013
$db = pg_connect($conn_str);
1114

12-
if (!pg_send_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100))) {
13-
echo "pg_send_query_params() 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-
if (!($rows = pg_num_rows($result))) {
24-
echo "pg_num_rows() error\n";
25-
}
26-
for ($i=0; $i < $rows; $i++)
27-
{
28-
pg_fetch_array($result, $i, PGSQL_NUM);
29-
}
30-
for ($i=0; $i < $rows; $i++)
31-
{
32-
pg_fetch_object($result);
33-
}
34-
for ($i=0; $i < $rows; $i++)
35-
{
36-
pg_fetch_row($result, $i);
37-
}
38-
for ($i=0; $i < $rows; $i++)
39-
{
40-
pg_fetch_result($result, $i, 0);
41-
}
15+
$version = pg_version($db);
16+
if ($version['protocol'] >= 3) {
17+
if (!pg_send_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100))) {
18+
echo "pg_send_query_params() error\n";
19+
}
20+
while(pg_connection_busy($db)); // busy wait: intended
21+
if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
22+
echo "pg_connection_status() error\n";
23+
}
24+
if (!($result = pg_get_result($db)))
25+
{
26+
echo "pg_get_result() error\n";
27+
}
28+
if (!($rows = pg_num_rows($result))) {
29+
echo "pg_num_rows() error\n";
30+
}
31+
for ($i=0; $i < $rows; $i++)
32+
{
33+
pg_fetch_array($result, $i, PGSQL_NUM);
34+
}
35+
for ($i=0; $i < $rows; $i++)
36+
{
37+
pg_fetch_object($result);
38+
}
39+
for ($i=0; $i < $rows; $i++)
40+
{
41+
pg_fetch_row($result, $i);
42+
}
43+
for ($i=0; $i < $rows; $i++)
44+
{
45+
pg_fetch_result($result, $i, 0);
46+
}
4247

43-
pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
44-
pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
45-
pg_field_name($result, 0);
46-
pg_field_num($result, $field_name);
47-
pg_field_size($result, 0);
48-
pg_field_type($result, 0);
49-
pg_field_prtlen($result, 0);
50-
pg_field_is_null($result, 0);
48+
pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
49+
pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
50+
pg_field_name($result, 0);
51+
pg_field_num($result, $field_name);
52+
pg_field_size($result, 0);
53+
pg_field_type($result, 0);
54+
pg_field_prtlen($result, 0);
55+
pg_field_is_null($result, 0);
5156

52-
if (!pg_send_query_params($db, "INSERT INTO ".$table_name." VALUES (\$1, \$2);", array(9999, "A'BC")))
53-
{
54-
echo "pg_send_query_params() error\n";
55-
}
57+
if (!pg_send_query_params($db, "INSERT INTO ".$table_name." VALUES (\$1, \$2);", array(9999, "A'BC")))
58+
{
59+
echo "pg_send_query_params() error\n";
60+
}
5661

57-
pg_last_oid($result);
58-
pg_free_result($result);
62+
pg_last_oid($result);
63+
pg_free_result($result);
64+
}
65+
pg_close($db)
5966

6067
echo "OK";
6168
?>

0 commit comments

Comments
 (0)