From: Ash Berlin Date: Sat, 4 Apr 2009 18:33:00 +0000 (+0100) Subject: IS NOT? NULL support X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ec376489c337a428477e4b26c554e5f28586bfd4;p=dbsrgits%2FSQL-Abstract-2.0-ish.git IS NOT? NULL support --- diff --git a/lib/SQL/Abstract/AST/v1.pm b/lib/SQL/Abstract/AST/v1.pm index 0543330..e27584b 100644 --- a/lib/SQL/Abstract/AST/v1.pm +++ b/lib/SQL/Abstract/AST/v1.pm @@ -246,6 +246,15 @@ class SQL::Abstract::AST::v1 extends SQL::Abstract { my ($lhs, $rhs) = @{$ast->{args}}; my $op = $ast->{op}; + # IS NOT? NULL + if ($rhs->{-type} eq 'value' && !defined $rhs->{value} && + ($op eq '==' || $op eq '!=')) + { + return $self->_expr($lhs) . + ($op eq '==' ? " IS " : " IS NOT ") . + "NULL"; + } + join (' ', $self->_expr($lhs), $self->binop_mapping($op) || croak("Unknown binary operator $op"), $self->_expr($rhs) diff --git a/t/100_expr_basic.t b/t/100_expr_basic.t index 0bcdaa4..9e1b014 100644 --- a/t/100_expr_basic.t +++ b/t/100_expr_basic.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 14; +use Test::More tests => 16; use Test::Differences; use_ok('SQL::Abstract') or BAIL_OUT( "$@" ); @@ -190,3 +190,27 @@ is $sqla->dispatch( } ), "me.id LIKE ?", "LIKE expr clause"; + + +is $sqla->dispatch( + { -type => 'expr', + op => '==', + args => [ + {-type => name => args => [qw/me id/] }, + { -type => 'value', value => undef } + ] + } +), "me.id IS NULL", + "== undef"; + + +is $sqla->dispatch( + { -type => 'expr', + op => '!=', + args => [ + {-type => name => args => [qw/me id/] }, + { -type => 'value', value => undef } + ] + } +), "me.id IS NOT NULL", + "!= undef";