Edit report at https://bugs.php.net/bug.php?id=62593&edit=1

 ID:                 62593
 Comment by:         willfi...@php.net
 Reported by:        mascione at sviluppo dot toscana dot it
 Summary:            Emulate prepares behave strangely with PARAM_BOOL
 Status:             Assigned
 Type:               Bug
 Package:            PDO related
 Operating System:   Ubuntu 10.04
 PHP Version:        5.3.14
 Assigned To:        willfitch
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2012-07-19 06:15:02] 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-07-18 10:04:51] 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
                              ^
)


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=62593&edit=1

Reply via email to