Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Using multiple values in a SQL "in" statement

by trwww (Priest)
on May 02, 2013 at 07:59 UTC ( #1031706=note: print w/ replies, xml ) Need Help??


in reply to Using multiple values in a SQL "in" statement

Use SQL::Abstract to write extendable code that builds SQL. This is the tool DBIx::Class uses, so it gets lots of support:

$ cat 1031647.pl use warnings; use strict; use Data::Dumper; use SQL::Abstract; my $sql = SQL::Abstract->new; my($stmt, @bind) = $sql->select( 'table', # table name [ 'name' ], # fields { id => { -in => [ 1, 2, 3, 4 ] } # the ids }, [ 'id' ] # order by ); print Data::Dumper->Dump( [ $stmt, \@bind ], [ qw( stmt bind ) ], ); my $sth = $dbh->prepare( $stmt ); $sth->execute( @bind ); $ perl 1031647.pl $stmt = 'SELECT name FROM table WHERE ( id IN ( ?, ?, ?, ? ) ) ORDER B +Y id'; $bind = [ 1, 2, 3, 4 ]; ...


Comment on Re: Using multiple values in a SQL "in" statement
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1031706]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (15)
As of 2014-07-30 12:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (231 votes), past polls