From: Peter Rabbitson Date: Thu, 29 Mar 2012 02:53:28 +0000 (+0200) Subject: Fix bind order in RNO limits when there are both select and order bindvals X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ebc5c60a4ff45bb9ab7630e2512015b3b7cb2c96;p=dbsrgits%2FDBIx-Class-Historic.git Fix bind order in RNO limits when there are both select and order bindvals --- diff --git a/lib/DBIx/Class/SQLMaker/LimitDialects.pm b/lib/DBIx/Class/SQLMaker/LimitDialects.pm index c67c22b..e9a1c87 100644 --- a/lib/DBIx/Class/SQLMaker/LimitDialects.pm +++ b/lib/DBIx/Class/SQLMaker/LimitDialects.pm @@ -100,7 +100,11 @@ sub _RowNumberOver { # make up an order if none exists my $requested_order = (delete $rs_attrs->{order_by}) || $self->_rno_default_order; + + # the order binds (if any) will need to go at the end of the entire inner select + local $self->{order_bind}; my $rno_ord = $self->_order_by ($requested_order); + push @{$self->{select_bind}}, @{$self->{order_bind}}; # this is the order supplement magic my $mid_sel = $sq_attrs->{selection_outer}; diff --git a/t/746mssql.t b/t/746mssql.t index 611d9e0..c494be8 100644 --- a/t/746mssql.t +++ b/t/746mssql.t @@ -373,15 +373,20 @@ SQL ); my ($sql, @bind) = @${$owners->page(3)->as_query}; + # not testing the SQL as it is quite different between top/rno is_same_bind ( \@bind, [ - ($dialect eq 'Top' ? [ { dbic_colname => 'test' } => 'xxx' ] : ()), # the extra re-order bind - [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'me.name' } - => 'somebogusstring' ], [ { dbic_colname => 'test' } => 'xxx' ], - ($dialect ne 'Top' ? ( [ $OFFSET => 7 ], [ $TOTAL => 9 ] ) : ()), # parameterised RNO + [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'me.name' } + => 'somebogusstring' ], + + ($dialect eq 'Top' + ? [ { dbic_colname => 'test' } => 'xxx' ] # the extra re-order bind + : ([ $OFFSET => 7 ], [ $TOTAL => 9 ]) # parameterised RNO + ), + [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'me.name' } => 'somebogusstring' ], [ { dbic_colname => 'test' } @@ -417,6 +422,7 @@ SQL ); ($sql, @bind) = @${$books->page(3)->as_query}; + # not testing the SQL as it is quite different between top/rno is_same_bind ( \@bind, [