in reply to SQL queries using dynamic array
This way, you don't need to worry about quoting the place names, and it might even give you more headroom in terms of overall statement length.# assume that $dbh is ready... my @places = qw/Otago Auckland Northland Boolaboola/; my $query = <<ENDSQL; SELECT c_mail, c_first, c_last FROM tblClient, tblGroup, tblRegion WHERE tblGroup.g_name = 'motel' AND tblRegion.r_name IN ENDSQL my $sth = $dbh->prepare( $query . ' (' . join(',',map{'?'} @places) . +')' ); $sth->execute( @places );
The @places array dictates how many placeholders are added for the "IN (...)" clause, as well as providing the placeholder values for the execute call, so if you change the number of elements in the array, the sql stuff will follow through without further ado.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: SQL queries using dynamic array
by Anonymous Monk on Nov 16, 2008 at 07:20 UTC | |
by graff (Chancellor) on Nov 16, 2008 at 14:27 UTC | |
by Anonymous Monk on Nov 16, 2008 at 20:43 UTC | |
by graff (Chancellor) on Nov 17, 2008 at 03:31 UTC | |
by cocl04 (Sexton) on Nov 18, 2008 at 15:40 UTC | |
| |
by cocl04 (Sexton) on Nov 18, 2008 at 15:16 UTC |