[Bast-commits] r6404 - in DBIx-Class/0.08/branches/top-crap: lib/DBIx/Class t

caelum at dev.catalyst.perl.org caelum at dev.catalyst.perl.org
Sun May 24 18:13:04 GMT 2009


Author: caelum
Date: 2009-05-24 18:13:04 +0000 (Sun, 24 May 2009)
New Revision: 6404

Modified:
   DBIx-Class/0.08/branches/top-crap/lib/DBIx/Class/SQLAHacks.pm
   DBIx-Class/0.08/branches/top-crap/t/42toplimit.t
Log:
fix Top warnings

Modified: DBIx-Class/0.08/branches/top-crap/lib/DBIx/Class/SQLAHacks.pm
===================================================================
--- DBIx-Class/0.08/branches/top-crap/lib/DBIx/Class/SQLAHacks.pm	2009-05-24 17:17:49 UTC (rev 6403)
+++ DBIx-Class/0.08/branches/top-crap/lib/DBIx/Class/SQLAHacks.pm	2009-05-24 18:13:04 UTC (rev 6404)
@@ -5,6 +5,7 @@
 use strict;
 use warnings;
 use Carp::Clan qw/^DBIx::Class/;
+use Scalar::Util ();
 
 sub new {
   my $self = shift->SUPER::new(@_);
@@ -94,7 +95,6 @@
   return $sql;
 }
 
-
 # While we're at it, this should make LIMIT queries more efficient,
 #  without digging into things too deeply
 use Scalar::Util 'blessed';
@@ -130,11 +130,6 @@
   @rest = (-1) unless defined $rest[0];
   croak "LIMIT 0 Does Not Compute" if $rest[0] == 0;
     # and anyway, SQL::Abstract::Limit will cause a barf if we don't first
-
-  if ($self->{limit_dialect} eq 'Top' && !defined($order)) {
-    $order = '1 ASC';
-  }
-
   my ($sql, @where_bind) = $self->SUPER::select(
     $table, $self->_recurse_fields($fields), $where, $order, @rest
   );
@@ -276,7 +271,18 @@
       }
     } @{ $order }];
   }
-  return $self->SUPER::_order_directions($order);
+  
+  if (ref($order) && Scalar::Util::reftype($order) eq 'ARRAY'
+      && !@$order) {
+        $order = '';
+  }
+
+  my @dirs = $self->SUPER::_order_directions($order);
+
+  if (!defined($dirs[0]) && !defined($dirs[1])) {
+    return ('', '');
+  }
+  return @dirs;
 }
 
 sub _order_directions_hash {

Modified: DBIx-Class/0.08/branches/top-crap/t/42toplimit.t
===================================================================
--- DBIx-Class/0.08/branches/top-crap/t/42toplimit.t	2009-05-24 17:17:49 UTC (rev 6403)
+++ DBIx-Class/0.08/branches/top-crap/t/42toplimit.t	2009-05-24 18:13:04 UTC (rev 6404)
@@ -51,7 +51,8 @@
   my $subquery = $sa->select( [{ subq => \['(SELECT * FROM foo)'] }], [qw{bar baz}], undef, undef, 1, 3);
   is_same_sql(
     $subquery,
-    "SELECT * FROM ( SELECT TOP 1 * FROM ( SELECT TOP 4 bar,baz FROM (SELECT * FROM foo) subq ORDER BY 1 ASC) AS foo ORDER BY 1 DESC) AS bar ORDER BY 1 ASC",);
+    "SELECT * FROM ( SELECT TOP 1 * FROM ( SELECT TOP 4 bar,baz FROM (SELECT * FROM foo) ) AS foo) AS bar",
+  );
 
   is (@w, 0, 'No warnings on limit with subquery')
     || diag join ("\n", @w);




More information about the Bast-commits mailing list