From: Dagfinn Ilmari Mannsåker Date: Sun, 14 Apr 2013 10:53:32 +0000 (+0100) Subject: Revert "Add support for NULLS FIRST/LAST in ORDER BY" X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5e4361304e44378efe29ad97c4430cd5f5c0f1ba;p=scpubgit%2FQ-Branch.git Revert "Add support for NULLS FIRST/LAST in ORDER BY" Despite being an ISO/ANSI SQL feature, it's apparently not supported by enough databses to have by default. This reverts commits 2266ca5c0bf34c24ba7fbf6448ad1c34a082f240 and b137b0744a3aaea3df1ba497345378e9d3f8da40. --- diff --git a/Changes b/Changes index 7c5a4a8..40e994f 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,5 @@ Revision history for SQL::Abstract - - Add support for NULLS FIRST/LAST in ORDER BY - Fix insufficient parenthesis unroll during operator comparison revision 1.73 2012-07-10 diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index f33e75f..c877a4d 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -1150,24 +1150,16 @@ sub _order_by_chunks { SCALARREF => sub {$$arg}, # literal SQL, no quoting HASHREF => sub { - return () unless %$arg; - - my ($direction, $nulls, $val); - foreach my $key (keys %$arg) { - if ( $key =~ /^-(desc|asc)/i ) { - puke "hash passed to _order_by must have exactly one of -desc or -asc" - if defined $direction; - $direction = $1; - $val = $arg->{$key}; - } elsif ($key =~ /^-nulls$/i) { - $nulls = $arg->{$key}; - puke "invalid value for -nulls" unless $nulls =~ /^(?:first|last)$/i; - } else { - puke "invalid key in hash passed to _order_by"; - } + # get first pair in hash + my ($key, $val, @rest) = %$arg; + + return () unless $key; + + if ( @rest or not $key =~ /^-(desc|asc)/i ) { + puke "hash passed to _order_by must have exactly one key (-desc or -asc)"; } - puke "hash passed to _order_by must have exactly one of -desc or -asc" - unless defined $direction; + + my $direction = $1; my @ret; for my $c ($self->_order_by_chunks ($val)) { @@ -1182,9 +1174,7 @@ sub _order_by_chunks { }, }); - $sql .= ' ' . $self->_sqlcase($direction); - $sql .= ' ' . $self->_sqlcase("nulls $nulls") - if defined $nulls; + $sql = $sql . ' ' . $self->_sqlcase($direction); push @ret, [ $sql, @bind]; } @@ -2631,7 +2621,6 @@ script. Some functions take an order by clause. This can either be a scalar (just a column name,) a hash of C<< { -desc => 'col' } >> or C<< { -asc => 'col' } >>, -optionally with C<< -nulls => 'first' >> or C<< -nulls => 'last' >>, or an array of either of the two previous forms. Examples: Given | Will Generate @@ -2647,20 +2636,10 @@ or an array of either of the two previous forms. Examples: | {-desc => 'colB'} | ORDER BY colB DESC | - { | - -asc => 'colA', | ORDER BY colA ASC NULLS LAST - -nulls => 'last', | - } | - | ['colA', {-asc => 'colB'}] | ORDER BY colA, colB ASC | { -asc => [qw/colA colB/] } | ORDER BY colA ASC, colB ASC | - { | - -asc => [qw/colA colB/] | ORDER BY colA ASC NULLS FIRST, - -nulls => 'first' | colB ASC NULLS FIRST - } | - | [ | { -asc => 'colA' }, | ORDER BY colA ASC, colB DESC, { -desc => [qw/colB/], | colC ASC, colD ASC diff --git a/t/06order_by.t b/t/06order_by.t index d924569..3a29b3d 100644 --- a/t/06order_by.t +++ b/t/06order_by.t @@ -104,25 +104,10 @@ my @cases = expects_quoted => ' ORDER BY colA ASC, colB LIKE ? DESC, colC LIKE ? ASC', bind => [qw/test tost/], }, - { - given => [ { -ASC => 'colA', -NULLS => 'FIRST' }, { -DESC => 'colB', -NULLS => 'LAST' } ], - expects => ' ORDER BY colA ASC NULLS FIRST, colB DESC NULLS LAST', - expects_quoted => ' ORDER BY `colA` ASC NULLS FIRST, `colB` DESC NULLS LAST', - }, - { - given => [ { -asc => 'colA', -nulls => 'first' }, { -desc => 'colB', -nulls => 'last' } ], - expects => ' ORDER BY colA ASC NULLS FIRST, colB DESC NULLS LAST', - expects_quoted => ' ORDER BY `colA` ASC NULLS FIRST, `colB` DESC NULLS LAST', - }, - { - given => { -asc => [qw/colA colB/], -nulls => 'first' } , - expects => ' ORDER BY colA ASC NULLS FIRST, colB ASC NULLS FIRST', - expects_quoted => ' ORDER BY `colA` ASC NULLS FIRST, `colB` ASC NULLS FIRST', - }, ); -plan tests => (scalar(@cases) * 2) + 4; +plan tests => (scalar(@cases) * 2) + 2; my $sql = SQL::Abstract->new; my $sqlq = SQL::Abstract->new({quote_char => '`'}); @@ -149,24 +134,12 @@ for my $case( @cases) { throws_ok ( sub { $sql->_order_by({-desc => 'colA', -asc => 'colB' }) }, - qr/hash passed .+ must have exactly one of/, + qr/hash passed .+ must have exactly one key/, 'Undeterministic order exception', ); throws_ok ( sub { $sql->_order_by({-desc => [ qw/colA colB/ ], -asc => [ qw/colC colD/ ] }) }, - qr/hash passed .+ must have exactly one of/, + qr/hash passed .+ must have exactly one key/, 'Undeterministic order exception', ); - -throws_ok( - sub { $sql->_order_by({-wibble => "fleem" }) }, - qr/invalid key in hash/, - 'Invalid order exception', -); - -throws_ok( - sub { $sql->_order_by({-nulls => "fleem" }) }, - qr/invalid value for -nulls/, - 'Invalid nulls exception', -);