Start working on update clause
[dbsrgits/SQL-Abstract-2.0-ish.git] / lib / SQL / Abstract / AST / v1.pm
index 0543330..54b4172 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
@@ -80,6 +80,15 @@ class SQL::Abstract::AST::v1 extends SQL::Abstract {
     return join(' ', @output);
   }
 
+  method _update(AST $ast) {
+
+    for (qw/columns values tablespec/) {
+      confess "'$_' is required in update AST with " . dump ($ast)
+        unless exists $ast->{$_};
+    }
+    
+  }
+
   method _join(HashRef $ast) {
 
     # TODO: Validate join type
@@ -116,10 +125,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 +255,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)