From: Dagfinn Ilmari Mannsåker Date: Wed, 4 Dec 2013 13:47:20 +0000 (+0000) Subject: Allow { -in => $scalar } X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=023fd01d349c966cfffe9c1db99cd57ad5a32860;p=dbsrgits%2FSQL-Abstract.git Allow { -in => $scalar } Although undocumented, the old version will accept and DWIM for this, so follow suit. --- diff --git a/lib/SQL/Abstract/Converter.pm b/lib/SQL/Abstract/Converter.pm index 5dad2b7..ec12707 100644 --- a/lib/SQL/Abstract/Converter.pm +++ b/lib/SQL/Abstract/Converter.pm @@ -483,6 +483,7 @@ sub _where_hashpair_to_dq { } }; if ($op eq 'BETWEEN' or $op eq 'IN' or $op eq 'NOT IN' or $op eq 'NOT BETWEEN') { + $rhs = [$rhs] unless ref $rhs; if (ref($rhs) ne 'ARRAY') { if ($op =~ /IN$/) { # have to add parens if none present because -in => \"SELECT ..." diff --git a/t/01generate.t b/t/01generate.t index df83661..91e51bb 100644 --- a/t/01generate.t +++ b/t/01generate.t @@ -547,10 +547,10 @@ my @tests = ( }, { func => 'select', - args => ['test', '*', { a => { -in => [] }, b => { -not_in => [] } }], - stmt => 'SELECT * FROM test WHERE ( 0=1 AND 1=1 )', - stmt_q => 'SELECT * FROM `test` WHERE ( 0=1 AND 1=1 )', - bind => [], + args => ['test', '*', { a => { -in => [] }, b => { -not_in => [] }, c => { -in => 42 } }], + stmt => 'SELECT * FROM test WHERE ( 0=1 AND 1=1 AND c IN ( ? ))', + stmt_q => 'SELECT * FROM `test` WHERE ( 0=1 AND 1=1 AND `c` IN ( ? ))', + bind => [ 42 ], }, );