The documentation contains a few examples of dollar-style placeholders in queries, but those queries are enclosed in double quotes, so the placeholders would be interpolated if actually used in this context.

Attached is a patch (against 2.0.0-RC) replacing the double quotes by single quotes where interpolation of $1,$2... would mess up the query text.

--
Daniel
PostgreSQL-powered mail user agent and storage: http://www.manitou-mail.org
*** Pg.pm.orig  Thu Jan 17 15:03:15 2008
--- Pg.pm       Thu Jan 17 15:06:19 2008
***************
*** 2277,2295 ****
  
  Not legal:
  
!   $SQL = "SELECT count(*) FROM pg_class WHERE relpages > $2";
  
!   $SQL = "SELECT count(*) FROM pg_class WHERE relpages BETWEEN $1 AND $3";
  
  Legal:
  
!   $SQL = "SELECT count(*) FROM pg_class WHERE relpages > $1";
  
!   $SQL = "SELECT count(*) FROM pg_class WHERE relpages BETWEEN $1 AND $2";
  
!   $SQL = "SELECT count(*) FROM pg_class WHERE relpages BETWEEN $1 AND $2 AND 
reltuples > $1";
  
!   $SQL = "SELECT count(*) FROM pg_class WHERE relpages > $1 AND reltuples > 
$1";
  
  In the final statement above, DBI thinks there is only one placeholder, so 
this
  statement will replace both placeholders:
--- 2277,2295 ----
  
  Not legal:
  
!   $SQL = 'SELECT count(*) FROM pg_class WHERE relpages > $2';
  
!   $SQL = 'SELECT count(*) FROM pg_class WHERE relpages BETWEEN $1 AND $3';
  
  Legal:
  
!   $SQL = 'SELECT count(*) FROM pg_class WHERE relpages > $1';
  
!   $SQL = 'SELECT count(*) FROM pg_class WHERE relpages BETWEEN $1 AND $2';
  
!   $SQL = 'SELECT count(*) FROM pg_class WHERE relpages BETWEEN $1 AND $2 AND 
reltuples > $1';
  
!   $SQL = 'SELECT count(*) FROM pg_class WHERE relpages > $1 AND reltuples > 
$1';
  
  In the final statement above, DBI thinks there is only one placeholder, so 
this
  statement will replace both placeholders:
***************
*** 2913,2922 ****
  
    ## Set the second placeholder's value and data type.
    ## We don't send a third argument, so the default "varchar" is used
!   $sth->bind_param("$2", "Zool");
  
    ## We realize that the wrong data type was set above, so we change it:
!   $sth->bind_param("$1", 234, { pg_type => SQL_INTEGER });
  
    ## We also got the wrong value, so we change that as well.
    ## Because the data type is sticky, we don't need to change it
--- 2913,2922 ----
  
    ## Set the second placeholder's value and data type.
    ## We don't send a third argument, so the default "varchar" is used
!   $sth->bind_param('$2', "Zool");
  
    ## We realize that the wrong data type was set above, so we change it:
!   $sth->bind_param('$1', 234, { pg_type => SQL_INTEGER });
  
    ## We also got the wrong value, so we change that as well.
    ## Because the data type is sticky, we don't need to change it

Reply via email to