Skip to content

Sqlite3 uninitialized object as error #6113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ext/sqlite3/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
10 changes: 7 additions & 3 deletions ext/sqlite3/tests/bug66550.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 6 additions & 4 deletions ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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--
Expand All @@ -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
3 changes: 3 additions & 0 deletions ext/sqlite3/tests/sqlite3_15_open_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ if(substr(PHP_OS, 0, 3) == 'WIN' ) {
die('skip non windows test');
}
require_once(__DIR__ . '/skipif.inc');
if (!function_exists('posix_geteui')) {
die('SKIP posix_geteuid() not defined so cannot check if run as root');
}
if (posix_geteuid() == 0) {
die('SKIP Cannot run test as root.');
}
Expand Down