[Bast-commits] r8948 - in SQL-Abstract/1.x/trunk: lib/SQL t

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Tue Mar 9 12:09:54 GMT 2010


Author: ribasushi
Date: 2010-03-09 12:09:53 +0000 (Tue, 09 Mar 2010)
New Revision: 8948

Modified:
   SQL-Abstract/1.x/trunk/lib/SQL/Abstract.pm
   SQL-Abstract/1.x/trunk/t/01generate.t
Log:
Extra nesting test and fix

Modified: SQL-Abstract/1.x/trunk/lib/SQL/Abstract.pm
===================================================================
--- SQL-Abstract/1.x/trunk/lib/SQL/Abstract.pm	2010-03-09 10:55:51 UTC (rev 8947)
+++ SQL-Abstract/1.x/trunk/lib/SQL/Abstract.pm	2010-03-09 12:09:53 UTC (rev 8948)
@@ -655,7 +655,6 @@
   $logic ||= 'and';
 
   local $self->{_nested_func_lhs} = $self->{_nested_func_lhs};
-  $self->{_nested_func_lhs} ||= $k;
 
   my ($all_sql, @all_bind);
 
@@ -714,8 +713,17 @@
         },
 
         FALLBACK => sub {       # CASE: col => {op/func => $stuff}
+
+          # if we are starting to nest and the first func is not a cmp op
+          # assume equality
+          my $prefix;
+          unless ($self->{_nested_func_lhs}) {
+            $self->{_nested_func_lhs} = $k;
+            $prefix = $self->{cmp} unless $op =~ $self->{cmp_ops};
+          }
+
           ($sql, @bind) = $self->_where_func_generic ($op, $val);
-          $sql = join ' ', $self->_convert($self->_quote($k)), $sql;
+          $sql = join ' ', $self->_convert($self->_quote($k)), $prefix||(), $sql;
         },
       });
     }

Modified: SQL-Abstract/1.x/trunk/t/01generate.t
===================================================================
--- SQL-Abstract/1.x/trunk/t/01generate.t	2010-03-09 10:55:51 UTC (rev 8947)
+++ SQL-Abstract/1.x/trunk/t/01generate.t	2010-03-09 12:09:53 UTC (rev 8948)
@@ -231,10 +231,10 @@
       #26            
       {              
               func   => 'select',
-              args   => ['test', '*', {priority => [ -and => {'!=', 2}, {'!=', 1} ]}],
-              stmt   => 'SELECT * FROM test WHERE ( ( ( priority != ? ) AND ( priority != ? ) ) )',
-              stmt_q => 'SELECT * FROM `test` WHERE ( ( ( `priority` != ? ) AND ( `priority` != ? ) ) )',
-              bind   => [qw(2 1)],
+              args   => ['test', '*', {priority => [ -and => {'!=', 2}, { -not_like => '3%'} ]}],
+              stmt   => 'SELECT * FROM test WHERE ( ( ( priority != ? ) AND ( priority NOT LIKE ? ) ) )',
+              stmt_q => 'SELECT * FROM `test` WHERE ( ( ( `priority` != ? ) AND ( `priority` NOT LIKE ? ) ) )',
+              bind   => [qw(2 3%)],
       },             
       #27            
       {              
@@ -584,6 +584,14 @@
               stmt_q => 'INSERT INTO `test` VALUES (?, ?, ?, ?, ?) RETURNING id',
               bind   => [qw/1 2 3 4 5/],
       },
+      {
+              func   => 'select',
+              new    => {bindtype => 'columns'},
+              args   => ['test', '*', [ Y => { -max => { -LENGTH => { -min => 'x' } } } ] ],
+              stmt   => 'SELECT * FROM test WHERE ( Y = MAX( LENGTH( MIN( ? ) ) ) )',
+              stmt_q => 'SELECT * FROM `test` WHERE ( `Y` = MAX( LENGTH( MIN( ? ) ) ) )',
+              bind   => [[Y => 'x']],
+      },
 );
 
 




More information about the Bast-commits mailing list