Bug #79664 [Opn->Ver]: PDOStatement::getColumnMeta fails on empty result set
| From: | cmb@php.net | Date: | Tue, 02 Jun 2020 07:39:23 +0000 |
| Subject: | Bug #79664 [Opn->Ver]: PDOStatement::getColumnMeta fails on empty result set | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227269@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79664&edit=1
ID: 79664
Updated by: cmb@php.net
Reported by: mic at kwayisi dot org
-Summary: PDOStatement::getColumnMeta should fail predictably
for an empty result set
+Summary: PDOStatement::getColumnMeta fails on empty result
set
-Status: Open
+Status: Verified
Type: Bug
Package: PDO SQLite
Operating System: Windows
PHP Version: 7.4.6
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2020-06-02 00:23:44] mic at kwayisi dot org
Description:
------------
PDOStatement::getColumnMeta throws a "column index out of range" error if the result set
is empty.
After calling PDOStatement::columnCount to confirm that there are columns in the result set,
subsequent call to PDOStatement::getColumnMeta shouldn't produce an error even if its
implementation does not enable it to fetch the requested column (because there are no rows).
Test script:
---------------
$pdo = new PDO('sqlite:', null, null, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);
$stmt = $pdo->query('select 1 where 0');
if ($stmt->columnCount())
var_dump($stmt->getColumnMeta(0));
Expected result:
----------------
array(6) {
["native_type"]=>
string(7) "integer"
["flags"]=>
array(0) {
}
["name"]=>
string(1) "1"
["len"]=>
int(4294967295)
["precision"]=>
int(0)
["pdo_type"]=>
int(2)
}
Actual result:
--------------
ERROR: SQLSTATE[HY000]: General error: 25 column index out of range
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79664&edit=1