in reply to DBIx::Class Build a Where Clause with multiple ORs and ANDs
Hi, since you've been struggling with this stuff for a long time now, I strongly suggest again that you spend some time experimenting with SQL::Abstract, which is the SQL generator used by DBIx::Class.
Use arrays for ORs; use hashes for ANDs. Until your query gets complicated, you can skip the -and and -or keywords.
Updated: Based on the correction you made to your spec.
Output:use strict; use warnings; use SQL::Abstract; my $sqla = SQL::Abstract->new; my @where = ( { status => 'Review' }, { status => [ 'Offered', 'Denied', 'Cancelled', 'Conditional O +ffer' ], sent_email => { '!=' => [ -and => undef, '0000-00-00' ] }, }, ); my ( $sql, @bind ) = $sqla->where( \@where ); say $sql; say for @bind; __END__
Used with DBIx::Class:perl 1206574.pl WHERE ( ( status = ? OR ( ( sent_email IS NOT NULL AND sent_email != +? ) AND ( status = ? OR status = ? OR status = ? OR status = ? ) ) ) +) Review 0000-00-00 Offered Denied Cancelled Conditional Offer
$schema->resultset( 'TblRequests' )->search([ { status => 'Review' }, { status => [ 'Offered', 'Denied', 'Cancelled', 'Conditional O +ffer' ], sent_email => { '!=' => [ -and => undef, '0000-00-00' ] }, }, ]);
Hope this helps!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: DBIx::Class Build a Where Clause with multiple ORs and ANDs
by phildeman (Scribe) on Jan 03, 2018 at 16:30 UTC |