From:             pronoia at beibob dot de
Operating system: FreeBSD 6.3
PHP version:      5.2.5
PHP Bug Type:     PDO related
Bug description:  Incorrect argument counter in prepared statements with pgsql

Description:
------------
Executing a prepared statement that includes identical named placeholders
among others breaks postgresql's PREPARE command.

PDO->prepare does not translate the number of unique placeholders in the
statement correctly. Looks like it increments the argument number on the
basis of the placeholder's position index instead using an unique index
(see therefor pgsql log entries in the actual result section).

pdo_pgsql
My postgresql version is 8.2.5

Reproduce code:
---------------
Table Setup
CREATE TABLE nodes
(
   id   integer NOT NULL PRIMARY KEY
 , root integer NOT NULL
 , lft  integer NOT NULL
 , rgt  integer NOT NULL
);

INSERT INTO nodes (id, root, lft, rgt) VALUES (1, 1, 1, 6);
INSERT INTO nodes (id, root, lft, rgt) VALUES (2, 1, 2, 3);
INSERT INTO nodes (id, root, lft, rgt) VALUES (3, 1, 4, 5);

// Assumes that $Dbh is pdo object
// Let pgsql log all statements, so we can see the prepared statement as
it is seen by the postgresql server
$Dbh->query("SET log_statement = 'all'");
$Stmt = $Dbh->prepare('SELECT * FROM nodes WHERE (lft > :left OR rgt >
:left) AND root = :rootId');
$Stmt->bindValue('left',   1, PDO::PARAM_INT);
$Stmt->bindValue('rootId', 1, PDO::PARAM_INT);

if (!$Stmt->execute())
   print_r($Stmt->errorInfo());

// And a second one to get it clearly
$Stmt = $Dbh->prepare('SELECT * FROM nodes WHERE (lft > :left OR rgt >
:left OR rgt > :left) AND root = :rootId');
$Stmt->bindValue('left',   1, PDO::PARAM_INT);
$Stmt->bindValue('rootId', 1, PDO::PARAM_INT);

if (!$Stmt->execute())
   print_r($Stmt->errorInfo());




Expected result:
----------------
no error

In the pgsql log:
STATEMENT: SELECT * FROM nodes WHERE (lft > $1 OR rgt > $1) AND root = $2

STATEMENT: SELECT * FROM nodes WHERE (lft > $1 OR rgt > $1 OR rgt > $1)
AND root = $2

Actual result:
--------------
Array
(
    [0] => 42P18
    [1] => 7
    [2] => ERROR:  could not determine data type of parameter $2
)

Array
(
    [0] => 42P18
    [1] => 7
    [2] => ERROR:  could not determine data type of parameter $2
)

And in the pgsql log:
STATEMENT: SELECT * FROM nodes WHERE (lft > $1 OR rgt > $1) AND root = $3
STATEMENT: SELECT * FROM nodes WHERE (lft > $1 OR rgt > $1 OR rgt > $1)
AND root = $4


-- 
Edit bug report at http://bugs.php.net/?id=43925&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=43925&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=43925&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=43925&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=43925&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=43925&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=43925&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=43925&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=43925&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=43925&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=43925&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=43925&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=43925&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=43925&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=43925&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=43925&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=43925&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=43925&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=43925&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=43925&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=43925&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=43925&r=mysqlcfg

Reply via email to