Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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 rifling through the Monastery: (7)
As of 2015-07-29 05:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls