in reply to Looking for neater solution with dynamic query
my $sql = "SELECT ... FROM table WHERE 1=1 "; my @bind; if( $query{env} ){ $sql .= " AND upper(env) = upper(?) "; push @bind, $query{env}; } if( $query{component} ){ $sql .= " AND upper(component) = upper(?) "; push @bind, $query{component}; } ... my $sth = $dbh->prepare($query); $sth->execute(@bind); # or use one of the $dbh->selectXXXX($query, {}, @bind) methods of DB +I
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Looking for neater solution with dynamic query
by pg (Canon) on Aug 24, 2005 at 22:52 UTC | |
by tlm (Prior) on Aug 25, 2005 at 12:08 UTC | |
by Anonymous Monk on Aug 26, 2005 at 18:13 UTC |