Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by trwww (Priest)
on May 02, 2013 at 07:59 UTC ( [id://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 ]; ...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-19 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found