php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79664 PDOStatement::getColumnMeta fails on empty result set
Submitted: 2020-06-02 00:23 UTC Modified: 2020-06-02 07:39 UTC
From: mic at kwayisi dot org Assigned: cmb (profile)
Status: Closed Package: PDO SQLite
PHP Version: 7.4.6 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mic at kwayisi dot org
New email:
PHP Version: OS:

 

 [2020-06-02 00:23 UTC] 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


Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-06-02 07:39 UTC] cmb@php.net
-Summary: PDOStatement::getColumnMeta should fail predictably for an empty result set +Summary: PDOStatement::getColumnMeta fails on empty result set -Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2020-06-02 07:55 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #79664: PDOStatement::getColumnMeta fails on empty result set
On GitHub:  https://github.com/php/php-src/pull/5654
Patch:      https://github.com/php/php-src/pull/5654.patch
 [2020-06-02 08:48 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=63bd8f38f4b7e8ffbcbd0ea607e21041ebba2455
Log: Fix #79664: PDOStatement::getColumnMeta fails on empty result set
 [2020-06-02 08:48 UTC] cmb@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 09:01:31 2024 UTC