User1 User1 - 4 months ago 7x
Perl Question

Reusing ?'s on a DBI prepare

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(?)");

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)");

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


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.