summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Peter Banyard <girgias@php.net>2020-09-11 18:10:38 +0200
committerGeorge Peter Banyard <girgias@php.net>2020-09-12 22:37:04 +0200
commit67d21bf237e45457336a545cef01c552e9a5a1f4 (patch)
treee0c5752c644b59bc3c562f8d4ddd66a50b7f36a5
parent1f118aa24c5f2807ec16e140e000555f92d48e93 (diff)
downloadphp-git-67d21bf237e45457336a545cef01c552e9a5a1f4.tar.gz
Use Error for uninitialized SQLite object
Closes GH-6113
-rw-r--r--ext/sqlite3/sqlite3.c8
-rw-r--r--ext/sqlite3/tests/bug66550.phpt10
-rw-r--r--ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt10
3 files changed, 17 insertions, 11 deletions
diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c
index b06f723b4c..464df5ae21 100644
--- a/ext/sqlite3/sqlite3.c
+++ b/ext/sqlite3/sqlite3.c
@@ -63,14 +63,14 @@ static void php_sqlite3_error(php_sqlite3_db_object *db_obj, char *format, ...)
#define SQLITE3_CHECK_INITIALIZED(db_obj, member, class_name) \
if (!(db_obj) || !(member)) { \
- php_sqlite3_error(db_obj, "The " #class_name " object has not been correctly initialised"); \
- RETURN_FALSE; \
+ zend_throw_error(NULL, "The " #class_name " object has not been correctly initialised or is already closed"); \
+ RETURN_THROWS(); \
}
#define SQLITE3_CHECK_INITIALIZED_STMT(member, class_name) \
if (!(member)) { \
- php_error_docref(NULL, E_WARNING, "The " #class_name " object has not been correctly initialised"); \
- RETURN_FALSE; \
+ zend_throw_error(NULL, "The " #class_name " object has not been correctly initialised or is already closed"); \
+ RETURN_THROWS(); \
}
/* {{{ PHP_INI */
diff --git a/ext/sqlite3/tests/bug66550.phpt b/ext/sqlite3/tests/bug66550.phpt
index de7aae1493..244f358a5f 100644
--- a/ext/sqlite3/tests/bug66550.phpt
+++ b/ext/sqlite3/tests/bug66550.phpt
@@ -15,7 +15,11 @@ $stmt = $db->prepare('SELECT bar FROM foo WHERE id=:id');
// Close the database connection and free the internal sqlite3_stmt object
$db->close();
// Access the sqlite3_stmt object via the php_sqlite3_stmt container
-$stmt->reset();
+try {
+ $stmt->reset();
+} catch (\Error $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
?>
---EXPECTF--
-Warning: SQLite3Stmt::reset(): The SQLite3 object has not been correctly initialised in %s
+--EXPECT--
+The SQLite3 object has not been correctly initialised or is already closed
diff --git a/ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt b/ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt
index e3e67f1ff4..34af57128a 100644
--- a/ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt
+++ b/ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt
@@ -27,7 +27,11 @@ while ($result = $results->fetchArray(SQLITE3_NUM))
echo "Closing database\n";
var_dump($db->close());
echo "Check db was closed\n";
-var_dump($results->numColumns());
+try {
+ var_dump($results->numColumns());
+} catch (\Error $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
echo "Done\n";
?>
--EXPECTF--
@@ -46,7 +50,5 @@ array(2) {
Closing database
bool(true)
Check db was closed
-
-Warning: SQLite3Result::numColumns(): The SQLite3Result object has not been correctly initialised in %s on line %d
-bool(false)
+The SQLite3Result object has not been correctly initialised or is already closed
Done