X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FAbstract.pm;h=32481f425de3654fe4b5de60e1abe6b7d62caef9;hb=994edb7789cfc682a88a3054143786ef7fe38926;hp=24a1c8763ad4db85e24bc4a5139ea17d87d24c3e;hpb=eb49170d9524af0a98dbe02cba213d82be6f0cc3;p=scpubgit%2FQ-Branch.git diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 24a1c87..32481f4 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -63,7 +63,7 @@ sub new { delete $opt{case} if $opt{case} && $opt{case} ne 'lower'; # default logic for interpreting arrayrefs - $opt{logic} = uc $opt{logic} || 'OR'; + $opt{logic} = $opt{logic} ? uc $opt{logic} : 'OR'; # how to return bind vars # LDNOTE: changed nwiger code : why this 'delete' ?? @@ -703,16 +703,39 @@ sub _where_UNDEF { sub _where_field_BETWEEN { my ($self, $k, $op, $vals) = @_; - ref $vals eq 'ARRAY' && @$vals == 2 - or puke "special op 'between' requires an arrayref of two values"; + (ref $vals eq 'ARRAY' && @$vals == 2) or + (ref $vals eq 'REF' && (@$$vals == 1 || @$$vals == 2 || @$$vals == 3)) + or puke "special op 'between' requires an arrayref of two values (or a scalarref or arrayrefref for literal SQL)"; - my ($label) = $self->_convert($self->_quote($k)); - my ($placeholder) = $self->_convert('?'); - my $and = $self->_sqlcase('and'); + my ($clause, @bind, $label, $and, $placeholder); + $label = $self->_convert($self->_quote($k)); + $and = ' ' . $self->_sqlcase('and') . ' '; + $placeholder = $self->_convert('?'); $op = $self->_sqlcase($op); - my $sql = "( $label $op $placeholder $and $placeholder )"; - my @bind = $self->_bindtype($k, @$vals); + if (ref $vals eq 'REF') { + ($clause, @bind) = @$$vals; + } + else { + my (@all_sql, @all_bind); + + foreach my $val (@$vals) { + my ($sql, @bind) = $self->_SWITCH_refkind($val, { + SCALAR => sub { + return ($placeholder, ($val)); + }, + SCALARREF => sub { + return ($self->_convert($$val), ()); + }, + }); + push @all_sql, $sql; + push @all_bind, @bind; + } + + $clause = (join $and, @all_sql); + @bind = $self->_bindtype($k, @all_bind); + } + my $sql = "( $label $op $clause )"; return ($sql, @bind) } @@ -806,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; } @@ -2074,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 ==========================================================