From: Matt S Trout Date: Sun, 31 Jul 2011 00:59:56 +0000 (+0000) Subject: clean up IN/BETWEEN handling X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=da159fd92f0e0d2cd5348d7422b07d1ece4c59bc;p=dbsrgits%2FSQL-Abstract.git clean up IN/BETWEEN handling --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index fde45df..f8afdcc 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -709,15 +709,19 @@ sub _where_hashpair_to_dq { # got documented. mst hates everything. if (ref($rhs) eq 'SCALAR') { my $x = $$rhs; - $x = "($x)" unless $x =~ /^\s*\(/; + 1 while ($x =~ s/\A\s*\((.*)\)\s*\Z/$1/s); $rhs = \$x; } else { my ($x, @rest) = @{$$rhs}; - $x = "($x)" unless $x =~ /^\s*\(/; + 1 while ($x =~ s/\A\s*\((.*)\)\s*\Z/$1/s); $rhs = \[ $x, @rest ]; } } - return $self->_literal_with_prepend_to_dq("$k $op", $$rhs); + return +{ + type => DQ_OPERATOR, + operator => { 'SQL.Naive' => $op }, + args => [ $self->_ident_to_dq($k), $self->_literal_to_dq($$rhs) ] + }; } return $self->_literal_to_dq($self->{sqlfalse}) unless @$rhs; return +{ diff --git a/t/05in_between.t b/t/05in_between.t index abc35d6..84bd215 100644 --- a/t/05in_between.t +++ b/t/05in_between.t @@ -134,7 +134,7 @@ my @in_between_tests = ( { parenthesis_significant => 1, where => { x => { -in => \['( ( ?,?,lower(y) ) )', 1, 2] } }, - stmt => "WHERE ( x IN ( ( ?,?,lower(y) ) ) )", # note that outer parens are opened even though literal was requested (RIBASUSHI) + stmt => "WHERE ( x IN ( ?,?,lower(y) ) )", # note that outer parens are opened even though literal was requested (RIBASUSHI) bind => [1, 2], test => '-in with a literal arrayrefref', },