Fix some warnings
[scpubgit/Q-Branch.git] / lib / SQL / Abstract.pm
index 5936443..532d70a 100644 (file)
@@ -15,7 +15,7 @@ use Scalar::Util qw/blessed/;
 # GLOBALS
 #======================================================================
 
-our $VERSION  = '1.56';
+our $VERSION  = '1.58';
 
 # This would confuse some packagers
 #$VERSION      = eval $VERSION; # numify for warning-free dev releases
@@ -553,14 +553,35 @@ sub _where_op_NEST {
 sub _where_op_BOOL {
   my ($self, $op, $v) = @_; 
 
-  my $prefix = ($op =~ /\bnot\b/i) ? 'NOT ' : '';
+  my ( $prefix, $suffix ) = ( $op =~ /\bnot\b/i ) 
+    ? ( '(NOT ', ')' ) 
+    : ( '', '' );
   $self->_SWITCH_refkind($v, {
+    ARRAYREF => sub {
+      my ( $sql, @bind ) = $self->_where_ARRAYREF($v, '');
+      return ( ($prefix . $sql . $suffix), @bind );
+    },
+
+    ARRAYREFREF => sub {
+      my ( $sql, @bind ) = @{ ${$v} };
+      return ( ($prefix . $sql . $suffix), @bind );
+    },
+
+    HASHREF => sub {
+      my ( $sql, @bind ) = $self->_where_HASHREF($v);
+      return ( ($prefix . $sql . $suffix), @bind );
+    },
+
     SCALARREF  => sub {         # literal SQL
-      return ($prefix . $$v); 
+      return ($prefix . $$v . $suffix); 
     },
 
     SCALAR => sub { # interpreted as SQL column
-      return ($prefix . $self->_convert($self->_quote($v))); 
+      return ($prefix . $self->_convert($self->_quote($v)) . $suffix); 
+    },
+
+    UNDEF => sub {
+      puke "-$op => undef not supported";
     },
    });
 }
@@ -687,11 +708,14 @@ sub _where_field_op_ARRAYREF {
   my @vals = @$vals;  #always work on a copy
 
   if(@vals) {
-    $self->_debug("ARRAY($vals) means multiple elements: [ @vals ]");
+    $self->_debug(sprintf '%s means multiple elements: [ %s ]',
+      $vals,
+      join (', ', map { defined $_ ? "'$_'" : 'NULL' } @vals ),
+    );
 
     # see if the first element is an -and/-or op
     my $logic;
-    if ($vals[0] =~ /^ - ( AND|OR ) $/ix) {
+    if (defined $vals[0] && $vals[0] =~ /^ - ( AND|OR ) $/ix) {
       $logic = uc $1;
       shift @vals;
     }
@@ -1956,8 +1980,23 @@ example to test the column C<is_user> being true and the column
 
 Would give you:
 
-    WHERE is_user AND NOT is_enabledmv 
+    WHERE is_user AND NOT is_enabled
+
+If a more complex combination is required, testing more conditions,
+then you should use the and/or operators:-
+
+    my %where  = (
+        -and           => [
+            -bool      => 'one',
+            -bool      => 'two',
+            -bool      => 'three',
+            -not_bool  => 'four',
+        ],
+    );
+
+Would give you:
 
+    WHERE one AND two AND three AND NOT four
 
 
 =head2 Nested conditions, -and/-or prefixes
@@ -2080,8 +2119,10 @@ with this:
 
 TMTOWTDI.
 
-Conditions on boolean columns can be expressed in the 
-same way, passing a reference to an empty string :
+Conditions on boolean columns can be expressed in the same way, passing
+a reference to an empty string, however using liternal SQL in this way
+is deprecated - the preferred method is to use the boolean operators -
+see L</"Unary operators: bool"> :
 
     my %where = (
         priority  => { '<', 2 },