On Fri, Jun 13, 2003 at 12:56:23PM -0600, Ian Harisay wrote:
> Hi,
> 
> Here is a code snippet that will accomplish your desired task.

Thanks.

> This is not meant to be generic.  It does have some limitations.

Specifically that *any* question mark characters in the sql statement
(in comments or interpolated literal strings etc) will be treated
as placeholders.

Tim.

> sub interpolate {
>  my $dbh = shift;
>  my $sql = shift;
> 
>  foreach (@_){
>    my $val = $dbh->quote($_);
>    print "replacing \? for $val$/";
>    $sql =~ s/\?/$val/;
>  }
>  return $sql;
> }


> output produced:
> 
> replacing ? for '500'
> replacing ? for '500'
> replacing ? for '12-Jul-2003'
>  SELECT
>    foo,
>    bar
>  FROM
>    some_table
>  WHERE
>    name='500',
>    AND value='500',
>    AND date='12-Jul-2003'
> 
> 
> 

Reply via email to