Skip to content

Commit de0d2a9

Browse files
committed
Fix sqlite3 fetchArray #64531
1 parent 31dd455 commit de0d2a9

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

ext/sqlite3/sqlite3.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,6 +1810,11 @@ PHP_METHOD(sqlite3result, fetchArray)
18101810
return;
18111811
}
18121812

1813+
if (sqlite3_column_count(result_obj->stmt_obj->stmt) == 0) {
1814+
result_obj->complete = 1;
1815+
RETURN_FALSE;
1816+
}
1817+
18131818
ret = sqlite3_step(result_obj->stmt_obj->stmt);
18141819
switch (ret) {
18151820
case SQLITE_ROW:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
SQLite3Result::fetchArray() test, testing non-SQLITE3_ROWS result type
3+
--CREDITS--
4+
Antoni Villalonga Noceras <antoni@friki.cat>
5+
--SKIPIF--
6+
<?php require_once(__DIR__ . '/skipif.inc'); ?>
7+
--FILE--
8+
<?php
9+
$db = new SQLite3(':memory:');
10+
$db->exec('CREATE TABLE foo (bar STRING)');
11+
12+
$result = $db->query("INSERT INTO foo (bar) VALUES ('This is a test')");
13+
14+
//fetchArray should not call sqlite3_step() after an Insert, Update, etc
15+
$result->fetchArray(SQLITE3_ASSOC);
16+
17+
$result = $db->query("SELECT COUNT(*) FROM foo");
18+
echo $result->fetchArray(SQLITE3_NUM)[0];
19+
?>
20+
--EXPECTF--
21+
1

0 commit comments

Comments
 (0)