Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reusing ?'s on a DBI prepare

Tags:

perl

dbi

Is there a way to reuse the ?'s used on a DBI prepare statement. Consider the following code:


$sth=$dbh->prepare("INSERT INTO mytable(a,b,c) SELECT ?,B(?),C(?)");
$sth->execute($a,$a,$a);

It would be very nice to instead use something like this:


#I'm making this up as something I hope exists
$sth=$dbh->prepare("INSERT INTO mytable(a,b,c) SELECT ?,B(?:1),C(?:1)");
$sth->execute($a);

Notice that only one $a is passed to the execute instead of three. Is there a way to do this in real life?

like image 481
User1 Avatar asked Jul 05 '10 16:07

User1


1 Answers

It depends on your DBD. For example, using DBD::Pg with the $1 style of placeholders, or DBD::Oracle with named placeholders and bind_param, you can do exactly what you like. But using the general purpose ? style of placeholders that works DBI-wide, it's not possible.

like image 110
hobbs Avatar answered Oct 14 '22 14:10

hobbs