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

groditi at dev.catalyst.perl.org groditi at dev.catalyst.perl.org
Thu May 15 21:07:12 BST 2008


Author: groditi
Date: 2008-05-15 21:07:12 +0100 (Thu, 15 May 2008)
New Revision: 4387

Added:
   SQL-Abstract/1.x/trunk/t/06order_by.t
Modified:
   SQL-Abstract/1.x/trunk/Changes
   SQL-Abstract/1.x/trunk/lib/SQL/Abstract.pm
Log:
bumped version but not $REVISION. small fix to order_by plus more tests. docs pending

Modified: SQL-Abstract/1.x/trunk/Changes
===================================================================
--- SQL-Abstract/1.x/trunk/Changes	2008-05-14 17:57:57 UTC (rev 4386)
+++ SQL-Abstract/1.x/trunk/Changes	2008-05-15 20:07:12 UTC (rev 4387)
@@ -1,6 +1,7 @@
 Revision history for SQL::Abstract
 
     - Added { -desc => 'column' } order by support (Ash)
+    - Tiny fix for { -desc => 'columns'} order by support + tests (groditi)
 
 ----------------------------
 revision 1.20

Modified: SQL-Abstract/1.x/trunk/lib/SQL/Abstract.pm
===================================================================
--- SQL-Abstract/1.x/trunk/lib/SQL/Abstract.pm	2008-05-14 17:57:57 UTC (rev 4386)
+++ SQL-Abstract/1.x/trunk/lib/SQL/Abstract.pm	2008-05-15 20:07:12 UTC (rev 4387)
@@ -143,7 +143,8 @@
 use Carp;
 use strict;
 
-our $VERSION  = '1.22';
+our $VERSION  = '1.23';
+#XXX don't understand this below, leaving it for someone else. did bump the $VERSION --groditi
 our $REVISION = '$Id$';
 our $AUTOLOAD;
 
@@ -852,9 +853,10 @@
     my $_order_hash = sub {
       local *__ANON__ = '_order_by_hash';
       my ($col, $order);
-      if ( $col = $_->{-desc} ) {
+      my $hash = shift; # $_ was failing in some cases for me --groditi
+      if ( $col = $hash->{'-desc'} ) {
         $order = 'DESC'
-      } elsif ( $col = $_->{-asc} ) {
+      } elsif ( $col = $hash->{'-asc'} ) {
         $order = 'ASC';
       } else {
         puke "Hash must have a key of '-desc' or '-asc' for ORDER BY";
@@ -1360,7 +1362,7 @@
     Eric Kolve (hashref "AND" support)
     Mike Fragassi (enhancements to "BETWEEN" and "LIKE")
     Dan Kubb (support for "quote_char" and "name_sep")
-    Guillermo Roditi (patch to cleanup "IN" and "BETWEEN")
+    Guillermo Roditi (patch to cleanup "IN" and "BETWEEN", fix and tests for _order_by)
 
 Thanks!
 

Added: SQL-Abstract/1.x/trunk/t/06order_by.t
===================================================================
--- SQL-Abstract/1.x/trunk/t/06order_by.t	                        (rev 0)
+++ SQL-Abstract/1.x/trunk/t/06order_by.t	2008-05-15 20:07:12 UTC (rev 4387)
@@ -0,0 +1,51 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More;
+
+use SQL::Abstract;
+
+my @cases = 
+  (
+   {
+    given => \'colA DESC',
+    expects => ' ORDER BY colA DESC',
+    expects_quoted => ' ORDER BY colA DESC',
+   },
+   {
+    given => 'colA',
+    expects => ' ORDER BY colA',
+    expects_quoted => ' ORDER BY `colA`',
+   },
+   {
+    given => [qw/colA colB/],
+    expects => ' ORDER BY colA, colB',
+    expects_quoted => ' ORDER BY `colA`, `colB`',
+   },
+   {
+    given => {-asc => 'colA'},
+    expects => ' ORDER BY colA ASC',
+    expects_quoted => ' ORDER BY `colA` ASC',
+   },
+   {
+    given => {-desc => 'colB'},
+    expects => ' ORDER BY colB DESC',
+    expects_quoted => ' ORDER BY `colB` DESC',
+   },
+   {
+    given => [{-asc => 'colA'}, {-desc => 'colB'}],
+    expects => ' ORDER BY colA ASC, colB DESC',
+    expects_quoted => ' ORDER BY `colA` ASC, `colB` DESC',
+   },
+  );
+
+my $sql  = SQL::Abstract->new;
+my $sqlq = SQL::Abstract->new({quote_char => '`'});
+
+plan tests => (scalar(@cases) * 2);
+
+for my $case( @cases){
+  is($sql->_order_by($case->{given}), $case->{expects});
+  is($sqlq->_order_by($case->{given}), $case->{expects_quoted});
+}




More information about the Bast-commits mailing list