X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FAbstract.pm;h=4609e5dd75129a7c70a93ba41b9f3ade4c2e01d5;hb=3af02ccb064ba561a4e7b0f6638df2ecc3df8b81;hp=f33e75fb8e8a737a0fbcc41f68b88b5e61de70dc;hpb=521647e7e01af89d2deda6724bd76cb399c0bfff;p=dbsrgits%2FSQL-Abstract.git diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index f33e75f..4609e5d 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -15,7 +15,7 @@ use Scalar::Util (); # GLOBALS #====================================================================== -our $VERSION = '1.73'; +our $VERSION = '1.74'; # This would confuse some packagers $VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases @@ -86,7 +86,7 @@ sub new { # default comparison is "=", but can be overridden $opt{cmp} ||= '='; - # try to recognize which are the 'equality' and 'unequality' ops + # try to recognize which are the 'equality' and 'inequality' ops # (temporary quickfix, should go through a more seasoned API) $opt{equality_op} = qr/^(\Q$opt{cmp}\E|is|(is\s+)?like)$/i; $opt{inequality_op} = qr/^(!=|<>|(is\s+)?not(\s+like)?)$/i; @@ -104,7 +104,7 @@ sub new { $opt{unary_ops} ||= []; push @{$opt{unary_ops}}, @BUILTIN_UNARY_OPS; - # rudimentary saniy-check for user supplied bits treated as functions/operators + # rudimentary sanity-check for user supplied bits treated as functions/operators # If a purported function matches this regular expression, an exception is thrown. # Literal SQL is *NOT* subject to this check, only functions (and column names # when quoting is not in effect) @@ -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]; } @@ -1709,7 +1699,7 @@ C to C you would get SQL such as: WHERE name like 'nwiger' AND email like 'nate@wiger.org' -You can also override the comparsion on an individual basis - see +You can also override the comparison on an individual basis - see the huge section on L at the bottom. =item sqltrue, sqlfalse @@ -2441,7 +2431,7 @@ Note that if you were to simply say: array => [1, 2, 3] ); -the result would porbably be not what you wanted: +the result would probably not be what you wanted: $stmt = 'WHERE array = ? OR array = ? OR array = ?'; @bind = (1, 2, 3); @@ -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