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

0 commit comments

Comments
 (0)