[Bast-commits] r8259 - DBIx-Class/0.08/branches/mssql_limit_regression/lib/DBIx/Class

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Fri Jan 8 22:58:13 GMT 2010


Author: ribasushi
Date: 2010-01-08 22:58:13 +0000 (Fri, 08 Jan 2010)
New Revision: 8259

Modified:
   DBIx-Class/0.08/branches/mssql_limit_regression/lib/DBIx/Class/SQLAHacks.pm
Log:
Cleaner RNO sql

Modified: DBIx-Class/0.08/branches/mssql_limit_regression/lib/DBIx/Class/SQLAHacks.pm
===================================================================
--- DBIx-Class/0.08/branches/mssql_limit_regression/lib/DBIx/Class/SQLAHacks.pm	2010-01-08 18:19:41 UTC (rev 8258)
+++ DBIx-Class/0.08/branches/mssql_limit_regression/lib/DBIx/Class/SQLAHacks.pm	2010-01-08 22:58:13 UTC (rev 8259)
@@ -51,21 +51,27 @@
 sub _RowNumberOver {
   my ($self, $sql, $order, $rows, $offset ) = @_;
 
+  # get the select to make the final amount of columns equal the original one
+  my ($select) = $sql =~ /^ \s* SELECT \s+ (.+?) \s+ FROM/ix
+    or croak "Unrecognizable SELECT: $sql";
+
   # get the order_by only (or make up an order if none exists)
   my $order_by = $self->_order_by(
     (delete $order->{order_by}) || $self->_rno_default_order
   );
 
-  # whatever is left
+  # whatever is left of the order_by
   my $group_having = $self->_order_by($order);
 
   my $qalias = $self->_quote ($self->{_dbic_rs_attrs}{alias});
 
-  $sql = sprintf (<<'EOS', $qalias, $order_by, $sql, $group_having, $qalias, $offset + 1, $offset + $rows, );
+  $sql = sprintf (<<EOS, $offset + 1, $offset + $rows, );
 
-SELECT * FROM (
-  SELECT %s.*, ROW_NUMBER() OVER(%s ) AS rno__row__index FROM (%s%s) %s
-) rno_subq WHERE rno__row__index BETWEEN %d AND %d
+SELECT $select FROM (
+  SELECT $qalias.*, ROW_NUMBER() OVER($order_by ) AS rno__row__index FROM (
+    ${sql}${group_having}
+  ) $qalias
+) $qalias WHERE rno__row__index BETWEEN %d AND %d
 
 EOS
 




More information about the Bast-commits mailing list