Skip to content

Commit 9e03cf9

Browse files
committed
Deprecate implicit default PGSQL connection
1 parent 6690547 commit 9e03cf9

40 files changed

+305
-107
lines changed

ext/pgsql/pgsql.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@
8080
zend_throw_error(NULL, "No PostgreSQL link opened yet"); \
8181
RETURN_THROWS(); \
8282
}
83-
#define FETCH_DEFAULT_LINK() PGG(default_link)
83+
84+
/* This is a bit hacky as the macro usage is "link = FETCH_DEFAULT_LINK();" */
85+
#define FETCH_DEFAULT_LINK() \
86+
PGG(default_link); \
87+
php_error_docref(NULL, E_DEPRECATED, "Automatic fetching of PostgreSQL link is deprecated")
8488

8589
#ifndef HAVE_PQFREEMEM
8690
#define PQfreemem free
@@ -735,6 +739,7 @@ PHP_FUNCTION(pg_close)
735739
}
736740

737741
if (!pgsql_link) {
742+
php_error_docref(NULL, E_DEPRECATED, "Automatic fetching of PostgreSQL link is deprecated");
738743
link = PGG(default_link);
739744
CHECK_DEFAULT_LINK(link);
740745
zend_list_delete(link);

ext/pgsql/tests/01createdb.phpt

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

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

ext/pgsql/tests/05large_object.phpt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ echo "open/read_all/close LO\n";
3232
pg_exec ($db, "begin");
3333
$handle = pg_lo_open ($db, $oid, "w");
3434
pg_lo_read_all($handle);
35-
if (pg_last_error()) echo "pg_lo_read_all() error\n".pg_last_error();
35+
if (pg_last_error($db)) echo "pg_lo_read_all() error\n".pg_last_error();
3636
pg_lo_close($handle);
3737
pg_exec ($db, "commit");
3838

@@ -92,17 +92,23 @@ try {
9292

9393
echo "OK";
9494
?>
95-
--EXPECT--
95+
--EXPECTF--
9696
create/write/close LO
9797
open/read/tell/seek/close LO
9898
open/read_all/close LO
9999
large object data
100100
unlink LO
101101
Test without connection
102+
103+
Deprecated: pg_lo_unlink(): Automatic fetching of PostgreSQL link is deprecated in %s on line %d
102104
Test with string oid value
103105
import/export LO
106+
107+
Deprecated: pg_lo_create(): Automatic fetching of PostgreSQL link is deprecated in %s on line %d
104108
Invalid OID value passed
105109
Invalid OID value passed
110+
111+
Deprecated: pg_lo_create(): Automatic fetching of PostgreSQL link is deprecated in %s on line %d
106112
Invalid OID value passed
107113
Invalid OID value passed
108114
OK

ext/pgsql/tests/07optional.phpt

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

1616
if (function_exists('pg_set_error_verbosity')) {
17-
pg_set_error_verbosity(PGSQL_ERRORS_TERSE);
18-
pg_set_error_verbosity(PGSQL_ERRORS_DEFAULT);
19-
pg_set_error_verbosity(PGSQL_ERRORS_VERBOSE);
17+
pg_set_error_verbosity($db, PGSQL_ERRORS_TERSE);
18+
pg_set_error_verbosity($db, PGSQL_ERRORS_DEFAULT);
19+
pg_set_error_verbosity($db, PGSQL_ERRORS_VERBOSE);
2020
}
2121
echo "OK";
2222
?>

ext/pgsql/tests/08escape.phpt

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

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

@@ -96,9 +96,18 @@ else {
9696
}
9797

9898
?>
99-
--EXPECT--
99+
--EXPECTF--
100+
Deprecated: pg_escape_string(): Automatic fetching of PostgreSQL link is deprecated in %s on line %d
100101
pg_escape_string() is Ok
102+
103+
Deprecated: pg_escape_bytea(): Automatic fetching of PostgreSQL link is deprecated in %s on line %d
101104
pg_escape_bytea() is Ok
105+
106+
Deprecated: pg_escape_bytea(): Automatic fetching of PostgreSQL link is deprecated in %s on line %d
102107
pg_escape_bytea() actually works with database
108+
109+
Deprecated: pg_escape_literal(): Automatic fetching of PostgreSQL link is deprecated in %s on line %d
103110
pg_escape_literal() is Ok
111+
112+
Deprecated: pg_escape_identifier(): Automatic fetching of PostgreSQL link is deprecated in %s on line %d
104113
pg_escape_identifier() is Ok

ext/pgsql/tests/09notice.phpt

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

1919
$db = pg_connect($conn_str);
2020

21-
_set_lc_messages();
21+
_set_lc_messages($db);
2222

2323
$res = pg_query($db, 'SET client_min_messages TO NOTICE;');
2424
var_dump($res);

ext/pgsql/tests/13pg_select_9.phpt

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

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

1717
$fields = array('num'=>'1234', 'str'=>'ABC', 'bin'=>'XYZ');
1818
$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
@@ -26,5 +26,6 @@ else {
2626
echo "OK";
2727
}
2828
?>
29-
--EXPECT--
29+
--EXPECTF--
30+
Deprecated: pg_escape_bytea(): Automatic fetching of PostgreSQL link is deprecated in %s on line %d
3031
OK

ext/pgsql/tests/18pg_escape_bytea_esc.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ else {
2626
echo "OK";
2727
}
2828
?>
29-
--EXPECT--
29+
--EXPECTF--
30+
Deprecated: pg_escape_bytea(): Automatic fetching of PostgreSQL link is deprecated in %s on line %d
3031
OK

ext/pgsql/tests/18pg_escape_bytea_hex.phpt

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

ext/pgsql/tests/27large_object_oid.phpt

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

4141
echo "OK";
4242
?>
43-
--EXPECT--
43+
--EXPECTF--
4444
create LO from int
4545
create LO from string
4646
create LO using default connection
47+
48+
Deprecated: pg_exec(): Automatic fetching of PostgreSQL link is deprecated in %s on line %d
49+
50+
Deprecated: pg_lo_create(): Automatic fetching of PostgreSQL link is deprecated in %s on line %d
51+
52+
Deprecated: pg_lo_unlink(): Automatic fetching of PostgreSQL link is deprecated in %s on line %d
53+
54+
Deprecated: pg_exec(): Automatic fetching of PostgreSQL link is deprecated in %s on line %d
4755
OK

ext/pgsql/tests/28large_object_import_oid.phpt

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

8383
echo "OK";
8484
?>
85-
--EXPECT--
85+
--EXPECTF--
8686
import LO from int
8787
import LO from string
8888
import LO using default connection
89+
90+
Deprecated: pg_exec(): Automatic fetching of PostgreSQL link is deprecated in %s on line %d
91+
92+
Deprecated: pg_lo_unlink(): Automatic fetching of PostgreSQL link is deprecated in %s on line %d
93+
94+
Deprecated: pg_exec(): Automatic fetching of PostgreSQL link is deprecated in %s on line %d
95+
96+
Deprecated: pg_lo_import(): Automatic fetching of PostgreSQL link is deprecated in %s on line %d
8997
Invalid OID value passed
9098
Invalid OID value passed
99+
100+
Deprecated: pg_lo_import(): Automatic fetching of PostgreSQL link is deprecated in %s on line %d
91101
Invalid OID value passed
92102
Invalid OID value passed
103+
104+
Deprecated: pg_lo_import(): Automatic fetching of PostgreSQL link is deprecated in %s on line %d
93105
OID value must be of type string|int, bool given
94106
OID value must be of type string|int, array given
95107
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
@@ -14,12 +14,12 @@ if (!$dbh) {
1414
die ("Could not connect to the server");
1515
}
1616

17-
@pg_query("DROP SEQUENCE id_id_seq");
18-
@pg_query("DROP TABLE id");
19-
pg_query("CREATE TABLE id (id SERIAL, t INT)");
17+
@pg_query($dbh, "DROP SEQUENCE id_id_seq");
18+
@pg_query($dbh, "DROP TABLE id");
19+
pg_query($dbh, "CREATE TABLE id (id SERIAL, t INT)");
2020

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

2525
class Id

ext/pgsql/tests/80_bug27597.phpt

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

17-
@pg_query("DROP TABLE id");
18-
pg_query("CREATE TABLE id (id INT)");
17+
@pg_query($dbh, "DROP TABLE id");
18+
pg_query($dbh, "CREATE TABLE id (id INT)");
1919

2020
for ($i=0; $i<4; $i++) {
21-
pg_query("INSERT INTO id (id) VALUES ($i)");
21+
pg_query($dbh, "INSERT INTO id (id) VALUES ($i)");
2222
}
2323

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

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

ext/pgsql/tests/80_bug32223.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Bug #32223 (weird behaviour of pg_last_notice)
44
<?php
55
require_once('skipif.inc');
66

7-
_skip_lc_messages();
7+
_skip_lc_messages($conn);
88

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

31-
_set_lc_messages();
31+
_set_lc_messages($dbh);
3232

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

ext/pgsql/tests/80_bug32223b.phpt

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

31-
_set_lc_messages();
31+
_set_lc_messages(dbh);
3232

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

ext/pgsql/tests/80_bug39971.phpt

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

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

1919
$values = array('tm' => 'now()');
2020
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
@@ -14,11 +14,11 @@ if (!$dbh) {
1414
die ("Could not connect to the server");
1515
}
1616

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

1919
pg_insert($dbh, 'php_test', array());
2020

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

2323
pg_query($dbh, "DROP TABLE php_test");
2424
pg_close($dbh);

ext/pgsql/tests/98old_api.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ PostgreSQL old api
88
include('config.inc');
99

1010
$db = pg_connect($conn_str);
11-
$result = pg_exec("SELECT * FROM ".$table_name);
11+
$result = pg_exec($db, "SELECT * FROM ".$table_name);
1212
pg_numrows($result);
1313
pg_numfields($result);
1414
pg_fieldname($result, 0);
@@ -18,11 +18,11 @@ pg_fieldprtlen($result, 0);
1818
pg_fieldisnull($result, 0);
1919

2020
pg_result($result,0,0);
21-
$result = pg_exec("INSERT INTO ".$table_name." VALUES (7777, 'KKK')");
21+
$result = pg_exec($db, "INSERT INTO ".$table_name." VALUES (7777, 'KKK')");
2222
$oid = pg_getlastoid($result);
2323
pg_freeresult($result);
24-
pg_errormessage();
25-
$result = pg_exec("UPDATE ".$table_name." SET str = 'QQQ' WHERE str like 'RGD';");
24+
pg_errormessage($db);
25+
$result = pg_exec($db, "UPDATE ".$table_name." SET str = 'QQQ' WHERE str like 'RGD';");
2626
pg_cmdtuples($result);
2727

2828

ext/pgsql/tests/bug37100_9.phpt

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

1313
$db = pg_connect($conn_str);
1414

15-
@pg_query('DROP TABLE test_bug');
15+
@pg_query($db, 'DROP TABLE test_bug');
1616

17-
pg_query('CREATE TABLE test_bug (binfield byteA) ;');
18-
pg_query("INSERT INTO test_bug VALUES (decode('0103AA000812','hex'))");
17+
pg_query($db, 'CREATE TABLE test_bug (binfield byteA) ;');
18+
pg_query($db, "INSERT INTO test_bug VALUES (decode('0103AA000812','hex'))");
1919

2020

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

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

28-
$data = pg_query($sql);
28+
$data = pg_query($db, $sql);
2929
$res = pg_fetch_result($data,0);
3030

3131
var_dump(strlen($res));
@@ -34,7 +34,7 @@ var_dump(bin2hex($res));
3434
pg_close($db);
3535

3636
$db = pg_connect($conn_str);
37-
pg_query('DROP TABLE test_bug');
37+
pg_query($db, 'DROP TABLE test_bug');
3838
pg_close($db);
3939

4040

ext/pgsql/tests/bug47199.phpt

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

1212
$dbh = pg_connect($conn_str);
1313
$tbl_name = 'test_47199';
14-
@pg_query("DROP TABLE $tbl_name");
15-
pg_query("CREATE TABLE $tbl_name (null_field INT, not_null_field INT NOT NULL)");
14+
@pg_query($dbh, "DROP TABLE $tbl_name");
15+
pg_query($dbh, "CREATE TABLE $tbl_name (null_field INT, not_null_field INT NOT NULL)");
1616

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

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

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

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

2828
echo $query, "\n";
2929

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

32-
@pg_query("DROP TABLE $tbl_name");
32+
@pg_query($dbh, "DROP TABLE $tbl_name");
3333
pg_close($dbh);
3434

3535
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
@@ -10,7 +10,7 @@ include("skipif.inc");
1010
include 'config.inc';
1111

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

1515
try {
1616
var_dump(pg_fetch_array($result, -1));

0 commit comments

Comments
 (0)