grump- has asked for the wisdom of the Perl Monks concerning the following question:
I hate to just accept that 'if it works, use it' because I might end up down the road in trouble having used poor practice. If someone has done this successfully for some time I would like to know. Even if it does work, is it good practice? I had the thought that if I could test multiple overlapping placeholders successfully (e.g. change query and args to:#!/usr/bin/perl use DBI; use Data::Dumper; my $dbh = DBI->connect( dsn, user, pass, { RaiseError => 1 } ); my $query = qq{ select * from blah_table where col1 = :p0 union select * from blah_table where col1 = :p0 union select * from blah_table where col1 = :p0 }; my $dbhq = $dbh->prepare( $query ); my @args = ('foo_param'); while( $query =~ /(:p(\d+))/g ) { #$1 will be :p0, $2 will be 0 $dbhq->bind_param($1, @args[$2]); #':p0 gets @args[0] } $dbhq->execute(); print Dumper($dbhq->fetchall_arrayref());
) that might prove to me that it is o.k. to use but even so, some input from experts would be nice. Any input would be welcome. Thanks!... my $query = qq{ select * from blah_table where col1 = :p0 union select * from blah_table where col1 = :p0 union select * from blah_table where col1 = :p1 union select * from blah_table where col1 = :p0 union select * from blah_table where col1 = :p1 }; ... my @args = ('foo_param0', 'foo_param1'); ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI indexable placeholder
by runrig (Abbot) on Jan 04, 2013 at 17:52 UTC | |
|
Re: DBI indexable placeholder
by mje (Curate) on Jan 08, 2013 at 10:19 UTC | |
|
Re: DBI indexable placeholder
by locked_user sundialsvc4 (Abbot) on Jan 07, 2013 at 22:49 UTC |