php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62593 Emulate prepares behave strangely with PARAM_BOOL
Submitted: 2012-07-18 10:04 UTC Modified: 2012-10-30 14:45 UTC
Votes:10
Avg. Score:4.8 ± 0.4
Reproduced:10 of 10 (100.0%)
Same Version:4 (40.0%)
Same OS:4 (40.0%)
From: mascione at sviluppo dot toscana dot it Assigned: willfitch (profile)
Status: Closed Package: PDO related
PHP Version: 5.3.14 OS: Ubuntu 10.04
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mascione at sviluppo dot toscana dot it
New email:
PHP Version: OS:

 

 [2012-07-18 10:04 UTC] mascione at sviluppo dot toscana dot it
Description:
------------
On postgresql when I use ATTR_EMULATE_PREPARES binding params or values with PARAM_BOOL behave strangely.

Disabling ATTR_EMULATE_PREPARES resolve the problem.

(driver specific PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT generates same problem)

(Related to bug #38386 ?)

Test script:
---------------
$db = new PDO('pgsql:dbname=testdb;user=postgres');
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
//$db->setAttribute(PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT, true);
//CREATE TABLE t(a boolean, b boolean)
$stmt = $db->prepare("INSERT INTO t(a,b) VALUES (true,false)");
$stmt->execute();
print_r($stmt->errorInfo());
$stmt = $db->prepare("INSERT INTO t(a,b) VALUES (:test,:test)");
$stmt->bindValue('test', false, PDO::PARAM_BOOL);
$stmt->execute();
print_r($stmt->errorInfo());
$stmt = $db->prepare("SELECT * FROM t WHERE :test");
$stmt->bindValue('test', true, PDO::PARAM_BOOL);
$stmt->execute();
print_r($stmt->errorInfo());
print_r($stmt->fetchAll());


Expected result:
----------------
Works without errors.

Actual result:
--------------
Array
(
    [0] => 00000
    [1] => 
    [2] => 
)
Array
(
    [0] => 42804
    [1] => 7
    [2] => ERROR:  column "a" is of type boolean but expression is of type integer
LINE 1: INSERT INTO t(a,b) VALUES (0,'0')
                                   ^
HINT:  You will need to rewrite or cast the expression.
)
Array
(
    [0] => 42804
    [1] => 7
    [2] => ERROR:  argument of WHERE must be type boolean, not type integer
LINE 1: SELECT * FROM t WHERE 1
                              ^
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-19 06:15 UTC] ploginoff at gmail dot com
Yes! _Yesterday_ I have * with the same bug. Solution: install 5.3.13 or disable emulate prepares (but it is sometimes necessary).
 [2012-09-17 16:13 UTC] willfitch@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: willfitch
 [2012-09-17 16:17 UTC] willfitch@php.net
I have confirmed this.  The issue with disabling emulation prepares for this 
purpose is that it sends the query through PQprepare, then PQexec.  If you're 
using middleware such as pgbouncer, this won't work.
 [2012-09-17 19:19 UTC] willfitch@php.net
-Status: Assigned +Status: Verified
 [2012-09-18 10:04 UTC] v dot picture at free dot fr
Same problem with the stock version on Ubuntu 12.04: PHP 5.3.10-1ubuntu3.4 
(built: Sep 12 2012)
I hope this problem will be solved soon.
 [2012-09-20 16:36 UTC] willfitch@php.net
Pull request for this fix:

https://github.com/php/php-src/pull/198
 [2012-10-10 21:30 UTC] willfitch@php.net
This was accepted and is awaiting merge.
 [2012-10-17 07:50 UTC] franck dot borel at ub dot uni-freiburg dot de
I am running the test script on SLES11 SP2 with PHP 5.2.14 and I have the same error described here!
 [2012-10-30 14:45 UTC] dsp@php.net
-Status: Verified +Status: Closed
 [2012-10-30 14:45 UTC] dsp@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC