Skip to content

ext/sqlite3: SQLite3::close, SQLite3Stmt::close and SQLite3Result::fi… #10878

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ PHP 8.3 UPGRADE NOTES
argument is non empty with the class not having constructor.
. pg_insert now raises a ValueError instead of a WARNING when the table specified is invalid.

- Sqlite:
. SQLite3::close, SQLite3Result::finalize and SQLite3Stmt::close are void.
Previously, they always returned true.

- Standard:
. E_NOTICEs emitted by unserialized() have been promoted to E_WARNING.
RFC: https://wiki.php.net/rfc/improve_unserialize_error_handling
Expand Down
6 changes: 0 additions & 6 deletions ext/sqlite3/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ PHP_METHOD(SQLite3, close)
}
db_obj->initialised = 0;
}

RETURN_TRUE;
}
/* }}} */

Expand Down Expand Up @@ -1418,8 +1416,6 @@ PHP_METHOD(SQLite3Stmt, close)
if(stmt_obj->db_obj) {
zend_llist_del_element(&(stmt_obj->db_obj->free_list), object, (int (*)(void *, void *)) php_sqlite3_compare_stmt_zval_free);
}

RETURN_TRUE;
}
/* }}} */

Expand Down Expand Up @@ -2052,8 +2048,6 @@ PHP_METHOD(SQLite3Result, finalize)
} else {
sqlite3_reset(result_obj->stmt_obj->stmt);
}

RETURN_TRUE;
}
/* }}} */

Expand Down
10 changes: 5 additions & 5 deletions ext/sqlite3/sqlite3.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ public function __construct(string $filename, int $flags = SQLITE3_OPEN_READWRIT
/** @tentative-return-type */
public function open(string $filename, int $flags = SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, string $encryptionKey = ""): void {}

/** @return bool */
public function close() {} // TODO make return type void
/** @tentative-return-type */
public function close(): void {}

/** @tentative-return-type */
public static function version(): array {}
Expand Down Expand Up @@ -397,7 +397,7 @@ public function bindValue(string|int $param, mixed $value, int $type = SQLITE3_T
public function clear(): bool {}

/** @tentative-return-type */
public function close(): bool {}
public function close(): void {}

/** @tentative-return-type */
public function execute(): SQLite3Result|false {}
Expand Down Expand Up @@ -435,6 +435,6 @@ public function fetchArray(int $mode = SQLITE3_BOTH): array|false {}
/** @tentative-return-type */
public function reset(): bool {}

/** @return bool */
public function finalize() {} // TODO make return type void
/** @tentative-return-type */
public function finalize(): void {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

}
9 changes: 5 additions & 4 deletions ext/sqlite3/sqlite3_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions ext/sqlite3/tests/bug47159.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ require_once(__DIR__ . '/new_db.inc');

$stmt = $db->prepare("SELECT 1");

var_dump($stmt->close());
$stmt->close();

var_dump($db->close());
$db->close();

print "done";

?>
--EXPECT--
bool(true)
bool(true)
done
3 changes: 1 addition & 2 deletions ext/sqlite3/tests/bug69972.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $db = new SQLite3(':memory:');
echo "SELECTING from invalid table\n";
$result = $db->query("SELECT * FROM non_existent_table");
echo "Closing database\n";
var_dump($db->close());
$db->close();
echo "Done\n";

// Trigger the use-after-free
Expand All @@ -20,7 +20,6 @@ SELECTING from invalid table

Warning: SQLite3::query(): Unable to prepare statement: 1, no such table: non_existent_table in %sbug69972.php on line %d
Closing database
bool(true)
Done
Error Code: 0
Error Msg:
3 changes: 1 addition & 2 deletions ext/sqlite3/tests/sqlite3_01_open-mb.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ $db = new SQLite3($db_file);
//require_once(__DIR__ . '/new_db.inc');

var_dump($db);
var_dump($db->close());
$db->close();

unlink($db_file);
echo "Done\n";
?>
--EXPECTF--
object(SQLite3)#%d (0) {
}
bool(true)
Done
3 changes: 1 addition & 2 deletions ext/sqlite3/tests/sqlite3_01_open.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ sqlite3
require_once(__DIR__ . '/new_db.inc');

var_dump($db);
var_dump($db->close());
$db->close();
echo "Done\n";
?>
--EXPECTF--
object(SQLite3)#%d (0) {
}
bool(true)
Done
3 changes: 1 addition & 2 deletions ext/sqlite3/tests/sqlite3_02_create.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ echo "Dropping database\n";
var_dump($db->exec('DROP TABLE test'));

echo "Closing database\n";
var_dump($db->close());
$db->close();
echo "Done\n";
?>
--EXPECTF--
Expand All @@ -30,5 +30,4 @@ bool(false)
Dropping database
bool(true)
Closing database
bool(true)
Done
3 changes: 1 addition & 2 deletions ext/sqlite3/tests/sqlite3_03_insert.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ while ($result = $results->fetchArray(SQLITE3_NUM))
$results->finalize();

echo "Closing database\n";
var_dump($db->close());
$db->close();
echo "Done\n";
?>
--EXPECTF--
Expand All @@ -47,5 +47,4 @@ array(2) {
string(1) "b"
}
Closing database
bool(true)
Done
3 changes: 1 addition & 2 deletions ext/sqlite3/tests/sqlite3_04_update.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ while ($result = $results->fetchArray(SQLITE3_NUM))
$results->finalize();

echo "Closing database\n";
var_dump($db->close());
$db->close();
echo "Done\n";
?>
--EXPECTF--
Expand Down Expand Up @@ -73,5 +73,4 @@ array(2) {
string(1) "c"
}
Closing database
bool(true)
Done
3 changes: 1 addition & 2 deletions ext/sqlite3/tests/sqlite3_05_delete.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ while ($result = $results->fetchArray(SQLITE3_NUM))
$results->finalize();

echo "Closing database\n";
var_dump($db->close());
$db->close();
echo "Done\n";
?>
--EXPECTF--
Expand Down Expand Up @@ -67,5 +67,4 @@ array(2) {
string(1) "b"
}
Closing database
bool(true)
Done
3 changes: 1 addition & 2 deletions ext/sqlite3/tests/sqlite3_06_prepared_stmt.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ while ($result = $results->fetchArray(SQLITE3_NUM))
$results->finalize();

echo "Closing database\n";
var_dump($db->close());
$db->close();
echo "Done\n";
?>
--EXPECTF--
Expand All @@ -48,5 +48,4 @@ array(2) {
string(1) "a"
}
Closing database
bool(true)
Done
3 changes: 1 addition & 2 deletions ext/sqlite3/tests/sqlite3_07_prepared_stmt.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ while ($result = $results->fetchArray(SQLITE3_NUM))
$results->finalize();

echo "Closing database\n";
var_dump($db->close());
$db->close();
echo "Done\n";
?>
--EXPECTF--
Expand All @@ -47,5 +47,4 @@ array(2) {
string(1) "a"
}
Closing database
bool(true)
Done
3 changes: 1 addition & 2 deletions ext/sqlite3/tests/sqlite3_08_udf.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ while ($result = $results->fetchArray(SQLITE3_NUM))
$results->finalize();

echo "Closing database\n";
var_dump($db->close());
$db->close();
echo "Done\n";
?>
--EXPECT--
Expand All @@ -53,5 +53,4 @@ array(1) {
string(32) "92eb5ffee6ae2fec3ad71c777531578f"
}
Closing database
bool(true)
Done
6 changes: 2 additions & 4 deletions ext/sqlite3/tests/sqlite3_09_blob_bound_param.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var_dump($insert_stmt->bindValue(1, 'a', SQLITE3_TEXT));
var_dump($insert_stmt->bindParam(2, $foo, SQLITE3_BLOB));
$insert_stmt->execute();
echo "Closing statement\n";
var_dump($insert_stmt->close());
$insert_stmt->close();

echo "SELECTING results\n";
$results = $db->query("SELECT id, quote(data) AS data FROM test ORDER BY id ASC");
Expand All @@ -35,7 +35,7 @@ while ($result = $results->fetchArray(SQLITE3_NUM))
$results->finalize();

echo "Closing database\n";
var_dump($db->close());
$db->close();
echo "Done\n";
?>
--EXPECTF--
Expand All @@ -48,7 +48,6 @@ BINDING Parameter
bool(true)
bool(true)
Closing statement
bool(true)
SELECTING results
array(2) {
[0]=>
Expand All @@ -57,5 +56,4 @@ array(2) {
string(23) "X'61626364656667006869'"
}
Closing database
bool(true)
Done
3 changes: 1 addition & 2 deletions ext/sqlite3/tests/sqlite3_10_bound_value_name.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ while ($result = $results->fetchArray(SQLITE3_NUM))
$results->finalize();

echo "Closing database\n";
var_dump($db->close());
$db->close();
echo "Done\n";
?>
--EXPECTF--
Expand All @@ -51,5 +51,4 @@ array(2) {
string(1) "a"
}
Closing database
bool(true)
Done
3 changes: 1 addition & 2 deletions ext/sqlite3/tests/sqlite3_11_numrows.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var_dump($results->numRows());
$results->finalize();

echo "Closing database\n";
var_dump($db->close());
$db->close();
echo "Done\n";
?>
--EXPECT--
Expand All @@ -44,5 +44,4 @@ SELECTING results
Number of rows
int(2)
Closing database
bool(true)
Done
3 changes: 1 addition & 2 deletions ext/sqlite3/tests/sqlite3_12_unfinalized_stmt_cleanup.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ while ($result = $results->fetchArray(SQLITE3_NUM))
}

echo "Closing database\n";
var_dump($db->close());
$db->close();
echo "Check db was closed\n";
try {
var_dump($results->numColumns());
Expand All @@ -48,7 +48,6 @@ array(2) {
string(1) "a"
}
Closing database
bool(true)
Check db was closed
The SQLite3Result object has not been correctly initialised or is already closed
Done
3 changes: 1 addition & 2 deletions ext/sqlite3/tests/sqlite3_16_select_no_results.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ while ($result = $results->fetchArray(SQLITE3_NUM))
$results->finalize();

echo "Closing database\n";
var_dump($db->close());
$db->close();
echo "Done\n";
?>
--EXPECT--
Creating Table
bool(true)
SELECTING results
Closing database
bool(true)
Done
3 changes: 1 addition & 2 deletions ext/sqlite3/tests/sqlite3_18_changes.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ echo "Rows Updated\n";
var_dump($db->changes());

echo "Closing database\n";
var_dump($db->close());
$db->close();
echo "Done\n";
?>
--EXPECT--
Expand All @@ -36,5 +36,4 @@ bool(true)
Rows Updated
int(2)
Closing database
bool(true)
Done
3 changes: 1 addition & 2 deletions ext/sqlite3/tests/sqlite3_19_columninfo.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ while ($row = $result->fetchArray(SQLITE3_NUM)) {
$result->finalize();

echo "Closing database\n";
var_dump($db->close());
$db->close();
echo "Done\n";
?>
--EXPECT--
Expand All @@ -41,5 +41,4 @@ Name: id - Type: 3
Name: time - Type: 1
Name: id - Type: 3
Closing database
bool(true)
Done
Loading