[Bast-commits] r8015 - in
DBIx-Class/0.08/branches/mssql_rno_pagination/lib/DBIx/Class:
SQLAHacks Storage/DBI
frew at dev.catalyst.perl.org
frew at dev.catalyst.perl.org
Thu Dec 3 01:48:37 GMT 2009
Author: frew
Date: 2009-12-03 01:48:36 +0000 (Thu, 03 Dec 2009)
New Revision: 8015
Modified:
DBIx-Class/0.08/branches/mssql_rno_pagination/lib/DBIx/Class/SQLAHacks/MSSQL.pm
DBIx-Class/0.08/branches/mssql_rno_pagination/lib/DBIx/Class/Storage/DBI/MSSQL.pm
Log:
Switch to RowNumberOver for MSSQL
Modified: DBIx-Class/0.08/branches/mssql_rno_pagination/lib/DBIx/Class/SQLAHacks/MSSQL.pm
===================================================================
--- DBIx-Class/0.08/branches/mssql_rno_pagination/lib/DBIx/Class/SQLAHacks/MSSQL.pm 2009-12-02 22:52:40 UTC (rev 8014)
+++ DBIx-Class/0.08/branches/mssql_rno_pagination/lib/DBIx/Class/SQLAHacks/MSSQL.pm 2009-12-03 01:48:36 UTC (rev 8015)
@@ -4,30 +4,13 @@
use base qw( DBIx::Class::SQLAHacks );
use Carp::Clan qw/^DBIx::Class|^SQL::Abstract/;
-#
-# MSSQL is retarded wrt TOP (crappy limit) and ordering.
-# One needs to add a TOP to *all* ordered subqueries, if
-# TOP has been used in the statement at least once.
-# Do it here.
-#
-sub select {
- my $self = shift;
-
- my ($sql, @bind) = $self->SUPER::select (@_);
-
- # ordering was requested and there are at least 2 SELECT/FROM pairs
- # (thus subquery), and there is no TOP specified
- if (
- $sql =~ /\bSELECT\b .+? \bFROM\b .+? \bSELECT\b .+? \bFROM\b/isx
- &&
- $sql !~ /^ \s* SELECT \s+ TOP \s+ \d+ /xi
- &&
- scalar $self->_order_by_chunks ($_[3]->{order_by})
- ) {
- $sql =~ s/^ \s* SELECT \s/SELECT TOP 100 PERCENT /xi;
- }
-
- return wantarray ? ($sql, @bind) : $sql;
+sub _RowNumberOver {
+ my $self = shift;
+ my $sql = $self->SUPER::_RowNumberOver(@_);
+ $sql =~ s/(\s*)SELECT\s Q1\.\*,\s ROW_NUMBER\(\)\s OVER\(\s \)\s AS\s ROW_NUM\s
+ FROM\s \(\n(\s*.*)\n\s*(.*)\n\s*\)\s Q1
+ /$1SELECT Q1.*, ROW_NUMBER() OVER($3) AS ROW_NUM FROM (\n$2\n) Q1/ixm;
+ return $sql;
}
1;
Modified: DBIx-Class/0.08/branches/mssql_rno_pagination/lib/DBIx/Class/Storage/DBI/MSSQL.pm
===================================================================
--- DBIx-Class/0.08/branches/mssql_rno_pagination/lib/DBIx/Class/Storage/DBI/MSSQL.pm 2009-12-02 22:52:40 UTC (rev 8014)
+++ DBIx-Class/0.08/branches/mssql_rno_pagination/lib/DBIx/Class/Storage/DBI/MSSQL.pm 2009-12-03 01:48:36 UTC (rev 8015)
@@ -212,7 +212,7 @@
$self->{_sql_maker_opts} = { %$opts };
}
- return { limit_dialect => 'Top', %{$self->{_sql_maker_opts}||{}} };
+ return { limit_dialect => 'RowNumberOver', %{$self->{_sql_maker_opts}||{}} };
}
1;
More information about the Bast-commits
mailing list