The generated SQL and array of values looks like (I added some lay-out and delimiters for clarity):use strict; use SQL::Abstract; my @all_names = qw/one two three/; my @email = qw/first_email second_email third_email/; my @local = qw/here there and_everywhere/; my @year = qw/1970 1980 1990/; my @order = qw/location name/; my $sql = SQL::Abstract->new; my @fields = qw/name email addr location/; my $table = 'my_users'; my %where = ( year => \@year, email => \@email, location => \@local, name => \@all_names, ); my ( $stmt, @bind ) = $sql->select( $table, \@fields, \%where, \@order + ); print "$stmt\n"; print join '|', @bind;
This data can then be handed directly to your DBI handle:SELECT name, email, addr, location FROM my_users WHERE ( ( ( email = ? OR email = ? OR email = ? ) AND ( location = ? OR location = ? OR location = ? ) AND ( name = ? OR name = ? OR name = ? ) AND ( year = ? OR year = ? OR year = ? ) ) ) ORDER BY location, name first_email|second_email|third_email| here|there|and_everywhere| one|two|three| 1970|1980|1990
As the author of SQL::Abstract so eloquently said : "Easy, eh?".my $sth = $dbh->prepare($stmt); $sth->execute(@bind);
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
In reply to Re: DBI, MAP Help!
by CountZero
in thread DBI, MAP Help!
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |