Bug #79664 [NEW]: PDOStatement::getColumnMeta should fail predictably for an empty result set
| From: | mic at kwayisi dot org | Date: | Tue, 02 Jun 2020 00:23:44 +0000 |
| Subject: | Bug #79664 [NEW]: PDOStatement::getColumnMeta should fail predictably for an empty result set | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-227268@lists.php.net to get a copy of this message | ||
From: mic at kwayisi dot org
Operating system: Windows
PHP version: 7.4.6
Package: PDO SQLite
Bug Type: Bug
Bug description:PDOStatement::getColumnMeta should fail predictably for an empty result set
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 bug report at https://bugs.php.net/bug.php?id=79664&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79664&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79664&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79664&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79664&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79664&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79664&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79664&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79664&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79664&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79664&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79664&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79664&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79664&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79664&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79664&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79664&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79664&r=mysqlcfg