[Dbix-class] [OT][ANNOUNCE] SQL Generation with SQL::DB
Mark Lawrence
nomad at null.net
Fri Sep 7 13:06:15 GMT 2007
On Fri Sep 07, 2007 at 11:07:26AM +0200, Emanuele Zeppieri wrote:
> > ($track->length > 248) & ! ($cd->year < 1997)
>
> No, I'm asking how it could be *built* by code without string
> concatenations/interpolations.
Don't forget, the operators in the above statements are not strings,
so concatenation won't work anyway.
> (For example, think of arbitrarily data input by the user via a search
> form that the code has to turn into (arbitrarily complex) where clauses).
my $length = $form->param('length');
my $year = $form->param('year');
my $not = $form->param('not');
my $expr = SQL::DB::Expr;
if ($length) {
$expr = $track->length > $length;
}
if ($year) {
if ($not) {
$expr = $expr & ! ($cd->year < $year);
}
else {
$expr = $expr & ($cd->year < $year);
}
}
Cheers,
Mark.
--
Mark Lawrence
More information about the DBIx-Class
mailing list