Skip to content

Fix sqlite3 fetchArray #64531 #5137

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 2 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
5 changes: 5 additions & 0 deletions ext/sqlite3/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,11 @@ PHP_METHOD(SQLite3Result, fetchArray)

SQLITE3_CHECK_INITIALIZED(result_obj->db_obj, result_obj->stmt_obj->initialised, SQLite3Result)

if (sqlite3_column_count(result_obj->stmt_obj->stmt) == 0) {
result_obj->complete = 1;
RETURN_FALSE;
}

ret = sqlite3_step(result_obj->stmt_obj->stmt);
switch (ret) {
case SQLITE_ROW:
Expand Down
21 changes: 21 additions & 0 deletions ext/sqlite3/tests/sqlite3result_fetchArray_nonrows_problem.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
SQLite3Result::fetchArray() test, testing non-SQLITE3_ROWS result type
--CREDITS--
Antoni Villalonga Noceras <[email protected]>
--SKIPIF--
<?php require_once(__DIR__ . '/skipif.inc'); ?>
--FILE--
<?php
$db = new SQLite3(':memory:');
$db->exec('CREATE TABLE foo (bar STRING)');

$result = $db->query("INSERT INTO foo (bar) VALUES ('This is a test')");

//fetchArray should not call sqlite3_step() after an Insert, Update, etc
$result->fetchArray(SQLITE3_ASSOC);

$result = $db->query("SELECT COUNT(*) FROM foo");
echo $result->fetchArray(SQLITE3_NUM)[0];
?>
--EXPECTF--
1