[Bast-commits] r4390 - in SQL-Abstract/1.x/branches/cleanup: . lib/SQL t

groditi at dev.catalyst.perl.org groditi at dev.catalyst.perl.org
Fri May 16 19:17:23 BST 2008


Author: groditi
Date: 2008-05-16 19:17:23 +0100 (Fri, 16 May 2008)
New Revision: 4390

Added:
   SQL-Abstract/1.x/branches/cleanup/t/06order_by.t
Modified:
   SQL-Abstract/1.x/branches/cleanup/
   SQL-Abstract/1.x/branches/cleanup/Changes
   SQL-Abstract/1.x/branches/cleanup/lib/SQL/Abstract.pm
Log:
 r17737 at martha (orig r4387):  groditi | 2008-05-15 16:07:12 -0400
 bumped version but not $REVISION. small fix to order_by plus more tests. docs pending
 r17738 at martha (orig r4388):  groditi | 2008-05-15 16:28:33 -0400
 one more test and some simple docs



Property changes on: SQL-Abstract/1.x/branches/cleanup
___________________________________________________________________
Name: svk:merge
   - b9bda2dc-4395-4011-945f-8c81d782bde1:/branches/matthewt:18
b9bda2dc-4395-4011-945f-8c81d782bde1:/trunk:23
   + b9bda2dc-4395-4011-945f-8c81d782bde1:/branches/matthewt:18
b9bda2dc-4395-4011-945f-8c81d782bde1:/trunk:23
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/SQL-Abstract/1.x/trunk:4388
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/trunk/SQL-Abstract:3093

Modified: SQL-Abstract/1.x/branches/cleanup/Changes
===================================================================
--- SQL-Abstract/1.x/branches/cleanup/Changes	2008-05-16 17:31:16 UTC (rev 4389)
+++ SQL-Abstract/1.x/branches/cleanup/Changes	2008-05-16 18:17:23 UTC (rev 4390)
@@ -1,6 +1,8 @@
 Revision history for SQL::Abstract
 
     - Added { -desc => 'column' } order by support (Ash)
+    - Tiny "$_"-related fix for { -desc => 'columns'} order by support 
+      - tests + docs (groditi)
 
 ----------------------------
 revision 1.20

Modified: SQL-Abstract/1.x/branches/cleanup/lib/SQL/Abstract.pm
===================================================================
--- SQL-Abstract/1.x/branches/cleanup/lib/SQL/Abstract.pm	2008-05-16 17:31:16 UTC (rev 4389)
+++ SQL-Abstract/1.x/branches/cleanup/lib/SQL/Abstract.pm	2008-05-16 18:17:23 UTC (rev 4390)
@@ -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";
@@ -1269,8 +1271,22 @@
 
 Some functions take an order by clause. This can either be a scalar (just a 
 column name,) a hash of C<< { -desc => 'col' } >> or C<< { -asc => 'col' } >>,
-or an array of either of the two previous forms.
+or an array of either of the two previous forms. Examples:
 
+             Given             |    Will Generate
+    ----------------------------------------------------------
+    \'colA DESC'               | ORDER BY colA DESC
+    'colA'                     | ORDER BY colA
+    [qw/colA colB/]            | ORDER BY colA, colB
+    {-asc  => 'colA'}          | ORDER BY colA ASC
+    {-desc => 'colB'}          | ORDER BY colB DESC
+    [                          |
+      {-asc  => 'colA'},       | ORDER BY colA ASC, colB DESC
+      {-desc => 'colB'}        |
+    ]                          |
+    [colA => {-asc => 'colB'}] | ORDER BY colA, colB ASC
+    ==========================================================
+
 =head1 PERFORMANCE
 
 Thanks to some benchmarking by Mark Stosberg, it turns out that
@@ -1360,7 +1376,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/branches/cleanup/t/06order_by.t
===================================================================
--- SQL-Abstract/1.x/branches/cleanup/t/06order_by.t	                        (rev 0)
+++ SQL-Abstract/1.x/branches/cleanup/t/06order_by.t	2008-05-16 18:17:23 UTC (rev 4390)
@@ -0,0 +1,56 @@
+#!/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',
+   },
+   {
+    given => ['colA', {-desc => 'colB'}],
+    expects => ' ORDER BY colA, colB DESC',
+    expects_quoted => ' ORDER BY `colA`, `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