]> granicus.if.org Git - php/commitdiff
Promote pgsql no link to Error exception
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 9 Sep 2020 10:44:28 +0000 (12:44 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 9 Sep 2020 10:45:07 +0000 (12:45 +0200)
ext/pgsql/pgsql.c
ext/pgsql/tests/no_link_open.phpt [new file with mode: 0644]

index b0883769d183171377fd903423c8f6d02f20dbd5..118ecabbf34c52196ff2ca1f66297fedd01a447d 100644 (file)
 #define PGSQL_RETURN_OID(oid) RETURN_LONG((zend_long)oid)
 #endif
 
-#define CHECK_DEFAULT_LINK(x) if ((x) == NULL) { php_error_docref(NULL, E_WARNING, "No PostgreSQL link opened yet"); RETURN_FALSE; }
+#define CHECK_DEFAULT_LINK(x) \
+       if ((x) == NULL) { \
+               zend_throw_error(NULL, "No PostgreSQL link opened yet"); \
+               RETURN_THROWS(); \
+       }
 #define FETCH_DEFAULT_LINK()  PGG(default_link)
 
 #ifndef HAVE_PQFREEMEM
diff --git a/ext/pgsql/tests/no_link_open.phpt b/ext/pgsql/tests/no_link_open.phpt
new file mode 100644 (file)
index 0000000..051ce38
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+Using pg function with default link while no link open
+--FILE--
+<?php
+
+try {
+    pg_dbname();
+} catch (Error $e) {
+    echo $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+No PostgreSQL link opened yet