Chage {-type => 'name', args => [] } to {-type => 'identifier', elements => [] }
[dbsrgits/SQL-Abstract-2.0-ish.git] / lib / SQL / Abstract / AST / v1.pm
index 0543330..a87fc5c 100644 (file)
@@ -25,7 +25,7 @@ class SQL::Abstract::AST::v1 extends SQL::Abstract {
       or => $self->can('_recurse_where'),
       map { +"$_" => $self->can("_$_") } qw/
         value
-        name
+        identifier
         true
         false
         expr
@@ -116,10 +116,10 @@ class SQL::Abstract::AST::v1 extends SQL::Abstract {
     return $output;
   }
 
-  method _name(AST $ast) {
-    my @names = @{$ast->{args}};
+  method _identifier(AST $ast) {
+    my @names = @{$ast->{elements}};
 
-    my $sep = $self->name_separator;
+    my $sep = $self->ident_separator;
     my $quote = $self->is_quoting 
               ? $self->quote_chars
               : [ '' ];
@@ -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)