expression expansion pass, zeroth cut
[scpubgit/Q-Branch.git] / lib / SQL / Abstract.pm
index 02ea6dd..3327db7 100644 (file)
@@ -535,14 +535,26 @@ sub where {
   return wantarray ? ($sql, @bind) : $sql;
 }
 
+sub _expand_expr {
+  my ($self, $expr, $logic) = @_;
+  if (ref($expr) eq 'HASH' and keys %$expr > 1) {
+    $logic ||= 'and';
+    return +{ "-${logic}" => [
+      map +{ $_ => $expr->{$_} }, sort keys %$expr
+    ] };
+  }
+  return $expr;
+}
 
 sub _recurse_where {
   my ($self, $where, $logic) = @_;
 
+  my $where_exp = $self->_expand_expr($where, $logic);
+
   # dispatch on appropriate method according to refkind of $where
-  my $method = $self->_METHOD_FOR_refkind("_where", $where);
+  my $method = $self->_METHOD_FOR_refkind("_where", $where_exp);
 
-  my ($sql, @bind) =  $self->$method($where, $logic);
+  my ($sql, @bind) =  $self->$method($where_exp, $logic);
 
   # DBIx::Class used to call _recurse_where in scalar context
   # something else might too...
@@ -844,7 +856,7 @@ sub _where_op_VALUE {
   # special-case NULL
   if (! defined $rhs) {
     return defined $lhs
-      ? $self->_convert($self->_quote($lhs)) . ' IS NULL'
+      ? $self->_where_hashpair_HASHREF($lhs, { -is => undef })
       : undef
     ;
   }
@@ -1096,8 +1108,7 @@ sub _where_hashpair_SCALAR {
 sub _where_hashpair_UNDEF {
   my ($self, $k, $v) = @_;
   $self->_debug("UNDEF($k) means IS NULL");
-  my $sql = $self->_quote($k) . $self->_sqlcase(' is null');
-  return ($sql);
+  return $self->_where_hashpair_HASHREF($k, { -is => undef });
 }
 
 #======================================================================