From: Arthur Axel "fREW" Schmidt Date: Thu, 3 Dec 2009 14:56:35 +0000 (+0000) Subject: fix RNO for MSSQL to not use a kludgy regexp X-Git-Tag: v0.08116~103^2~23 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=584d2dd1ac98a4e46496006b0a655b6e5c5e7ac9;p=dbsrgits%2FDBIx-Class.git fix RNO for MSSQL to not use a kludgy regexp --- diff --git a/lib/DBIx/Class/SQLAHacks/MSSQL.pm b/lib/DBIx/Class/SQLAHacks/MSSQL.pm index 6110c8d..70cc8c3 100644 --- a/lib/DBIx/Class/SQLAHacks/MSSQL.pm +++ b/lib/DBIx/Class/SQLAHacks/MSSQL.pm @@ -5,12 +5,24 @@ use base qw( DBIx::Class::SQLAHacks ); use Carp::Clan qw/^DBIx::Class|^SQL::Abstract/; 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; + my ($self, $sql, $order, $rows, $offset ) = @_; + + $offset += 1; + my $last = $rows + $offset - 1; + my ( $order_by ) = $self->_order_by( $order ); + + $sql = <<"SQL"; +SELECT * FROM +( + SELECT Q1.*, ROW_NUMBER() OVER( $order_by ) AS ROW_NUM FROM ( + $sql + ) Q1 +) Q2 +WHERE ROW_NUM BETWEEN $offset AND $last + +SQL + + return $sql; } 1;