From: Dagfinn Ilmari Mannsåker Date: Tue, 3 Dec 2013 17:17:29 +0000 (+0000) Subject: Fix NOT IN empty list optimisation X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bdf532008ec6cc1ed4790906da8d19487b1ff624;p=dbsrgits%2FSQL-Abstract.git Fix NOT IN empty list optimisation --- diff --git a/lib/SQL/Abstract/Converter.pm b/lib/SQL/Abstract/Converter.pm index d3cce0a..5dad2b7 100644 --- a/lib/SQL/Abstract/Converter.pm +++ b/lib/SQL/Abstract/Converter.pm @@ -505,7 +505,9 @@ sub _where_hashpair_to_dq { $op, $self->_ident_to_dq($k), $self->_literal_to_dq($$rhs) ); } - return $self->_literal_to_dq($self->{sqlfalse}) unless @$rhs; + return $self->_literal_to_dq( + $op =~ /^NOT/ ? $self->{sqltrue} : $self->{sqlfalse} + ) unless @$rhs; return $self->_op_to_dq( $op, $self->_ident_to_dq($k), map $self->_expr_to_dq($_), @$rhs ) diff --git a/t/01generate.t b/t/01generate.t index 62047c6..df83661 100644 --- a/t/01generate.t +++ b/t/01generate.t @@ -545,6 +545,13 @@ my @tests = ( stmt_q => 'SELECT * FROM `test` WHERE ( `Y` = ( MAX( LENGTH( MIN ? ) ) ) )', bind => [[Y => 'x']], }, + { + 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 => [], + }, ); for my $t (@tests) {