|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81343 pdo_pgsql: Inconsitent boolean conversion after calling closeCursor()
Submitted: 2021-08-10 12:09 UTC Modified: -
From: phofstetter at sensational dot ch Assigned:
Status: Closed Package: PDO PgSQL
PHP Version: 8.1.0beta2 OS: macOS
Private report: No CVE-ID: None
 [2021-08-10 12:09 UTC] phofstetter at sensational dot ch
After calling closeCursor() on a Postgres PDO statement handle, the conversion behavior for boolean values will change:

prior to calling closeCursor, boolean values in the database get converted to PHP boolean values.

after calling closeCursor() (and subsequently calling execute() again), boolean values will be converted to strings 't' and 'f'

This was fine in PHP 8.0, broken in PHP 8.1b2 at least, though I'll update this bug with after some bisecting to find the specific commit.

Test script:
$pdo = new PDO('pgsql:host=localhost;port=5432;user=someuser;dbname=somedb');
$sth = $pdo->prepare("select false where 2=?");

for ($i = 0; $i < 2; $i++) {

Expected result:

Actual result:
string(1) "f"


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-08-10 13:03 UTC] phofstetter at sensational dot ch
According to git bisect, commit caa710037e663fd78f67533b29611183090068b2 is where this broke.

> Rewrite PDO result binding

commit subject checks out :p
 [2021-08-10 13:32 UTC] phofstetter at sensational dot ch
The following pull request has been associated:

Patch Name: fix bug 81343: inconsistent type conversion after closeCursor
On GitHub:
 [2021-08-10 13:34 UTC] phofstetter at sensational dot ch
I have attached a PR that fixes the problem, though I would love to get a review by Nikita who did the big PDO result refactoring. 

I'm not entirely sure it's safe to not free S->cols, but reading the code, I believe cols is freed in the statement destructor anyways.

The other approach would be to restore the freeing of the column metadata and call `describe` again on subsequent execs
 [2021-08-11 16:24 UTC]
Automatic comment on behalf of pilif (author) and nikic (committer)
Log: Fix bug #81343: inconsistent type conversion after closeCursor
 [2021-08-11 16:24 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 20 00:01:28 2024 UTC