Beefy Boxes and Bandwidth Generously Provided by pair Networks
vroom "be consistent"  How do Monks programatically construct
SQL selects  by Cody Pendant (Prior) on Sep 03, 2003 at
02:19 UTC ( #288485=perlquestion: print w/ replies, xml ) Need
Help??  I'm currently thinking about SQL selects and how they
can be constructed, so that I can construct them from
subroutines and make things more modular.  Something like  use
strict; sub make_query { my @clauses = @_; my $count = 0; my
$sql = "select * from employees \n"; foreach (@clauses) { if
($count > 0) { $sql .= ' AND ' } else { $sql .= ' WHERE ' }
foreach ($_) { my @criteria = @{$_}; if ($criteria[2] !~
/^\d+$/) { $criteria[2] = "'$criteria[2]'"; } $sql .= "
@criteria \n"; } $count++; } return $sql; } my @array = ( [
'name', '=', 'smith' ], [ 'salary', '>', '50000' ], [
'department', 'NOT LIKE', 'eng%' ] ); print make_query(@array);
### select * from employees ### WHERE name = 'smith' ### AND
salary > 50000 ### AND department NOT LIKE 'eng%'  So am I
missing