Support for the { operator => \["...", @bind] } construct (to embed literal SQL with...
Norbert Buchmuller [Wed, 26 Nov 2008 18:58:34 +0000 (18:58 +0000)]
lib/SQL/Abstract.pm
t/01generate.t

index 848a60f..248ec3a 100644 (file)
@@ -536,6 +536,14 @@ sub _where_hashpair_HASHREF {
                             $$val;
         },
 
+        ARRAYREFREF => sub {    # CASE: col => {op => \[$sql, @bind]}
+          my ($sub_sql, @sub_bind) = @$$val;
+          $sql  = join ' ', $self->_convert($self->_quote($k)),
+                            $self->_sqlcase($op),
+                            $sub_sql;
+          @bind = @sub_bind;
+        },
+
         UNDEF => sub {          # CASE: col => {op => undef} : sql "IS (NOT)? NULL"
           my $is = ($op =~ $self->{equality_op})   ? 'is'     :
                    ($op =~ $self->{inequality_op}) ? 'is not' :
index 18e015c..419d3e4 100644 (file)
@@ -352,6 +352,14 @@ my @tests = (
               stmt_q => 'SELECT * FROM `test` WHERE ( `a` > 1 + 1 AND `b` = ? )',
               bind   => [8],
       },             
+      #38
+      {
+              func   => 'select',
+              args   => ['test', '*', { a => {'<' => \["to_date(?, 'MM/DD/YY')", '02/02/02']}, b => 8 }],
+              stmt   => 'SELECT * FROM test WHERE ( a < to_date(?, \'MM/DD/YY\') AND b = ? )',
+              stmt_q => 'SELECT * FROM `test` WHERE ( `a` < to_date(?, \'MM/DD/YY\') AND `b` = ? )',
+              bind   => ['02/02/02', 8],
+      },             
 );