From 5d22cd63d4505d5ec0375207afa91881286a91c2 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Tue, 17 Oct 2023 21:13:51 +0100 Subject: [PATCH] ext/pgsql: cleanup the 3rd protocol is supported since circa 2010. --- ext/pgsql/pgsql.c | 38 ++--- ext/pgsql/tests/23sync_query_params.phpt | 70 ++++---- ext/pgsql/tests/24sync_query_prepared.phpt | 81 +++++---- ext/pgsql/tests/25async_query_params.phpt | 92 +++++----- ext/pgsql/tests/26async_query_prepared.phpt | 158 +++++++++--------- ext/pgsql/tests/30nb_async_query_params.phpt | 7 - .../tests/31nb_async_query_prepared.phpt | 7 - ext/pgsql/tests/32nb_async_query.phpt | 7 - 8 files changed, 211 insertions(+), 249 deletions(-) diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 09d8c2875db75..fb88e55d20f7b 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -362,7 +362,7 @@ static int _rollback_transactions(zval *el) while ((res = PQgetResult(link))) { PQclear(res); } - if ((PQprotocolVersion(link) >= 3 && PQtransactionStatus(link) != PQTRANS_IDLE) || PQprotocolVersion(link) < 3) { + if (PQtransactionStatus(link) != PQTRANS_IDLE) { int orig = PGG(ignore_notices); PGG(ignore_notices) = 1; res = PQexec(link,"ROLLBACK;"); @@ -614,7 +614,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) } pgsql = (PGconn *) le->ptr; /* consider to use php_version_compare() here */ - if (PQprotocolVersion(pgsql) >= 3 && zend_strtod(PQparameterStatus(pgsql, "server_version"), NULL) >= 7.2) { + if (zend_strtod(PQparameterStatus(pgsql, "server_version"), NULL) >= 7.2) { pg_result = PQexec(pgsql, "RESET ALL;"); PQclear(pg_result); } @@ -815,31 +815,29 @@ static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type case PHP_PG_HOST: result = PQhost(pgsql); break; - case PHP_PG_VERSION: + case PHP_PG_VERSION: { array_init(return_value); + char *tmp; add_assoc_string(return_value, "client", pgsql_libpq_version); add_assoc_long(return_value, "protocol", PQprotocolVersion(pgsql)); - if (PQprotocolVersion(pgsql) >= 3) { - /* 8.0 or grater supports protorol version 3 */ - char *tmp; - add_assoc_string(return_value, "server", (char*)PQparameterStatus(pgsql, "server_version")); + add_assoc_string(return_value, "server", (char*)PQparameterStatus(pgsql, "server_version")); #define PHP_PQ_COPY_PARAM(_x) tmp = (char*)PQparameterStatus(pgsql, _x); \ if(tmp) add_assoc_string(return_value, _x, tmp); \ else add_assoc_null(return_value, _x); - PHP_PQ_COPY_PARAM("server_encoding"); - PHP_PQ_COPY_PARAM("client_encoding"); - PHP_PQ_COPY_PARAM("is_superuser"); - PHP_PQ_COPY_PARAM("session_authorization"); - PHP_PQ_COPY_PARAM("DateStyle"); - PHP_PQ_COPY_PARAM("IntervalStyle"); - PHP_PQ_COPY_PARAM("TimeZone"); - PHP_PQ_COPY_PARAM("integer_datetimes"); - PHP_PQ_COPY_PARAM("standard_conforming_strings"); - PHP_PQ_COPY_PARAM("application_name"); - } + PHP_PQ_COPY_PARAM("server_encoding"); + PHP_PQ_COPY_PARAM("client_encoding"); + PHP_PQ_COPY_PARAM("is_superuser"); + PHP_PQ_COPY_PARAM("session_authorization"); + PHP_PQ_COPY_PARAM("DateStyle"); + PHP_PQ_COPY_PARAM("IntervalStyle"); + PHP_PQ_COPY_PARAM("TimeZone"); + PHP_PQ_COPY_PARAM("integer_datetimes"); + PHP_PQ_COPY_PARAM("standard_conforming_strings"); + PHP_PQ_COPY_PARAM("application_name"); return; + } EMPTY_SWITCH_DEFAULT_CASE() } if (result) { @@ -4015,7 +4013,7 @@ PHP_FUNCTION(pg_get_notify) add_index_string(return_value, 0, pgsql_notify->relname); add_index_long(return_value, 1, pgsql_notify->be_pid); /* consider to use php_version_compare() here */ - if (PQprotocolVersion(pgsql) >= 3 && zend_strtod(PQparameterStatus(pgsql, "server_version"), NULL) >= 9.0) { + if (zend_strtod(PQparameterStatus(pgsql, "server_version"), NULL) >= 9.0) { add_index_string(return_value, 2, pgsql_notify->extra); } } @@ -4023,7 +4021,7 @@ PHP_FUNCTION(pg_get_notify) add_assoc_string(return_value, "message", pgsql_notify->relname); add_assoc_long(return_value, "pid", pgsql_notify->be_pid); /* consider to use php_version_compare() here */ - if (PQprotocolVersion(pgsql) >= 3 && zend_strtod(PQparameterStatus(pgsql, "server_version"), NULL) >= 9.0) { + if (zend_strtod(PQparameterStatus(pgsql, "server_version"), NULL) >= 9.0) { add_assoc_string(return_value, "payload", pgsql_notify->extra); } } diff --git a/ext/pgsql/tests/23sync_query_params.phpt b/ext/pgsql/tests/23sync_query_params.phpt index 8d610b4b7ec1c..b3fa1d4adc835 100644 --- a/ext/pgsql/tests/23sync_query_params.phpt +++ b/ext/pgsql/tests/23sync_query_params.phpt @@ -13,46 +13,42 @@ if (!function_exists('pg_query_params')) die('skip function pg_query_params() do 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, null, 0); - pg_field_is_null($result, null, 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, null, 0); +pg_field_is_null($result, null, 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"; diff --git a/ext/pgsql/tests/24sync_query_prepared.phpt b/ext/pgsql/tests/24sync_query_prepared.phpt index 63ce3f61f0487..92bb6ac8f6122 100644 --- a/ext/pgsql/tests/24sync_query_prepared.phpt +++ b/ext/pgsql/tests/24sync_query_prepared.phpt @@ -14,51 +14,48 @@ include('config.inc'); $db = pg_connect($conn_str); -$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); - } +$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"; diff --git a/ext/pgsql/tests/25async_query_params.phpt b/ext/pgsql/tests/25async_query_params.phpt index bc3151273da61..1c33160a5a480 100644 --- a/ext/pgsql/tests/25async_query_params.phpt +++ b/ext/pgsql/tests/25async_query_params.phpt @@ -13,57 +13,53 @@ if (!function_exists('pg_send_query_params')) die('skip function pg_send_query_p 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); - - 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_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_last_oid($result); - pg_free_result($result); +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_close($db); echo "OK"; diff --git a/ext/pgsql/tests/26async_query_prepared.phpt b/ext/pgsql/tests/26async_query_prepared.phpt index f347146240220..8f0adb6cda262 100644 --- a/ext/pgsql/tests/26async_query_prepared.phpt +++ b/ext/pgsql/tests/26async_query_prepared.phpt @@ -13,93 +13,89 @@ if (!function_exists('pg_send_prepare')) die('skip function pg_send_prepare() do 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 (!($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 (!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"; +} - 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 (!($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 (!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); +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_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_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); - pg_last_oid($result); - 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"; +} + +pg_last_oid($result); +pg_free_result($result); pg_close($db); echo "OK"; diff --git a/ext/pgsql/tests/30nb_async_query_params.phpt b/ext/pgsql/tests/30nb_async_query_params.phpt index 8a05f3f6ed9a4..00fcb80c629da 100644 --- a/ext/pgsql/tests/30nb_async_query_params.phpt +++ b/ext/pgsql/tests/30nb_async_query_params.phpt @@ -14,13 +14,6 @@ include('config.inc'); include('nonblocking.inc'); $db = pg_connect($conn_str); - -$version = pg_version($db); -if ($version['protocol'] < 3) { - echo "OK"; - exit(0); -} - $db_socket = pg_socket($db); stream_set_blocking($db_socket, false); diff --git a/ext/pgsql/tests/31nb_async_query_prepared.phpt b/ext/pgsql/tests/31nb_async_query_prepared.phpt index 53382affb2646..42020181aa723 100644 --- a/ext/pgsql/tests/31nb_async_query_prepared.phpt +++ b/ext/pgsql/tests/31nb_async_query_prepared.phpt @@ -14,13 +14,6 @@ include('config.inc'); include('nonblocking.inc'); $db = pg_connect($conn_str); - -$version = pg_version($db); -if ($version['protocol'] < 3) { - echo "OK"; - exit(0); -} - $db_socket = pg_socket($db); stream_set_blocking($db_socket, false); diff --git a/ext/pgsql/tests/32nb_async_query.phpt b/ext/pgsql/tests/32nb_async_query.phpt index c4884cdf9e65e..634e6f04dbbd5 100644 --- a/ext/pgsql/tests/32nb_async_query.phpt +++ b/ext/pgsql/tests/32nb_async_query.phpt @@ -14,13 +14,6 @@ include('config.inc'); include('nonblocking.inc'); $db = pg_connect($conn_str); - -$version = pg_version($db); -if ($version['protocol'] < 3) { - echo "OK"; - exit(0); -} - $db_socket = pg_socket($db); stream_set_blocking($db_socket, false);