From: Matt S Trout Date: Mon, 1 Apr 2019 01:52:15 +0000 (+0000) Subject: make -is work at top level X-Git-Tag: v2.000000~3^2~300 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=43779415b61fa06ddb068940ea6c407f98da65d6;p=dbsrgits%2FSQL-Abstract.git make -is work at top level --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 0f524ff..6973f21 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -215,6 +215,7 @@ sub new { my ($op, @opargs) = @$args; +{ $node => [ $op, map $self->expand_expr($_), @opargs ] }; }, + (map +($_ => '_expand_op_is'), ('-is', '-is_not')), }; $opt{expand_op} = { @@ -977,6 +978,8 @@ sub _expand_op_andor { sub _expand_op_is { my ($self, $op, $vv, $k) = @_; + $op =~ s/^-//; + ($k, $vv) = @$vv unless defined $k; puke "$op can only take undef as argument" if defined($vv) and not ( @@ -984,7 +987,7 @@ sub _expand_op_is { and exists($vv->{-value}) and !defined($vv->{-value}) ); - return +{ -op => [ $op.'_null', $self->_expand_ident(-ident => $k) ] }; + return +{ -op => [ $op.'_null', $self->expand_expr($k, -ident) ] }; } sub _expand_between { diff --git a/t/05in_between.t b/t/05in_between.t index bb98f11..a3e7656 100644 --- a/t/05in_between.t +++ b/t/05in_between.t @@ -317,7 +317,13 @@ my @in_between_tests = ( }, stmt => ' WHERE (x, y) IN ((?, ?), (?, ?))', bind => [ 1..4 ], - test => 'Complex IN', + test => 'Complex top-level -in', + }, + { + where => { -is => [ 'bob', undef ] }, + stmt => ' WHERE bob IS NULL', + bind => [], + test => 'Top level -is ok', }, );