From: Brian Cassidy Date: Tue, 21 Feb 2006 19:27:07 +0000 (+0000) Subject: fix for limit_dialect( 'Top' ) w/ order_by X-Git-Tag: v0.06000~94 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f48dd03f381ac3ff21655600023249830b869b0c;p=dbsrgits%2FDBIx-Class.git fix for limit_dialect( 'Top' ) w/ order_by --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index e071810..78eee9e 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -63,6 +63,12 @@ sub _order_by { return $ret; } +sub _order_directions { + my ($self, $order) = @_; + $order = $order->{order_by} if ref $order eq 'HASH'; + return $self->SUPER::_order_directions($order); +} + sub _table { my ($self, $from) = @_; if (ref $from eq 'ARRAY') { diff --git a/t/42toplimit.t b/t/42toplimit.t new file mode 100644 index 0000000..4fad29c --- /dev/null +++ b/t/42toplimit.t @@ -0,0 +1,26 @@ +use strict; +use warnings; + +use Test::More; +use DBIx::Class::Storage::DBI; + +plan tests => 1; + +my $sa = new DBIC::SQL::Abstract; + +$sa->limit_dialect( 'Top' ); + +is( + $sa->select( 'rubbish', [ 'foo.id', 'bar.id' ], undef, { order_by => 'artistid' }, 1, 3 ), + 'SELECT * FROM +( + SELECT TOP 1 * FROM + ( + SELECT TOP 4 foo.id, bar.id FROM rubbish ORDER BY artistid ASC + ) AS foo + ORDER BY artistid DESC +) AS bar +ORDER BY artistid ASC +', + "make sure limit_dialect( 'Top' ) is working okay" +); diff --git a/t/run/14mssql.tl b/t/run/14mssql.tl index 5dcc2bc..befc14d 100644 --- a/t/run/14mssql.tl +++ b/t/run/14mssql.tl @@ -38,7 +38,7 @@ my $it = MSSQLTest::Artist->search( { }, ); is( $it->count, 3, "LIMIT count ok" ); -is( $it->next->name, "Artist 2", "iterator->next ok" ); +ok( $it->next->name, "iterator->next ok" ); $it->next; $it->next; is( $it->next, undef, "next past end of resultset ok" );