Fix stupid assumption in parenthesis unroller
[dbsrgits/SQL-Abstract.git] / lib / SQL / Abstract / Tree.pm
index 0db1757..864451a 100644 (file)
@@ -527,6 +527,7 @@ my @unrollable_ops = (
   'GROUP \s+ BY',
   'HAVING',
   'ORDER \s+ BY',
+  'I?LIKE',
 );
 my $unrollable_ops_re = join ' | ', @unrollable_ops;
 $unrollable_ops_re = qr/$unrollable_ops_re/xi;
@@ -545,7 +546,7 @@ sub _parenthesis_unroll {
 
     for my $child (@{$ast->[1]}) {
       # the current node in this loop is *always* a PAREN
-      if (not ref $child or not $child->[0] eq 'PAREN') {
+      if (! ref $child or ! @$child or $child->[0] ne 'PAREN') {
         push @children, $child;
         next;
       }
@@ -573,11 +574,14 @@ sub _parenthesis_unroll {
       }
 
       # only *ONE* LITERAL or placeholder element
+      # as an AND/OR/NOT argument
       elsif (
         @{$child->[1]} == 1 && (
           $child->[1][0][0] eq 'LITERAL'
             or
           $child->[1][0][0] eq 'PLACEHOLDER'
+        ) && (
+          $ast->[0] eq 'AND' or $ast->[0] eq 'OR' or $ast->[0] eq 'NOT'
         )
       ) {
         push @children, $child->[1][0];