From: Norbert Buchmuller Date: Thu, 13 Nov 2008 06:13:07 +0000 (+0100) Subject: * Made DBIC::SQL::Abstract pass on order_by hashref ({-desc => 'colname'}) to SQL... X-Git-Tag: v0.08240~189^2~32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8682bb0758d4dd03517a8f0e4d0f9dcaf3b9ac44;p=dbsrgits%2FDBIx-Class.git * Made DBIC::SQL::Abstract pass on order_by hashref ({-desc => 'colname'}) to SQL::Abstract. --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 6126b3f..54c79f1 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -156,6 +156,9 @@ sub _order_by { if (defined $_[0]->{order_by}) { $ret .= $self->_order_by($_[0]->{order_by}); } + if (grep { $_ =~ /^-(desc|asc)/i } keys %{$_[0]}) { + return $self->SUPER::_order_by($_[0]); + } } elsif (ref $_[0] eq 'SCALAR') { $ret = $self->_sqlcase(' order by ').${ $_[0] }; } elsif (ref $_[0] eq 'ARRAY' && @{$_[0]}) { diff --git a/t/95sql_maker_quote.t b/t/95sql_maker_quote.t index 626cd49..5dd71a8 100644 --- a/t/95sql_maker_quote.t +++ b/t/95sql_maker_quote.t @@ -9,7 +9,7 @@ BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 7 ); + : ( tests => 8 ); } use lib qw(t/lib); @@ -72,12 +72,19 @@ is_same_sql_bind( ], undef, [ - 'year DESC' + { -desc => 'year' } ], undef, undef ); +is_same_sql_bind( + $sql, \@bind, + q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year` DESC/, [], + 'hashref ORDER BY okay' +); + + ($sql, @bind) = $sql_maker->select( [ {