From de0d2a9d5f4834345f08d62663b60d3d3c0b8b93 Mon Sep 17 00:00:00 2001 From: Antoni Villalonga Date: Tue, 18 Feb 2020 21:28:34 +0100 Subject: [PATCH] Fix sqlite3 fetchArray #64531 --- ext/sqlite3/sqlite3.c | 5 +++++ ...ite3result_fetchArray_nonrows_problem.phpt | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 ext/sqlite3/tests/sqlite3result_fetchArray_nonrows_problem.phpt diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 6ae049a740443..bed385f6fc7e5 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -1810,6 +1810,11 @@ PHP_METHOD(sqlite3result, fetchArray) return; } + 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: diff --git a/ext/sqlite3/tests/sqlite3result_fetchArray_nonrows_problem.phpt b/ext/sqlite3/tests/sqlite3result_fetchArray_nonrows_problem.phpt new file mode 100644 index 0000000000000..823d5f87dd100 --- /dev/null +++ b/ext/sqlite3/tests/sqlite3result_fetchArray_nonrows_problem.phpt @@ -0,0 +1,21 @@ +--TEST-- +SQLite3Result::fetchArray() test, testing non-SQLITE3_ROWS result type +--CREDITS-- +Antoni Villalonga Noceras +--SKIPIF-- + +--FILE-- +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