Skip to content

Commit 045dc10

Browse files
authored
ext/pgsql: cleanup the 3rd protocol is supported since circa 2010. (#12465)
1 parent 6518fec commit 045dc10

8 files changed

+211
-249
lines changed

ext/pgsql/pgsql.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ static int _rollback_transactions(zval *el)
362362
while ((res = PQgetResult(link))) {
363363
PQclear(res);
364364
}
365-
if ((PQprotocolVersion(link) >= 3 && PQtransactionStatus(link) != PQTRANS_IDLE) || PQprotocolVersion(link) < 3) {
365+
if (PQtransactionStatus(link) != PQTRANS_IDLE) {
366366
int orig = PGG(ignore_notices);
367367
PGG(ignore_notices) = 1;
368368
res = PQexec(link,"ROLLBACK;");
@@ -614,7 +614,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
614614
}
615615
pgsql = (PGconn *) le->ptr;
616616
/* consider to use php_version_compare() here */
617-
if (PQprotocolVersion(pgsql) >= 3 && zend_strtod(PQparameterStatus(pgsql, "server_version"), NULL) >= 7.2) {
617+
if (zend_strtod(PQparameterStatus(pgsql, "server_version"), NULL) >= 7.2) {
618618
pg_result = PQexec(pgsql, "RESET ALL;");
619619
PQclear(pg_result);
620620
}
@@ -815,31 +815,29 @@ static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type
815815
case PHP_PG_HOST:
816816
result = PQhost(pgsql);
817817
break;
818-
case PHP_PG_VERSION:
818+
case PHP_PG_VERSION: {
819819
array_init(return_value);
820+
char *tmp;
820821
add_assoc_string(return_value, "client", pgsql_libpq_version);
821822
add_assoc_long(return_value, "protocol", PQprotocolVersion(pgsql));
822-
if (PQprotocolVersion(pgsql) >= 3) {
823-
/* 8.0 or grater supports protorol version 3 */
824-
char *tmp;
825-
add_assoc_string(return_value, "server", (char*)PQparameterStatus(pgsql, "server_version"));
823+
add_assoc_string(return_value, "server", (char*)PQparameterStatus(pgsql, "server_version"));
826824

827825
#define PHP_PQ_COPY_PARAM(_x) tmp = (char*)PQparameterStatus(pgsql, _x); \
828826
if(tmp) add_assoc_string(return_value, _x, tmp); \
829827
else add_assoc_null(return_value, _x);
830828

831-
PHP_PQ_COPY_PARAM("server_encoding");
832-
PHP_PQ_COPY_PARAM("client_encoding");
833-
PHP_PQ_COPY_PARAM("is_superuser");
834-
PHP_PQ_COPY_PARAM("session_authorization");
835-
PHP_PQ_COPY_PARAM("DateStyle");
836-
PHP_PQ_COPY_PARAM("IntervalStyle");
837-
PHP_PQ_COPY_PARAM("TimeZone");
838-
PHP_PQ_COPY_PARAM("integer_datetimes");
839-
PHP_PQ_COPY_PARAM("standard_conforming_strings");
840-
PHP_PQ_COPY_PARAM("application_name");
841-
}
829+
PHP_PQ_COPY_PARAM("server_encoding");
830+
PHP_PQ_COPY_PARAM("client_encoding");
831+
PHP_PQ_COPY_PARAM("is_superuser");
832+
PHP_PQ_COPY_PARAM("session_authorization");
833+
PHP_PQ_COPY_PARAM("DateStyle");
834+
PHP_PQ_COPY_PARAM("IntervalStyle");
835+
PHP_PQ_COPY_PARAM("TimeZone");
836+
PHP_PQ_COPY_PARAM("integer_datetimes");
837+
PHP_PQ_COPY_PARAM("standard_conforming_strings");
838+
PHP_PQ_COPY_PARAM("application_name");
842839
return;
840+
}
843841
EMPTY_SWITCH_DEFAULT_CASE()
844842
}
845843
if (result) {
@@ -4015,15 +4013,15 @@ PHP_FUNCTION(pg_get_notify)
40154013
add_index_string(return_value, 0, pgsql_notify->relname);
40164014
add_index_long(return_value, 1, pgsql_notify->be_pid);
40174015
/* consider to use php_version_compare() here */
4018-
if (PQprotocolVersion(pgsql) >= 3 && zend_strtod(PQparameterStatus(pgsql, "server_version"), NULL) >= 9.0) {
4016+
if (zend_strtod(PQparameterStatus(pgsql, "server_version"), NULL) >= 9.0) {
40194017
add_index_string(return_value, 2, pgsql_notify->extra);
40204018
}
40214019
}
40224020
if (result_type & PGSQL_ASSOC) {
40234021
add_assoc_string(return_value, "message", pgsql_notify->relname);
40244022
add_assoc_long(return_value, "pid", pgsql_notify->be_pid);
40254023
/* consider to use php_version_compare() here */
4026-
if (PQprotocolVersion(pgsql) >= 3 && zend_strtod(PQparameterStatus(pgsql, "server_version"), NULL) >= 9.0) {
4024+
if (zend_strtod(PQparameterStatus(pgsql, "server_version"), NULL) >= 9.0) {
40274025
add_assoc_string(return_value, "payload", pgsql_notify->extra);
40284026
}
40294027
}

ext/pgsql/tests/23sync_query_params.phpt

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,42 @@ if (!function_exists('pg_query_params')) die('skip function pg_query_params() do
1313
include('config.inc');
1414

1515
$db = pg_connect($conn_str);
16+
$result = pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100));
17+
if (!($rows = pg_num_rows($result)))
18+
{
19+
echo "pg_num_row() error\n";
20+
}
21+
for ($i=0; $i < $rows; $i++)
22+
{
23+
pg_fetch_array($result, $i, PGSQL_NUM);
24+
}
25+
for ($i=0; $i < $rows; $i++)
26+
{
27+
pg_fetch_object($result);
28+
}
29+
for ($i=0; $i < $rows; $i++)
30+
{
31+
pg_fetch_row($result, $i);
32+
}
33+
for ($i=0; $i < $rows; $i++)
34+
{
35+
pg_fetch_result($result, $i, 0);
36+
}
1637

17-
$version = pg_version($db);
18-
if ($version['protocol'] >= 3) {
19-
$result = pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100));
20-
if (!($rows = pg_num_rows($result)))
21-
{
22-
echo "pg_num_row() error\n";
23-
}
24-
for ($i=0; $i < $rows; $i++)
25-
{
26-
pg_fetch_array($result, $i, PGSQL_NUM);
27-
}
28-
for ($i=0; $i < $rows; $i++)
29-
{
30-
pg_fetch_object($result);
31-
}
32-
for ($i=0; $i < $rows; $i++)
33-
{
34-
pg_fetch_row($result, $i);
35-
}
36-
for ($i=0; $i < $rows; $i++)
37-
{
38-
pg_fetch_result($result, $i, 0);
39-
}
40-
41-
pg_result_error($result);
42-
pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
43-
pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
44-
pg_field_name($result, 0);
45-
pg_field_num($result, $field_name);
46-
pg_field_size($result, 0);
47-
pg_field_type($result, 0);
48-
pg_field_prtlen($result, null, 0);
49-
pg_field_is_null($result, null, 0);
38+
pg_result_error($result);
39+
pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
40+
pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
41+
pg_field_name($result, 0);
42+
pg_field_num($result, $field_name);
43+
pg_field_size($result, 0);
44+
pg_field_type($result, 0);
45+
pg_field_prtlen($result, null, 0);
46+
pg_field_is_null($result, null, 0);
5047

51-
$result = pg_query_params($db, "INSERT INTO ".$table_name." VALUES (\$1, \$2);", array(9999, "A'BC"));
52-
pg_last_oid($result);
48+
$result = pg_query_params($db, "INSERT INTO ".$table_name." VALUES (\$1, \$2);", array(9999, "A'BC"));
49+
pg_last_oid($result);
5350

54-
pg_free_result($result);
55-
}
51+
pg_free_result($result);
5652
pg_close($db);
5753

5854
echo "OK";

ext/pgsql/tests/24sync_query_prepared.phpt

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,51 +14,48 @@ include('config.inc');
1414

1515
$db = pg_connect($conn_str);
1616

17-
$version = pg_version($db);
18-
if ($version['protocol'] >= 3) {
19-
$result = pg_prepare($db, "php_test", "SELECT * FROM ".$table_name." WHERE num > \$1;");
20-
pg_result_error($result);
21-
pg_free_result($result);
22-
$result = pg_execute($db, "php_test", array(100));
23-
if (!($rows = pg_num_rows($result)))
24-
{
25-
echo "pg_num_row() 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);
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-
}
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+
}
4341

44-
pg_result_error($result);
45-
pg_num_rows(pg_execute($db, "php_test", array(100)));
46-
pg_num_fields(pg_execute($db, "php_test", array(100)));
47-
pg_field_name($result, 0);
48-
pg_field_num($result, $field_name);
49-
pg_field_size($result, 0);
50-
pg_field_type($result, 0);
51-
pg_field_prtlen($result, 0);
52-
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);
5351

54-
$result = pg_prepare($db, "php_test2", "INSERT INTO ".$table_name." VALUES (\$1, \$2);");
55-
pg_result_error($result);
56-
pg_free_result($result);
57-
$result = pg_execute($db, "php_test2", array(9999, "A'BC"));
58-
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);
5957

60-
pg_free_result($result);
61-
}
58+
pg_free_result($result);
6259
pg_close($db);
6360

6461
echo "OK";

ext/pgsql/tests/25async_query_params.phpt

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,57 +13,53 @@ if (!function_exists('pg_send_query_params')) die('skip function pg_send_query_p
1313
include('config.inc');
1414

1515
$db = pg_connect($conn_str);
16+
if (!pg_send_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100))) {
17+
echo "pg_send_query_params() error\n";
18+
}
19+
while(pg_connection_busy($db)); // busy wait: intended
20+
if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
21+
echo "pg_connection_status() error\n";
22+
}
23+
if (!($result = pg_get_result($db)))
24+
{
25+
echo "pg_get_result() error\n";
26+
}
27+
if (!($rows = pg_num_rows($result))) {
28+
echo "pg_num_rows() error\n";
29+
}
30+
for ($i=0; $i < $rows; $i++)
31+
{
32+
pg_fetch_array($result, $i, PGSQL_NUM);
33+
}
34+
for ($i=0; $i < $rows; $i++)
35+
{
36+
pg_fetch_object($result);
37+
}
38+
for ($i=0; $i < $rows; $i++)
39+
{
40+
pg_fetch_row($result, $i);
41+
}
42+
for ($i=0; $i < $rows; $i++)
43+
{
44+
pg_fetch_result($result, $i, 0);
45+
}
1646

17-
$version = pg_version($db);
18-
if ($version['protocol'] >= 3) {
19-
if (!pg_send_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100))) {
20-
echo "pg_send_query_params() error\n";
21-
}
22-
while(pg_connection_busy($db)); // busy wait: intended
23-
if (pg_connection_status($db) === PGSQL_CONNECTION_BAD) {
24-
echo "pg_connection_status() error\n";
25-
}
26-
if (!($result = pg_get_result($db)))
27-
{
28-
echo "pg_get_result() error\n";
29-
}
30-
if (!($rows = pg_num_rows($result))) {
31-
echo "pg_num_rows() error\n";
32-
}
33-
for ($i=0; $i < $rows; $i++)
34-
{
35-
pg_fetch_array($result, $i, PGSQL_NUM);
36-
}
37-
for ($i=0; $i < $rows; $i++)
38-
{
39-
pg_fetch_object($result);
40-
}
41-
for ($i=0; $i < $rows; $i++)
42-
{
43-
pg_fetch_row($result, $i);
44-
}
45-
for ($i=0; $i < $rows; $i++)
46-
{
47-
pg_fetch_result($result, $i, 0);
48-
}
49-
50-
pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
51-
pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
52-
pg_field_name($result, 0);
53-
pg_field_num($result, $field_name);
54-
pg_field_size($result, 0);
55-
pg_field_type($result, 0);
56-
pg_field_prtlen($result, 0);
57-
pg_field_is_null($result, 0);
58-
59-
if (!pg_send_query_params($db, "INSERT INTO ".$table_name." VALUES (\$1, \$2);", array(9999, "A'BC")))
60-
{
61-
echo "pg_send_query_params() error\n";
62-
}
47+
pg_num_rows(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
48+
pg_num_fields(pg_query_params($db, "SELECT * FROM ".$table_name." WHERE num > \$1;", array(100)));
49+
pg_field_name($result, 0);
50+
pg_field_num($result, $field_name);
51+
pg_field_size($result, 0);
52+
pg_field_type($result, 0);
53+
pg_field_prtlen($result, 0);
54+
pg_field_is_null($result, 0);
6355

64-
pg_last_oid($result);
65-
pg_free_result($result);
56+
if (!pg_send_query_params($db, "INSERT INTO ".$table_name." VALUES (\$1, \$2);", array(9999, "A'BC")))
57+
{
58+
echo "pg_send_query_params() error\n";
6659
}
60+
61+
pg_last_oid($result);
62+
pg_free_result($result);
6763
pg_close($db);
6864

6965
echo "OK";

0 commit comments

Comments
 (0)