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

arcanez at dev.catalyst.perl.org arcanez at dev.catalyst.perl.org
Fri Apr 24 18:47:06 GMT 2009


Author: arcanez
Date: 2009-04-24 19:47:06 +0100 (Fri, 24 Apr 2009)
New Revision: 5981

Modified:
   SQL-Abstract/1.x/trunk/lib/SQL/Abstract.pm
   SQL-Abstract/1.x/trunk/t/06order_by.t
Log:
add support for order_by => [qw/colA colB/]

Modified: SQL-Abstract/1.x/trunk/lib/SQL/Abstract.pm
===================================================================
--- SQL-Abstract/1.x/trunk/lib/SQL/Abstract.pm	2009-04-24 16:52:50 UTC (rev 5980)
+++ SQL-Abstract/1.x/trunk/lib/SQL/Abstract.pm	2009-04-24 18:47:06 UTC (rev 5981)
@@ -829,7 +829,8 @@
   my ($order) = ($key =~ /^-(desc|asc)/i)
     or puke "invalid key in _order_by hash : $key";
 
-  return $self->_quote($val) ." ". $self->_sqlcase($order);
+  $val = ref $val eq 'ARRAY' ? $val : [$val];
+  return join ', ', map { $self->_quote($_) . ' ' . $self->_sqlcase($order) } @$val;
 }
 
 
@@ -2097,6 +2098,9 @@
       {-desc => 'colB'}        |
     ]                          |
     [colA => {-asc => 'colB'}] | ORDER BY colA, colB ASC
+    { -asc => [qw/colA colB] } | ORDER BY colA ASC, colB ASC
+    { -asc => [qw/colA colB] },|
+     -desc => [qw/colC colD] } | ORDER BY colA ASC, colB ASC, colC DESC, colD DESC
     ==========================================================
 
 

Modified: SQL-Abstract/1.x/trunk/t/06order_by.t
===================================================================
--- SQL-Abstract/1.x/trunk/t/06order_by.t	2009-04-24 16:52:50 UTC (rev 5980)
+++ SQL-Abstract/1.x/trunk/t/06order_by.t	2009-04-24 18:47:06 UTC (rev 5981)
@@ -59,6 +59,28 @@
     expects => '',
     expects_quoted => '',
    },
+
+   {
+    given => [{-desc => [ qw/colA colB/ ] }],
+    expects => ' ORDER BY colA DESC, colB DESC',
+    expects_quoted => ' ORDER BY `colA` DESC, `colB` DESC',
+   },
+   {
+    given => [{-desc => [ qw/colA colB/ ] }, {-asc => 'colC'}],
+    expects => ' ORDER BY colA DESC, colB DESC, colC ASC',
+    expects_quoted => ' ORDER BY `colA` DESC, `colB` DESC, `colC` ASC',
+   },
+   {
+    given => [{-desc => [ qw/colA colB/ ] }, {-asc => [ qw/colC colD/ ] }],
+    expects => ' ORDER BY colA DESC, colB DESC, colC ASC, colD ASC',
+    expects_quoted => ' ORDER BY `colA` DESC, `colB` DESC, `colC` ASC, `colD` ASC',
+   },
+   {
+    given => [{-desc => [ qw/colA colB/ ] }, {-desc => 'colC' }],
+    expects => ' ORDER BY colA DESC, colB DESC, colC DESC',
+    expects_quoted => ' ORDER BY `colA` DESC, `colB` DESC, `colC` DESC',
+   },
+
   );
 
 




More information about the Bast-commits mailing list