[Bast-commits] r6416 - in DBIx-Class/0.08/branches: . top_limit_altfix/lib/DBIx/Class top_limit_altfix/t

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Mon May 25 14:08:40 GMT 2009


Author: ribasushi
Date: 2009-05-25 14:08:40 +0000 (Mon, 25 May 2009)
New Revision: 6416

Removed:
   DBIx-Class/0.08/branches/top_limit_tweaks/
Modified:
   DBIx-Class/0.08/branches/top_limit_altfix/lib/DBIx/Class/SQLAHacks.pm
   DBIx-Class/0.08/branches/top_limit_altfix/t/42toplimit.t
Log:
Shoot another Top problem, move test from top_limit_tweaks branch and delete

Modified: DBIx-Class/0.08/branches/top_limit_altfix/lib/DBIx/Class/SQLAHacks.pm
===================================================================
--- DBIx-Class/0.08/branches/top_limit_altfix/lib/DBIx/Class/SQLAHacks.pm	2009-05-25 09:24:32 UTC (rev 6415)
+++ DBIx-Class/0.08/branches/top_limit_altfix/lib/DBIx/Class/SQLAHacks.pm	2009-05-25 14:08:40 UTC (rev 6416)
@@ -99,11 +99,16 @@
   croak '$order supplied to SQLAHacks limit emulators must be a hash'
     if (ref $order ne 'HASH');
 
+  $order = { %$order }; #copy
+
   my $last = $rows + $offset;
 
   my $req_order = $self->_order_by ($order->{order_by});
   my $limit_order = $req_order ? $order->{order_by} : $order->{_virtual_order_by};
 
+  delete $order->{$_} for qw/order_by _virtual_order_by/;
+  my $grpby_having = $self->_order_by ($order);
+
   my ( $order_by_inner, $order_by_outer ) = $self->_order_directions($limit_order);
 
   $sql =~ s/^\s*(SELECT|select)//;
@@ -113,7 +118,7 @@
   (
     SELECT TOP $rows * FROM
     (
-        SELECT TOP $last $sql $order_by_inner
+        SELECT TOP $last $sql $grpby_having $order_by_inner
     ) AS foo
     $order_by_outer
   ) AS bar

Modified: DBIx-Class/0.08/branches/top_limit_altfix/t/42toplimit.t
===================================================================
--- DBIx-Class/0.08/branches/top_limit_altfix/t/42toplimit.t	2009-05-25 09:24:32 UTC (rev 6415)
+++ DBIx-Class/0.08/branches/top_limit_altfix/t/42toplimit.t	2009-05-25 14:08:40 UTC (rev 6416)
@@ -9,6 +9,8 @@
 my $schema = DBICTest->init_schema;
 
 # Trick the sqlite DB to use Top limit emulation
+# We could test all of this via $sq->$op directly,
+# but some conditions needs a $rsrc
 delete $schema->storage->_sql_maker->{_cached_syntax};
 $schema->storage->_sql_maker->limit_dialect ('Top');
 
@@ -115,5 +117,22 @@
   },
 );
 
-plan (tests => scalar @tests);
+plan (tests => scalar @tests + 1);
+
 test_order ($_) for @tests;
+
+is_same_sql_bind (
+  $rs->search ({}, { group_by => 'bar', order_by => 'bar' })->as_query,
+  '(
+    SELECT * FROM
+    (
+      SELECT TOP 1 * FROM
+      (
+        SELECT TOP 4  me.foo, me.bar, me.hello, me.goodbye, me.sensors, me.read_count FROM fourkeys me GROUP BY bar ORDER BY bar ASC
+      ) AS foo
+      ORDER BY bar DESC
+    ) AS bar
+    ORDER BY bar
+  )',
+  [],
+);




More information about the Bast-commits mailing list