Skip to content

Commit 8f415d4

Browse files
committed
Promote pgsql no link to Error exception
1 parent 3ab8883 commit 8f415d4

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

ext/pgsql/pgsql.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@
7474
#define PGSQL_RETURN_OID(oid) RETURN_LONG((zend_long)oid)
7575
#endif
7676

77-
#define CHECK_DEFAULT_LINK(x) if ((x) == NULL) { php_error_docref(NULL, E_WARNING, "No PostgreSQL link opened yet"); RETURN_FALSE; }
77+
#define CHECK_DEFAULT_LINK(x) \
78+
if ((x) == NULL) { \
79+
zend_throw_error(NULL, "No PostgreSQL link opened yet"); \
80+
RETURN_THROWS(); \
81+
}
7882
#define FETCH_DEFAULT_LINK() PGG(default_link)
7983

8084
#ifndef HAVE_PQFREEMEM

ext/pgsql/tests/no_link_open.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Using pg function with default link while no link open
3+
--FILE--
4+
<?php
5+
6+
try {
7+
pg_dbname();
8+
} catch (Error $e) {
9+
echo $e->getMessage(), "\n";
10+
}
11+
12+
?>
13+
--EXPECT--
14+
No PostgreSQL link opened yet

0 commit comments

Comments
 (0)