]> granicus.if.org Git - php/commitdiff
- Ensure that ext/pgsql tests work when linked against 7.2 or lower libpq
authorChristopher Kings-Lynne <chriskl@php.net>
Wed, 23 Mar 2005 03:24:41 +0000 (03:24 +0000)
committerChristopher Kings-Lynne <chriskl@php.net>
Wed, 23 Mar 2005 03:24:41 +0000 (03:24 +0000)
ext/pgsql/tests/02connection.phpt
ext/pgsql/tests/03sync_query.phpt
ext/pgsql/tests/23sync_query_params.phpt
ext/pgsql/tests/24sync_query_prepared.phpt
ext/pgsql/tests/25async_query_params.phpt
ext/pgsql/tests/26async_query_prepared.phpt

index 761ddc22a3ad836ecf35b4096c6e254c81df7512..6288d0e1796ea5c9bc61dc98b0f76756a40085a7 100644 (file)
@@ -23,9 +23,11 @@ if (pg_connection_busy($db))
 {
        echo "pg_connection_busy() error\n";
 }
-if (pg_transaction_status($db) != PGSQL_TRANSACTION_IDLE) 
-{
-       echo "pg_transaction_status() error\n";
+if (function_exists('pg_transaction_status')) {
+       if (pg_transaction_status($db) != PGSQL_TRANSACTION_IDLE) 
+       {
+               echo "pg_transaction_status() error\n";
+       }
 }
 if (!pg_host($db)) 
 {
index 8a61496e001a2d461e20844b258bf1f9cbf8c243..afb6bb4475fb8899f20588a1f0674121ff6d88e4 100644 (file)
@@ -32,24 +32,26 @@ for ($i=0; $i < $rows; $i++)
 }
 
 pg_result_error($result);
-pg_result_error_field($result, PGSQL_DIAG_SEVERITY);
-pg_result_error_field($result, PGSQL_DIAG_SQLSTATE);
-pg_result_error_field($result, PGSQL_DIAG_MESSAGE_PRIMARY);
-pg_result_error_field($result, PGSQL_DIAG_MESSAGE_DETAIL);
-pg_result_error_field($result, PGSQL_DIAG_MESSAGE_HINT);
-pg_result_error_field($result, PGSQL_DIAG_STATEMENT_POSITION);
-if (defined('PGSQL_DIAG_INTERNAL_POSITION'))
-{
-       pg_result_error_field($result, PGSQL_DIAG_INTERNAL_POSITION);
-}
-if (defined('PGSQL_DIAG_INTERNAL_QUERY'))
-{
-       pg_result_error_field($result, PGSQL_DIAG_INTERNAL_QUERY);
+if (function_exists('pg_result_error_field')) {
+       pg_result_error_field($result, PGSQL_DIAG_SEVERITY);
+       pg_result_error_field($result, PGSQL_DIAG_SQLSTATE);
+       pg_result_error_field($result, PGSQL_DIAG_MESSAGE_PRIMARY);
+       pg_result_error_field($result, PGSQL_DIAG_MESSAGE_DETAIL);
+       pg_result_error_field($result, PGSQL_DIAG_MESSAGE_HINT);
+       pg_result_error_field($result, PGSQL_DIAG_STATEMENT_POSITION);
+       if (defined('PGSQL_DIAG_INTERNAL_POSITION'))
+       {
+               pg_result_error_field($result, PGSQL_DIAG_INTERNAL_POSITION);
+       }
+       if (defined('PGSQL_DIAG_INTERNAL_QUERY'))
+       {
+               pg_result_error_field($result, PGSQL_DIAG_INTERNAL_QUERY);
+       }
+       pg_result_error_field($result, PGSQL_DIAG_CONTEXT);
+       pg_result_error_field($result, PGSQL_DIAG_SOURCE_FILE);
+       pg_result_error_field($result, PGSQL_DIAG_SOURCE_LINE);
+       pg_result_error_field($result, PGSQL_DIAG_SOURCE_FUNCTION);
 }
-pg_result_error_field($result, PGSQL_DIAG_CONTEXT);
-pg_result_error_field($result, PGSQL_DIAG_SOURCE_FILE);
-pg_result_error_field($result, PGSQL_DIAG_SOURCE_LINE);
-pg_result_error_field($result, PGSQL_DIAG_SOURCE_FUNCTION);
 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);
index db1cfb24f987f2e452516340b5b06d751a1c14ff..6959cd75a7d6c227af18e0da2597e66ac677d85c 100644 (file)
@@ -1,7 +1,10 @@
 --TEST--
 PostgreSQL sync query params
 --SKIPIF--
-<?php include("skipif.inc"); ?>
+<?php 
+include("skipif.inc"); 
+if (!function_exists('pg_query_params')) die('skip function pg_query_params() does not exist');
+?>
 --FILE--
 <?php
 
@@ -9,42 +12,45 @@ include('config.inc');
 
 $db = pg_connect($conn_str);
 
-$result = pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100));
-if (!($rows   = pg_num_rows($result)))
-{
-       echo "pg_num_row() error\n";
-}
-for ($i=0; $i < $rows; $i++) 
-{
-       pg_fetch_array($result, $i, PGSQL_NUM);
-}
-for ($i=0; $i < $rows; $i++) 
-{
-       pg_fetch_object($result);
-}
-for ($i=0; $i < $rows; $i++) 
-{
-       pg_fetch_row($result, $i);
-}
-for ($i=0; $i < $rows; $i++) 
-{
-       pg_fetch_result($result, $i, 0);
-}
+$version = pg_version($db);
+if ($version['protocol'] >= 3) {
+       $result = pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100));
+       if (!($rows   = pg_num_rows($result)))
+       {
+               echo "pg_num_row() error\n";
+       }
+       for ($i=0; $i < $rows; $i++) 
+       {
+               pg_fetch_array($result, $i, PGSQL_NUM);
+       }
+       for ($i=0; $i < $rows; $i++) 
+       {
+               pg_fetch_object($result);
+       }
+       for ($i=0; $i < $rows; $i++) 
+       {
+               pg_fetch_row($result, $i);
+       }
+       for ($i=0; $i < $rows; $i++) 
+       {
+               pg_fetch_result($result, $i, 0);
+       }
 
-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_size($result, 0);
-pg_field_type($result, 0);
-pg_field_prtlen($result, 0);
-pg_field_is_null($result, 0);
+       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_size($result, 0);
+       pg_field_type($result, 0);
+       pg_field_prtlen($result, 0);
+       pg_field_is_null($result, 0);
 
-$result = pg_query_params($db, "INSERT INTO ".$table_name." VALUES (\$1, \$2);", array(9999, "A'BC"));
-pg_last_oid($result);
+       $result = pg_query_params($db, "INSERT INTO ".$table_name." VALUES (\$1, \$2);", array(9999, "A'BC"));
+       pg_last_oid($result);
 
-pg_free_result($result);
+       pg_free_result($result);
+}
 pg_close($db);
 
 echo "OK";
index ff16cb69cf4a1054ec58f147045d82860167f4b2..ea8f14661a0bd31dee414731fc74c20d487db0c7 100644 (file)
@@ -12,48 +12,51 @@ include('config.inc');
 
 $db = pg_connect($conn_str);
 
-$result = pg_prepare($db, "php_test", "SELECT * FROM ".$table_name." WHERE num > \$1;");
-pg_result_error($result);
-pg_free_result($result);
-$result = pg_execute($db, "php_test", array(100));
-if (!($rows   = pg_num_rows($result)))
-{
-       echo "pg_num_row() error\n";
-}
-for ($i=0; $i < $rows; $i++) 
-{
-       pg_fetch_array($result, $i, PGSQL_NUM);
-}
-for ($i=0; $i < $rows; $i++) 
-{
-       pg_fetch_object($result);
-}
-for ($i=0; $i < $rows; $i++) 
-{
-       pg_fetch_row($result, $i);
-}
-for ($i=0; $i < $rows; $i++) 
-{
-       pg_fetch_result($result, $i, 0);
-}
+$version = pg_version($db);
+if ($version['protocol'] >= 3) {
+       $result = pg_prepare($db, "php_test", "SELECT * FROM ".$table_name." WHERE num > \$1;");
+       pg_result_error($result);
+       pg_free_result($result);
+       $result = pg_execute($db, "php_test", array(100));
+       if (!($rows   = pg_num_rows($result)))
+       {
+               echo "pg_num_row() error\n";
+       }
+       for ($i=0; $i < $rows; $i++) 
+       {
+               pg_fetch_array($result, $i, PGSQL_NUM);
+       }
+       for ($i=0; $i < $rows; $i++) 
+       {
+               pg_fetch_object($result);
+       }
+       for ($i=0; $i < $rows; $i++) 
+       {
+               pg_fetch_row($result, $i);
+       }
+       for ($i=0; $i < $rows; $i++) 
+       {
+               pg_fetch_result($result, $i, 0);
+       }
 
-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_size($result, 0);
-pg_field_type($result, 0);
-pg_field_prtlen($result, 0);
-pg_field_is_null($result, 0);
+       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_size($result, 0);
+       pg_field_type($result, 0);
+       pg_field_prtlen($result, 0);
+       pg_field_is_null($result, 0);
 
-$result = pg_prepare($db, "php_test2", "INSERT INTO ".$table_name." VALUES (\$1, \$2);");
-pg_result_error($result);
-pg_free_result($result);
-$result = pg_execute($db, "php_test2", array(9999, "A'BC"));
-pg_last_oid($result);
+       $result = pg_prepare($db, "php_test2", "INSERT INTO ".$table_name." VALUES (\$1, \$2);");
+       pg_result_error($result);
+       pg_free_result($result);
+       $result = pg_execute($db, "php_test2", array(9999, "A'BC"));
+       pg_last_oid($result);
 
-pg_free_result($result);
+       pg_free_result($result);
+}
 pg_close($db);
 
 echo "OK";
index 2d0edbb724871d4a5c2cb26e8575a55343369a8c..3244532094415ab00688cb48601bf11175985895 100644 (file)
@@ -1,7 +1,10 @@
 --TEST--
 PostgreSQL async query params
 --SKIPIF--
-<?php include("skipif.inc"); ?>
+<?php
+include("skipif.inc");
+if (!function_exists('pg_send_query_params')) die('skip function pg_send_query_params() does not exist');
+?>
 --FILE--
 <?php
 
@@ -9,53 +12,57 @@ include('config.inc');
 
 $db = pg_connect($conn_str);
 
-if (!pg_send_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100))) {
-       echo "pg_send_query_params() error\n";
-}
-while(pg_connection_busy($db));  // busy wait: intended
-if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
-       echo "pg_connection_status() error\n";
-}
-if (!($result = pg_get_result($db))) 
-{
-       echo "pg_get_result() error\n";
-}
-if (!($rows = pg_num_rows($result))) {
-       echo "pg_num_rows() error\n";
-}
-for ($i=0; $i < $rows; $i++) 
-{
-       pg_fetch_array($result, $i, PGSQL_NUM);
-}
-for ($i=0; $i < $rows; $i++) 
-{
-       pg_fetch_object($result);
-}
-for ($i=0; $i < $rows; $i++) 
-{
-       pg_fetch_row($result, $i);
-}
-for ($i=0; $i < $rows; $i++) 
-{
-       pg_fetch_result($result, $i, 0);
-}
+$version = pg_version($db);
+if ($version['protocol'] >= 3) {
+       if (!pg_send_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100))) {
+               echo "pg_send_query_params() error\n";
+       }
+       while(pg_connection_busy($db));  // busy wait: intended
+       if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
+               echo "pg_connection_status() error\n";
+       }
+       if (!($result = pg_get_result($db))) 
+       {
+               echo "pg_get_result() error\n";
+       }
+       if (!($rows = pg_num_rows($result))) {
+               echo "pg_num_rows() error\n";
+       }
+       for ($i=0; $i < $rows; $i++) 
+       {
+               pg_fetch_array($result, $i, PGSQL_NUM);
+       }
+       for ($i=0; $i < $rows; $i++) 
+       {
+               pg_fetch_object($result);
+       }
+       for ($i=0; $i < $rows; $i++) 
+       {
+               pg_fetch_row($result, $i);
+       }
+       for ($i=0; $i < $rows; $i++) 
+       {
+               pg_fetch_result($result, $i, 0);
+       }
 
-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_size($result, 0);
-pg_field_type($result, 0);
-pg_field_prtlen($result, 0);
-pg_field_is_null($result, 0);
+       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_size($result, 0);
+       pg_field_type($result, 0);
+       pg_field_prtlen($result, 0);
+       pg_field_is_null($result, 0);
 
-if (!pg_send_query_params($db, "INSERT INTO ".$table_name." VALUES (\$1, \$2);", array(9999, "A'BC")))
-{
-       echo "pg_send_query_params() error\n";
-}
+       if (!pg_send_query_params($db, "INSERT INTO ".$table_name." VALUES (\$1, \$2);", array(9999, "A'BC")))
+       {
+               echo "pg_send_query_params() error\n";
+       }
 
-pg_last_oid($result);
-pg_free_result($result);
+       pg_last_oid($result);
+       pg_free_result($result);
+}
+pg_close($db)
 
 echo "OK";
 ?>
index 90912ff0b7f34bc43af0c7d3ed5af0b41aec1b90..bda363b7501bc98beb29b679b20a52e5b76f524e 100644 (file)
@@ -12,89 +12,93 @@ include('config.inc');
 
 $db = pg_connect($conn_str);
 
-if (!pg_send_prepare($db, 'php_test', "SELECT * FROM ".$table_name." WHERE num > \$1;")) {
-       echo "pg_send_prepare() error\n";
-}
-while(pg_connection_busy($db));  // busy wait: intended
-if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
-       echo "pg_connection_status() error\n";
-}
-if (!($result = pg_get_result($db))) 
-{
-       echo "pg_get_result() error\n";
-}
-pg_free_result($result);
+$version = pg_version($db);
+if ($version['protocol'] >= 3) {
+       if (!pg_send_prepare($db, 'php_test', "SELECT * FROM ".$table_name." WHERE num > \$1;")) {
+               echo "pg_send_prepare() error\n";
+       }
+       while(pg_connection_busy($db));  // busy wait: intended
+       if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
+               echo "pg_connection_status() error\n";
+       }
+       if (!($result = pg_get_result($db))) 
+       {
+               echo "pg_get_result() error\n";
+       }
+       pg_free_result($result);
 
-if (!pg_send_execute($db, 'php_test', array(100))) {
-       echo "pg_send_execute() error\n";
-}
-while(pg_connection_busy($db));  // busy wait: intended
-if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
-       echo "pg_connection_status() error\n";
-}
-if (!($result = pg_get_result($db))) 
-{
-       echo "pg_get_result() error\n";
-}
+       if (!pg_send_execute($db, 'php_test', array(100))) {
+               echo "pg_send_execute() error\n";
+       }
+       while(pg_connection_busy($db));  // busy wait: intended
+       if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
+               echo "pg_connection_status() error\n";
+       }
+       if (!($result = pg_get_result($db))) 
+       {
+               echo "pg_get_result() error\n";
+       }
 
-if (!($rows = pg_num_rows($result))) {
-       echo "pg_num_rows() error\n";
-}
-for ($i=0; $i < $rows; $i++) 
-{
-       pg_fetch_array($result, $i, PGSQL_NUM);
-}
-for ($i=0; $i < $rows; $i++) 
-{
-       pg_fetch_object($result);
-}
-for ($i=0; $i < $rows; $i++) 
-{
-       pg_fetch_row($result, $i);
-}
-for ($i=0; $i < $rows; $i++) 
-{
-       pg_fetch_result($result, $i, 0);
-}
+       if (!($rows = pg_num_rows($result))) {
+               echo "pg_num_rows() error\n";
+       }
+       for ($i=0; $i < $rows; $i++) 
+       {
+               pg_fetch_array($result, $i, PGSQL_NUM);
+       }
+       for ($i=0; $i < $rows; $i++) 
+       {
+               pg_fetch_object($result);
+       }
+       for ($i=0; $i < $rows; $i++) 
+       {
+               pg_fetch_row($result, $i);
+       }
+       for ($i=0; $i < $rows; $i++) 
+       {
+               pg_fetch_result($result, $i, 0);
+       }
 
-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_size($result, 0);
-pg_field_type($result, 0);
-pg_field_prtlen($result, 0);
-pg_field_is_null($result, 0);
+       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_size($result, 0);
+       pg_field_type($result, 0);
+       pg_field_prtlen($result, 0);
+       pg_field_is_null($result, 0);
 
-if (!pg_send_prepare($db, "php_test2", "INSERT INTO ".$table_name." VALUES (\$1, \$2);"))
-{
-       echo "pg_send_prepare() error\n";
-}
-while(pg_connection_busy($db));  // busy wait: intended
-if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
-       echo "pg_connection_status() error\n";
-}
-if (!($result = pg_get_result($db))) 
-{
-       echo "pg_get_result() error\n";
-}
-pg_free_result($result);
+       if (!pg_send_prepare($db, "php_test2", "INSERT INTO ".$table_name." VALUES (\$1, \$2);"))
+       {
+               echo "pg_send_prepare() error\n";
+       }
+       while(pg_connection_busy($db));  // busy wait: intended
+       if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
+               echo "pg_connection_status() error\n";
+       }
+       if (!($result = pg_get_result($db))) 
+       {
+               echo "pg_get_result() error\n";
+       }
+       pg_free_result($result);
 
-if (!pg_send_execute($db, "php_test2", array(9999, "A'BC")))
-{
-       echo "pg_send_execute() error\n";
-}
-while(pg_connection_busy($db));  // busy wait: intended
-if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
-       echo "pg_connection_status() error\n";
-}
-if (!($result = pg_get_result($db))) 
-{
-       echo "pg_get_result() error\n";
-}
+       if (!pg_send_execute($db, "php_test2", array(9999, "A'BC")))
+       {
+               echo "pg_send_execute() error\n";
+       }
+       while(pg_connection_busy($db));  // busy wait: intended
+       if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
+               echo "pg_connection_status() error\n";
+       }
+       if (!($result = pg_get_result($db))) 
+       {
+               echo "pg_get_result() error\n";
+       }
 
-pg_last_oid($result);
-pg_free_result($result);
+       pg_last_oid($result);
+       pg_free_result($result);
+}
+pg_close($db);
 
 echo "OK";
 ?>