X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FAbstract.pm;h=fcee0f9fbc7061b6385eb47021f90fd235d0ab70;hb=8a0d798a7a265eec82275bb0b67e620bb85d27ab;hp=46d2a4fe282ecea90709c381e8d5b6bd41a2c5bd;hpb=3e74bc77f2e6e0758218c579c6aa71b85c834c1a;p=scpubgit%2FQ-Branch.git diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 46d2a4f..fcee0f9 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -697,25 +697,36 @@ sub _where_field_IN { # backwards compatibility : if scalar, force into an arrayref $vals = [$vals] if defined $vals && ! ref $vals; - ref $vals eq 'ARRAY' - or puke "special op 'in' requires an arrayref"; - my ($label) = $self->_convert($self->_quote($k)); my ($placeholder) = $self->_convert('?'); - my $and = $self->_sqlcase('and'); $op = $self->_sqlcase($op); - if (@$vals) { # nonempty list - my $placeholders = join ", ", (($placeholder) x @$vals); - my $sql = "$label $op ( $placeholders )"; - my @bind = $self->_bindtype($k, @$vals); + my ($sql, @bind) = $self->_SWITCH_refkind($vals, { + ARRAYREF => sub { # list of choices + if (@$vals) { # nonempty list + my $placeholders = join ", ", (($placeholder) x @$vals); + my $sql = "$label $op ( $placeholders )"; + my @bind = $self->_bindtype($k, @$vals); - return ($sql, @bind); - } - else { # empty list : some databases won't understand "IN ()", so DWIM - my $sql = ($op =~ /\bnot\b/i) ? $self->{sqltrue} : $self->{sqlfalse}; - return ($sql); - } + return ($sql, @bind); + } + else { # empty list : some databases won't understand "IN ()", so DWIM + my $sql = ($op =~ /\bnot\b/i) ? $self->{sqltrue} : $self->{sqlfalse}; + return ($sql); + } + }, + + ARRAYREFREF => sub { # literal SQL with bind + my ($sql, @bind) = @$$vals; + return ("$label $op ( $sql )", @bind); + }, + + FALLBACK => sub { + puke "special op 'in' requires an arrayref (or arrayref-ref)"; + }, + }); + + return ($sql, @bind); }