[Bast-commits] r5477 - in SQL-Abstract/1.x/branches/1.50_RC: . lib/SQL t

norbi at dev.catalyst.perl.org norbi at dev.catalyst.perl.org
Sun Feb 15 15:39:26 GMT 2009


Author: norbi
Date: 2009-02-15 15:39:26 +0000 (Sun, 15 Feb 2009)
New Revision: 5477

Modified:
   SQL-Abstract/1.x/branches/1.50_RC/
   SQL-Abstract/1.x/branches/1.50_RC/lib/SQL/Abstract.pm
   SQL-Abstract/1.x/branches/1.50_RC/t/07subqueries.t
Log:
 r5588 at vger:  mendel | 2009-02-15 16:33:43 +0100
  * Applied patch from Zbigniew Lukasiak (with slight modifications) to accept "col => { -in => \[$sql, @bind] }".



Property changes on: SQL-Abstract/1.x/branches/1.50_RC
___________________________________________________________________
Name: svk:merge
   - 4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/SQL-Abstract/1.x/branches/1.50_RC:5583
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/SQL-Abstract/1.x/branches/1.50_RC-extraparens:5308
   + 4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/SQL-Abstract/1.x/branches/1.50_RC:5588
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/SQL-Abstract/1.x/branches/1.50_RC-extraparens:5308

Modified: SQL-Abstract/1.x/branches/1.50_RC/lib/SQL/Abstract.pm
===================================================================
--- SQL-Abstract/1.x/branches/1.50_RC/lib/SQL/Abstract.pm	2009-02-15 14:33:24 UTC (rev 5476)
+++ SQL-Abstract/1.x/branches/1.50_RC/lib/SQL/Abstract.pm	2009-02-15 15:39:26 UTC (rev 5477)
@@ -697,25 +697,36 @@
   # backwards compatibility : if scalar, force into an arrayref
   $vals = [$vals] if defined $vals && ! ref $vals;
 
-  ref $vals eq 'ARRAY'
-    or puke "special op 'in' requires an arrayref";
-
   my ($label)       = $self->_convert($self->_quote($k));
   my ($placeholder) = $self->_convert('?');
-  my $and           = $self->_sqlcase('and');
   $op               = $self->_sqlcase($op);
 
-  if (@$vals) { # nonempty list
-    my $placeholders  = join ", ", (($placeholder) x @$vals);
-    my $sql           = "$label $op ( $placeholders )";
-    my @bind = $self->_bindtype($k, @$vals);
+  my ($sql, @bind) = $self->_SWITCH_refkind($vals, {
+    ARRAYREF => sub {     # list of choices
+      if (@$vals) { # nonempty list
+        my $placeholders  = join ", ", (($placeholder) x @$vals);
+        my $sql           = "$label $op ( $placeholders )";
+        my @bind = $self->_bindtype($k, @$vals);
 
-    return ($sql, @bind);
-  }
-  else { # empty list : some databases won't understand "IN ()", so DWIM
-    my $sql = ($op =~ /\bnot\b/i) ? $self->{sqltrue} : $self->{sqlfalse};
-    return ($sql);
-  }
+        return ($sql, @bind);
+      }
+      else { # empty list : some databases won't understand "IN ()", so DWIM
+        my $sql = ($op =~ /\bnot\b/i) ? $self->{sqltrue} : $self->{sqlfalse};
+        return ($sql);
+      }
+    },
+
+    ARRAYREFREF => sub {  # literal SQL with bind
+      my ($sql, @bind) = @$$vals;
+      return ("$label $op ( $sql )", @bind);
+    },
+
+    FALLBACK => sub {
+      puke "special op 'in' requires an arrayref (or arrayref-ref)";
+    },
+  });
+
+  return ($sql, @bind);
 }
 
 

Modified: SQL-Abstract/1.x/branches/1.50_RC/t/07subqueries.t
===================================================================
--- SQL-Abstract/1.x/branches/1.50_RC/t/07subqueries.t	2009-02-15 14:33:24 UTC (rev 5476)
+++ SQL-Abstract/1.x/branches/1.50_RC/t/07subqueries.t	2009-02-15 15:39:26 UTC (rev 5477)
@@ -77,7 +77,20 @@
   bind => [10, 20, '%son%'],
 };
 
+#6
+($sub_stmt, @sub_bind) = ("SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?",
+                          100, "foo%");
+$where = {
+    foo => 1234,
+    bar => { -in => \[$sub_stmt => @sub_bind] },
+  };
+push @tests, {
+  where => $where,
+  stmt => " WHERE ( bar IN (SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?) AND foo = ? )",
+  bind => [100, "foo%", 1234],
+};
 
+
 plan tests => scalar(@tests);
 
 for (@tests) {




More information about the Bast-commits mailing list