From: Justin Hunter Date: Fri, 24 Apr 2009 18:47:06 +0000 (+0000) Subject: add support for order_by => [qw/colA colB/] X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=994edb7789cfc682a88a3054143786ef7fe38926;p=scpubgit%2FQ-Branch.git add support for order_by => [qw/colA colB/] --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index e93bca7..32481f4 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -829,7 +829,8 @@ sub _order_by_hash { my ($order) = ($key =~ /^-(desc|asc)/i) or puke "invalid key in _order_by hash : $key"; - return $self->_quote($val) ." ". $self->_sqlcase($order); + $val = ref $val eq 'ARRAY' ? $val : [$val]; + return join ', ', map { $self->_quote($_) . ' ' . $self->_sqlcase($order) } @$val; } @@ -2097,6 +2098,9 @@ or an array of either of the two previous forms. Examples: {-desc => 'colB'} | ] | [colA => {-asc => 'colB'}] | ORDER BY colA, colB ASC + { -asc => [qw/colA colB] } | ORDER BY colA ASC, colB ASC + { -asc => [qw/colA colB] },| + -desc => [qw/colC colD] } | ORDER BY colA ASC, colB ASC, colC DESC, colD DESC ========================================================== diff --git a/t/06order_by.t b/t/06order_by.t index 440517f..d404aa3 100644 --- a/t/06order_by.t +++ b/t/06order_by.t @@ -59,6 +59,28 @@ my @cases = expects => '', expects_quoted => '', }, + + { + given => [{-desc => [ qw/colA colB/ ] }], + expects => ' ORDER BY colA DESC, colB DESC', + expects_quoted => ' ORDER BY `colA` DESC, `colB` DESC', + }, + { + given => [{-desc => [ qw/colA colB/ ] }, {-asc => 'colC'}], + expects => ' ORDER BY colA DESC, colB DESC, colC ASC', + expects_quoted => ' ORDER BY `colA` DESC, `colB` DESC, `colC` ASC', + }, + { + given => [{-desc => [ qw/colA colB/ ] }, {-asc => [ qw/colC colD/ ] }], + expects => ' ORDER BY colA DESC, colB DESC, colC ASC, colD ASC', + expects_quoted => ' ORDER BY `colA` DESC, `colB` DESC, `colC` ASC, `colD` ASC', + }, + { + given => [{-desc => [ qw/colA colB/ ] }, {-desc => 'colC' }], + expects => ' ORDER BY colA DESC, colB DESC, colC DESC', + expects_quoted => ' ORDER BY `colA` DESC, `colB` DESC, `colC` DESC', + }, + );