Skip to content

Commit 366924e

Browse files
committed
Deprecate implicit default PGSQL connection
1 parent 2bc23cc commit 366924e

40 files changed

+307
-107
lines changed

ext/pgsql/pgsql.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,15 @@
7878
zend_throw_error(NULL, "No PostgreSQL connection opened yet"); \
7979
RETURN_THROWS(); \
8080
}
81+
82+
/* This is a bit hacky as the macro usage is "link = FETCH_DEFAULT_LINK();" */
8183
#define FETCH_DEFAULT_LINK() \
82-
(PGG(default_link) ? pgsql_link_from_obj(PGG(default_link)) : NULL)
84+
(PGG(default_link) ? pgsql_link_from_obj(PGG(default_link)) : NULL); \
85+
php_error_docref(NULL, E_DEPRECATED, "Automatic fetching of PostgreSQL connection is deprecated")
86+
87+
/* Used only when creating a connection */
88+
#define FETCH_DEFAULT_LINK_NO_WARNING() \
89+
(PGG(default_link) ? pgsql_link_from_obj(PGG(default_link)) : NULL)
8390

8491
#define CHECK_PGSQL_LINK(link_handle) \
8592
if (link_handle->conn == NULL) { \
@@ -850,7 +857,7 @@ PHP_FUNCTION(pg_close)
850857
link = Z_PGSQL_LINK_P(pgsql_link);
851858
CHECK_PGSQL_LINK(link);
852859

853-
if (link == FETCH_DEFAULT_LINK()) {
860+
if (link == FETCH_DEFAULT_LINK_NO_WARNING()) {
854861
GC_DELREF(PGG(default_link));
855862
PGG(default_link) = NULL;
856863
}

ext/pgsql/tests/01createdb.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ else {
2222
echo pg_last_error()."\n";
2323
}
2424

25-
$v = pg_version();
25+
$v = pg_version($db);
2626
if (version_compare($v['server'], '9.2', '>=') && (!($q = @pg_query($db, "SELECT * FROM ".$table_name_92)) || !@pg_num_rows($q)))
2727
{
2828
pg_query($db,$table_def_92); // Create table here

ext/pgsql/tests/05large_object.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ try {
103103

104104
echo "OK";
105105
?>
106-
--EXPECT--
106+
--EXPECTF--
107107
create/write/close LO
108108
open/read/tell/seek/close LO
109109
string(5) "large"
@@ -120,10 +120,16 @@ large object data
120120
int(17)
121121
unlink LO
122122
Test without connection
123+
124+
Deprecated: pg_lo_unlink(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
123125
Test with string oid value
124126
import/export LO
127+
128+
Deprecated: pg_lo_create(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
125129
Invalid OID value passed
126130
Invalid OID value passed
131+
132+
Deprecated: pg_lo_create(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
127133
Invalid OID value passed
128134
Invalid OID value passed
129135
OK

ext/pgsql/tests/07optional.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ $enc = pg_client_encoding($db);
1616
pg_set_client_encoding($db, $enc);
1717

1818
if (function_exists('pg_set_error_verbosity')) {
19-
pg_set_error_verbosity(PGSQL_ERRORS_TERSE);
20-
pg_set_error_verbosity(PGSQL_ERRORS_DEFAULT);
21-
pg_set_error_verbosity(PGSQL_ERRORS_VERBOSE);
19+
pg_set_error_verbosity($db, PGSQL_ERRORS_TERSE);
20+
pg_set_error_verbosity($db, PGSQL_ERRORS_DEFAULT);
21+
pg_set_error_verbosity($db, PGSQL_ERRORS_VERBOSE);
2222
}
2323
echo "OK";
2424
?>

ext/pgsql/tests/08escape.phpt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ $db = pg_connect($conn_str);
4545

4646
// Insert binary to DB
4747
$escaped_data = pg_escape_bytea($data);
48-
pg_query("DELETE FROM ".$table_name." WHERE num = 10000;");
48+
pg_query($db, "DELETE FROM ".$table_name." WHERE num = 10000;");
4949
$sql = "INSERT INTO ".$table_name." (num, bin) VALUES (10000, CAST ('".$escaped_data."' AS BYTEA));";
5050
pg_query($db, $sql);
5151

@@ -98,9 +98,18 @@ else {
9898
}
9999

100100
?>
101-
--EXPECT--
101+
--EXPECTF--
102+
Deprecated: pg_escape_string(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
102103
pg_escape_string() is Ok
104+
105+
Deprecated: pg_escape_bytea(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
103106
pg_escape_bytea() is Ok
107+
108+
Deprecated: pg_escape_bytea(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
104109
pg_escape_bytea() actually works with database
110+
111+
Deprecated: pg_escape_literal(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
105112
pg_escape_literal() is Ok
113+
114+
Deprecated: pg_escape_identifier(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
106115
pg_escape_identifier() is Ok

ext/pgsql/tests/09notice.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ini_set('pgsql.ignore_notice', FALSE);
2020

2121
$db = pg_connect($conn_str);
2222

23-
_set_lc_messages();
23+
_set_lc_messages($db);
2424

2525
$res = pg_query($db, 'SET client_min_messages TO NOTICE;');
2626
var_dump($res);

ext/pgsql/tests/13pg_select_9.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ error_reporting(E_ALL);
1414
include 'config.inc';
1515

1616
$db = pg_connect($conn_str);
17-
pg_query("SET bytea_output = 'hex'");
17+
pg_query($db, "SET bytea_output = 'hex'");
1818

1919
$fields = array('num'=>'1234', 'str'=>'ABC', 'bin'=>'XYZ');
2020
$ids = array('num'=>'1234');

ext/pgsql/tests/18pg_escape_bytea_before.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ else {
2828
echo "OK";
2929
}
3030
?>
31-
--EXPECT--
31+
--EXPECTF--
32+
Deprecated: pg_escape_bytea(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
3233
OK

ext/pgsql/tests/18pg_escape_bytea_esc.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ else {
2828
echo "OK";
2929
}
3030
?>
31-
--EXPECT--
31+
--EXPECTF--
32+
Deprecated: pg_escape_bytea(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
3233
OK

ext/pgsql/tests/18pg_escape_bytea_hex.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ else {
3131
echo "OK";
3232
}
3333
?>
34-
--EXPECT--
34+
--EXPECTF--
35+
Deprecated: pg_escape_bytea(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
3536
OK

ext/pgsql/tests/27large_object_oid.phpt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,16 @@ pg_exec ("commit");
4242

4343
echo "OK";
4444
?>
45-
--EXPECT--
45+
--EXPECTF--
4646
create LO from int
4747
create LO from string
4848
create LO using default connection
49+
50+
Deprecated: pg_exec(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
51+
52+
Deprecated: pg_lo_create(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
53+
54+
Deprecated: pg_lo_unlink(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
55+
56+
Deprecated: pg_exec(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
4957
OK

ext/pgsql/tests/28large_object_import_oid.phpt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,26 @@ try {
8484

8585
echo "OK";
8686
?>
87-
--EXPECT--
87+
--EXPECTF--
8888
import LO from int
8989
import LO from string
9090
import LO using default connection
91+
92+
Deprecated: pg_exec(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
93+
94+
Deprecated: pg_lo_unlink(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
95+
96+
Deprecated: pg_exec(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
97+
98+
Deprecated: pg_lo_import(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
9199
Invalid OID value passed
92100
Invalid OID value passed
101+
102+
Deprecated: pg_lo_import(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
93103
Invalid OID value passed
94104
Invalid OID value passed
105+
106+
Deprecated: pg_lo_import(): Automatic fetching of PostgreSQL connection is deprecated in %s on line %d
95107
OID value must be of type string|int, bool given
96108
OID value must be of type string|int, array given
97109
OID value must be of type string|int, stdClass given

ext/pgsql/tests/80_bug24499.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ if (!$dbh) {
1616
die ("Could not connect to the server");
1717
}
1818

19-
@pg_query("DROP SEQUENCE id_id_seq");
20-
@pg_query("DROP TABLE id");
21-
pg_query("CREATE TABLE id (id SERIAL, t INT)");
19+
@pg_query($dbh, "DROP SEQUENCE id_id_seq");
20+
@pg_query($dbh, "DROP TABLE id");
21+
pg_query($dbh, "CREATE TABLE id (id SERIAL, t INT)");
2222

2323
for ($i=0; $i<4; $i++) {
24-
pg_query("INSERT INTO id (t) VALUES ($i)");
24+
pg_query($dbh, "INSERT INTO id (t) VALUES ($i)");
2525
}
2626

2727
class Id

ext/pgsql/tests/80_bug27597.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ if (!$dbh) {
1616
die ("Could not connect to the server");
1717
}
1818

19-
@pg_query("DROP TABLE id");
20-
pg_query("CREATE TABLE id (id INT)");
19+
@pg_query($dbh, "DROP TABLE id");
20+
pg_query($dbh, "CREATE TABLE id (id INT)");
2121

2222
for ($i=0; $i<4; $i++) {
23-
pg_query("INSERT INTO id (id) VALUES ($i)");
23+
pg_query($dbh, "INSERT INTO id (id) VALUES ($i)");
2424
}
2525

2626
function xi_fetch_array($res, $type = PGSQL_ASSOC) {
2727
$a = pg_fetch_array($res, NULL, $type) ;
2828
return $a ;
2929
}
3030

31-
$res = pg_query("SELECT * FROM id");
31+
$res = pg_query($dbh, "SELECT * FROM id");
3232
$i = 0; // endless-loop protection
3333
while($row = xi_fetch_array($res)) {
3434
print_r($row);

ext/pgsql/tests/80_bug32223.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pgsql
66
<?php
77
require_once('skipif.inc');
88

9-
_skip_lc_messages();
9+
_skip_lc_messages($conn);
1010

1111
@pg_query($conn, "CREATE LANGUAGE 'plpgsql' HANDLER plpgsql_call_handler LANCOMPILER 'PL/pgSQL'");
1212
$res = @pg_query($conn, "CREATE OR REPLACE FUNCTION test_notice() RETURNS boolean AS '
@@ -30,7 +30,7 @@ if (!$dbh) {
3030
die ("Could not connect to the server");
3131
}
3232

33-
_set_lc_messages();
33+
_set_lc_messages($dbh);
3434

3535
$res = pg_query($dbh, "CREATE OR REPLACE FUNCTION test_notice() RETURNS boolean AS '
3636
begin

ext/pgsql/tests/80_bug32223b.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if (!$dbh) {
3030
die ("Could not connect to the server");
3131
}
3232

33-
_set_lc_messages();
33+
_set_lc_messages(dbh);
3434

3535
$res = pg_query($dbh, "CREATE OR REPLACE FUNCTION test_notice() RETURNS boolean AS '
3636
begin

ext/pgsql/tests/80_bug39971.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if (!$dbh) {
1616
die ("Could not connect to the server");
1717
}
1818

19-
pg_query("CREATE TABLE php_test (id SERIAL, tm timestamp NOT NULL)");
19+
pg_query($dbh, "CREATE TABLE php_test (id SERIAL, tm timestamp NOT NULL)");
2020

2121
$values = array('tm' => 'now()');
2222
pg_insert($dbh, 'php_test', $values);

ext/pgsql/tests/80_bug42783.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ if (!$dbh) {
1616
die ("Could not connect to the server");
1717
}
1818

19-
pg_query("CREATE TABLE php_test (id SERIAL PRIMARY KEY, time TIMESTAMP NOT NULL DEFAULT now())");
19+
pg_query($dbh, "CREATE TABLE php_test (id SERIAL PRIMARY KEY, time TIMESTAMP NOT NULL DEFAULT now())");
2020

2121
pg_insert($dbh, 'php_test', array());
2222

23-
var_dump(pg_fetch_assoc(pg_query("SELECT * FROM php_test")));
23+
var_dump(pg_fetch_assoc(pg_query($dbh, "SELECT * FROM php_test")));
2424

2525
pg_query($dbh, "DROP TABLE php_test");
2626
pg_close($dbh);

ext/pgsql/tests/98old_api.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pgsql
1010
include('config.inc');
1111

1212
$db = pg_connect($conn_str);
13-
$result = pg_exec("SELECT * FROM ".$table_name);
13+
$result = pg_exec($db, "SELECT * FROM ".$table_name);
1414
pg_numrows($result);
1515
pg_numfields($result);
1616
pg_fieldname($result, 0);
@@ -20,11 +20,11 @@ pg_fieldprtlen($result, 0);
2020
pg_fieldisnull($result, 0);
2121

2222
pg_result($result,0,0);
23-
$result = pg_exec("INSERT INTO ".$table_name." VALUES (7777, 'KKK')");
23+
$result = pg_exec($db, "INSERT INTO ".$table_name." VALUES (7777, 'KKK')");
2424
$oid = pg_getlastoid($result);
2525
pg_freeresult($result);
26-
pg_errormessage();
27-
$result = pg_exec("UPDATE ".$table_name." SET str = 'QQQ' WHERE str like 'RGD';");
26+
pg_errormessage($db);
27+
$result = pg_exec($db, "UPDATE ".$table_name." SET str = 'QQQ' WHERE str like 'RGD';");
2828
pg_cmdtuples($result);
2929

3030

ext/pgsql/tests/bug37100_9.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ include 'config.inc';
1414

1515
$db = pg_connect($conn_str);
1616

17-
@pg_query('DROP TABLE test_bug');
17+
@pg_query($db, 'DROP TABLE test_bug');
1818

19-
pg_query('CREATE TABLE test_bug (binfield byteA) ;');
20-
pg_query("INSERT INTO test_bug VALUES (decode('0103AA000812','hex'))");
19+
pg_query($db, 'CREATE TABLE test_bug (binfield byteA) ;');
20+
pg_query($db, "INSERT INTO test_bug VALUES (decode('0103AA000812','hex'))");
2121

2222

23-
$data = pg_query("SELECT binfield FROM test_bug");
23+
$data = pg_query($db, "SELECT binfield FROM test_bug");
2424
$res = pg_fetch_result($data,0);
2525
var_dump($res);
2626
var_dump(bin2hex(pg_unescape_bytea($res)));
2727

2828
$sql = "BEGIN; DECLARE mycursor BINARY CURSOR FOR SELECT binfield FROM test_bug; FETCH ALL IN mycursor;";
2929

30-
$data = pg_query($sql);
30+
$data = pg_query($db, $sql);
3131
$res = pg_fetch_result($data,0);
3232

3333
var_dump(strlen($res));
@@ -36,7 +36,7 @@ var_dump(bin2hex($res));
3636
pg_close($db);
3737

3838
$db = pg_connect($conn_str);
39-
pg_query('DROP TABLE test_bug');
39+
pg_query($db, 'DROP TABLE test_bug');
4040
pg_close($db);
4141

4242

ext/pgsql/tests/bug47199.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ require_once('config.inc');
1313

1414
$dbh = pg_connect($conn_str);
1515
$tbl_name = 'test_47199';
16-
@pg_query("DROP TABLE $tbl_name");
17-
pg_query("CREATE TABLE $tbl_name (null_field INT, not_null_field INT NOT NULL)");
16+
@pg_query($dbh, "DROP TABLE $tbl_name");
17+
pg_query($dbh, "CREATE TABLE $tbl_name (null_field INT, not_null_field INT NOT NULL)");
1818

1919
pg_insert($dbh, $tbl_name, array('null_field' => null, 'not_null_field' => 1));
2020
pg_insert($dbh, $tbl_name, array('null_field' => null, 'not_null_field' => 2));
2121

22-
var_dump(pg_fetch_all(pg_query('SELECT * FROM '. $tbl_name)));
22+
var_dump(pg_fetch_all(pg_query($dbh, 'SELECT * FROM '. $tbl_name)));
2323

2424
$query = pg_delete($dbh, $tbl_name, array('null_field' => NULL,'not_null_field' => 2), PGSQL_DML_STRING|PGSQL_DML_EXEC);
2525

@@ -29,9 +29,9 @@ $query = pg_update($dbh, $tbl_name, array('null_field' => NULL, 'not_null_field'
2929

3030
echo $query, "\n";
3131

32-
var_dump(pg_fetch_all(pg_query('SELECT * FROM '. $tbl_name)));
32+
var_dump(pg_fetch_all(pg_query($dbh, 'SELECT * FROM '. $tbl_name)));
3333

34-
@pg_query("DROP TABLE $tbl_name");
34+
@pg_query($dbh, "DROP TABLE $tbl_name");
3535
pg_close($dbh);
3636

3737
echo PHP_EOL."Done".PHP_EOL;

ext/pgsql/tests/bug60244.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ include("skipif.inc");
1212
include 'config.inc';
1313

1414
$db = pg_connect($conn_str);
15-
$result = pg_query("select 'a' union select 'b'");
15+
$result = pg_query($db, "select 'a' union select 'b'");
1616

1717
try {
1818
var_dump(pg_fetch_array($result, -1));

ext/pgsql/tests/bug64609.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ error_reporting(E_ALL);
1414
include 'config.inc';
1515

1616
$db = pg_connect($conn_str);
17-
pg_query("BEGIN");
18-
pg_query("CREATE TYPE t_enum AS ENUM ('ok', 'ko')");
19-
pg_query("CREATE TABLE test_enum (a t_enum)");
17+
pg_query($db, "BEGIN");
18+
pg_query($db, "CREATE TYPE t_enum AS ENUM ('ok', 'ko')");
19+
pg_query($db, "CREATE TABLE test_enum (a t_enum)");
2020

2121
$fields = array('a' => 'ok');
2222
$converted = pg_convert($db, 'test_enum', $fields);
2323

24-
pg_query("ROLLBACK");
24+
pg_query($db, "ROLLBACK");
2525

2626
var_dump($converted);
2727
?>

0 commit comments

Comments
 (0)