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

0 commit comments

Comments
 (0)