[Bast-commits] r6007 - SQL-Abstract/1.x/branches/and_or/lib/SQL
ribasushi at dev.catalyst.perl.org
ribasushi at dev.catalyst.perl.org
Tue Apr 28 21:57:54 GMT 2009
Author: ribasushi
Date: 2009-04-28 22:57:54 +0100 (Tue, 28 Apr 2009)
New Revision: 6007
Modified:
SQL-Abstract/1.x/branches/and_or/lib/SQL/Abstract.pm
Log:
A much better fix for the x => [ -and, ... ] corner case
Modified: SQL-Abstract/1.x/branches/and_or/lib/SQL/Abstract.pm
===================================================================
--- SQL-Abstract/1.x/branches/and_or/lib/SQL/Abstract.pm 2009-04-28 21:43:16 UTC (rev 6006)
+++ SQL-Abstract/1.x/branches/and_or/lib/SQL/Abstract.pm 2009-04-28 21:57:54 UTC (rev 6007)
@@ -606,17 +606,25 @@
if(@$vals) {
$self->_debug("ARRAY($vals) means multiple elements: [ @$vals ]");
+ # see if the first element is an -and/-or op
+ my $logic;
+ if ($vals->[0] =~ /^ - ( AND|OR ) $/ix) {
+ $logic = uc $1;
+ shift @$vals;
+ }
+
+ # distribute $op over each remaining member of @$vals, append logic if exists
+ return $self->_recurse_where([map { {$k => {$op, $_}} } @$vals], $logic);
+
# LDNOTE : had planned to change the distribution logic when
# $op =~ $self->{inequality_op}, because of Morgan laws :
# with {field => {'!=' => [22, 33]}}, it would be ridiculous to generate
# WHERE field != 22 OR field != 33 : the user probably means
# WHERE field != 22 AND field != 33.
- # To do this, replace the line below by :
+ # To do this, replace the above to roughly :
# my $logic = ($op =~ $self->{inequality_op}) ? 'AND' : 'OR';
# return $self->_recurse_where([map { {$k => {$op, $_}} } @$vals], $logic);
- # distribute $op over each member of @$vals
- return $self->_recurse_where([map { {$k => {$op, $_}} } @$vals]);
}
else {
# try to DWIM on equality operators
More information about the Bast-commits
mailing list