X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FAbstract%2FAST%2Fv1.pm;fp=lib%2FSQL%2FAbstract%2FAST%2Fv1.pm;h=1d49094beb231f3defea3d1991969c823ae3f2c9;hb=fc20481d8eb907b00a9ab2fe3fc9f3e79da87dd3;hp=54b41721516141ce7ce2589a094b3e47e76e169b;hpb=d4656fcf868ce52c9689c1036628e04993eb5e59;p=dbsrgits%2FSQL-Abstract-2.0-ish.git diff --git a/lib/SQL/Abstract/AST/v1.pm b/lib/SQL/Abstract/AST/v1.pm index 54b4172..1d49094 100644 --- a/lib/SQL/Abstract/AST/v1.pm +++ b/lib/SQL/Abstract/AST/v1.pm @@ -86,6 +86,37 @@ class SQL::Abstract::AST::v1 extends SQL::Abstract { 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 columns doesn\'t match values: ' . dump($ast) + if @{$ast->{columns}} != @{$ast->{values}}; + + $DB::single = 1; + 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); }