my $stmt = new SQL::Fragment("SELECT *, PRICE+? FROM ITEMS", $fees);
my @conds = ();
push(@conds, new SQL::Fragment("color = ?", "blue"));
push(@conds, [ "size = ?", "XXL" ]); # can also just use array refs
if (@conds) {
$stmt->append(" WHERE ")->append_join(" AND ", @conds);
}
my ($sql, @params) = $stmt->sql_and_params;
####
sub append - append another SQL Fragment to $self
sub append_join - append a join-ed list of SQL Fragments to $self
sub append_join_parens - do the equivalent of:
join( $sep, map { "($_)" } @list )
For instance, this is useful to ensure each condition is in it's own set of parens.
####
sub append_join_parens {
my $self = shift;
$self->append_join_map( sub {
[ "(".$_->sql.")", $_->params ]
});
$self;
}