Propagate bindtype properly over nested functions
[scpubgit/Q-Branch.git] / lib / SQL / Abstract.pm
index e90208c..3888f65 100644 (file)
@@ -513,7 +513,13 @@ sub _where_func_generic {
 
   my ($sql, @bind) = $self->_SWITCH_refkind ($rhs, {
     SCALAR =>   sub {
-      ($self->_convert('?'), $self->_bindtype('xxx', $rhs) );
+      puke "Illegal use of top-level '$op'"
+        unless $self->{_nested_func_lhs};
+
+      return (
+        $self->_convert('?'),
+        $self->_bindtype($self->{_nested_func_lhs}, $rhs)
+      );
     },
     FALLBACK => sub {
       $self->_recurse_where ($rhs)
@@ -648,6 +654,9 @@ sub _where_hashpair_HASHREF {
   my ($self, $k, $v, $logic) = @_;
   $logic ||= 'and';
 
+  local $self->{_nested_func_lhs} = $self->{_nested_func_lhs};
+  $self->{_nested_func_lhs} ||= $k;
+
   my ($all_sql, @all_bind);
 
   for my $orig_op (sort keys %$v) {