From: Peter Rabbitson Date: Tue, 15 Dec 2009 23:38:04 +0000 (+0000) Subject: Do not realias tables in the RNO subqueries X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1f36ab6755c16cae2d4c3d0099d68cd11948f0ff;p=dbsrgits%2FDBIx-Class-Historic.git Do not realias tables in the RNO subqueries --- diff --git a/lib/DBIx/Class/SQLAHacks.pm b/lib/DBIx/Class/SQLAHacks.pm index 02c336c..ac3ae4a 100644 --- a/lib/DBIx/Class/SQLAHacks.pm +++ b/lib/DBIx/Class/SQLAHacks.pm @@ -59,10 +59,12 @@ sub _RowNumberOver { # whatever is left my $group_having = $self->_order_by($order); - $sql = sprintf (<<'EOS', $order_by, $sql, $group_having, $offset + 1, $offset + $rows, ); + my $qalias = $self->_quote ($self->{_dbic_rs_attrs}{alias}); + + $sql = sprintf (<<'EOS', $qalias, $order_by, $sql, $group_having, $qalias, $offset + 1, $offset + $rows, ); SELECT * FROM ( - SELECT orig_query.*, ROW_NUMBER() OVER(%s ) AS rno__row__index FROM (%s%s) orig_query + SELECT %s.*, ROW_NUMBER() OVER(%s ) AS rno__row__index FROM (%s%s) %s ) rno_subq WHERE rno__row__index BETWEEN %d AND %d EOS diff --git a/t/746mssql.t b/t/746mssql.t index 9fa63c7..88a6f7d 100644 --- a/t/746mssql.t +++ b/t/746mssql.t @@ -417,7 +417,7 @@ Alan's SQL: FROM ( SELECT * FROM ( - SELECT orig_query.*, ROW_NUMBER() OVER( ORDER BY (SELECT(1)) ) AS rno__row__index + SELECT [me].*, ROW_NUMBER() OVER( ORDER BY (SELECT(1)) ) AS rno__row__index FROM ( SELECT [me].[id], [me].[source], [me].[owner], [me].[title], [me].[price] FROM ( @@ -427,7 +427,7 @@ Alan's SQL: WHERE ( ( [owner].[name] != ? AND [source] = ? ) ) ORDER BY [owner].[name] DESC ) [me] - ) orig_query + ) [me] ) rno_subq WHERE rno__row__index BETWEEN 3 AND 9 ) [me]