use SQL::Abstract::Types qw/AST/;
use Devel::PartialDump qw/dump/;
- clean;
-
# set things that are valid in where clauses
override _build_expr_dispatch_table {
return {
return join(' ', @output);
}
+ method _update(AST $ast) {
+
+ for (qw/columns values tablespec/) {
+ confess "'$_' is required in update AST with " . dump ($ast)
+ unless exists $ast->{$_};
+ }
+
+ my $table = $ast->{tablespec};
+ confess 'update: tablespec must be an ident or an alias in ' . dump($ast)
+ unless $table->{-type} =~ /^identifier|alias$/;
+
+ my @output = (
+ 'UPDATE',
+ $self->dispatch($table),
+ 'SET'
+ );
+
+ confess 'update: Number of values does not match columns: ' . dump($ast)
+ if @{$ast->{columns}} != @{$ast->{values}};
+
+ my $list = {
+ -type => 'list',
+ args => [ map {
+ { -type => 'expr',
+ op => '==', # This should really be '=' but hmmmmmmmm
+ args => [
+ $ast->{columns}[$_],
+ $ast->{values}[$_]
+ ]
+ }
+ } 0..$#{$ast->{columns}} ]
+ };
+
+ push @output, $self->dispatch($list);
+
+ return join(' ', @output);
+
+ }
+
method _join(HashRef $ast) {
# TODO: Validate join type