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;