Skip to content

Commit 63bd8f3

Browse files
committed
Fix #79664: PDOStatement::getColumnMeta fails on empty result set
As its name suggests, `sqlite3_data_count` returns the number of columns in the current row of the result set; we are interested in the number of columns regardless of the current row, so we have to use `sqlite3_column_count` instead.
1 parent 923c45b commit 63bd8f3

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ PHP NEWS
55
- Core:
66
. Fixed bug #79650 (php-win.exe 100% cpu lockup). (cmb)
77

8+
- PDO SQLite:
9+
. Fixed bug #79664 (PDOStatement::getColumnMeta fails on empty result set).
10+
(cmb)
11+
812
?? ??? ????, PHP 7.3.19
913

1014
- Core:

ext/pdo_sqlite/sqlite_statement.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ static int pdo_sqlite_stmt_col_meta(pdo_stmt_t *stmt, zend_long colno, zval *ret
337337
if (!S->stmt) {
338338
return FAILURE;
339339
}
340-
if(colno >= sqlite3_data_count(S->stmt)) {
340+
if(colno >= sqlite3_column_count(S->stmt)) {
341341
/* error invalid column */
342342
pdo_sqlite_error_stmt(stmt);
343343
return FAILURE;

ext/pdo_sqlite/tests/bug79664.phpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
Bug #79664 (PDOStatement::getColumnMeta fails on empty result set)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo_sqlite')) print 'skip not loaded';
6+
?>
7+
--FILE--
8+
<?php
9+
$pdo = new PDO('sqlite::memory:', null, null, [
10+
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
11+
]);
12+
$stmt = $pdo->query('select 1 where 0');
13+
if ($stmt->columnCount()) {
14+
var_dump($stmt->getColumnMeta(0));
15+
}
16+
?>
17+
--EXPECT--
18+
array(6) {
19+
["native_type"]=>
20+
string(4) "null"
21+
["flags"]=>
22+
array(0) {
23+
}
24+
["name"]=>
25+
string(1) "1"
26+
["len"]=>
27+
int(4294967295)
28+
["precision"]=>
29+
int(0)
30+
["pdo_type"]=>
31+
int(2)
32+
}

0 commit comments

Comments
 (0)