From: Ash Berlin Date: Fri, 1 May 2009 21:50:53 +0000 (+0100) Subject: Basic AST compat for update X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=946503a6fcccde2029657cb6b1a4c2b976a6ff50;p=dbsrgits%2FSQL-Abstract-2.0-ish.git Basic AST compat for update --- diff --git a/lib/SQL/Abstract/Compat.pm b/lib/SQL/Abstract/Compat.pm index af08032..5045664 100644 --- a/lib/SQL/Abstract/Compat.pm +++ b/lib/SQL/Abstract/Compat.pm @@ -94,7 +94,20 @@ class SQL::Abstract::Compat { method update_ast(Str|ArrayRef|ScalarRef $from, HashRef $fields, WhereType $where? ) { - return { -type => 'update' }; + my (@columns, @values); + my $ast = { + -type => 'update', + tablespec => $self->tablespec($from), + columns => \@columns, + values => \@values + }; + + for (keys %$fields) { + push @columns, $self->mk_name(0, $_); + push @values, { -type => 'value', value => $fields->{$_} }; + } + + return $ast; } method select_ast(Str|ArrayRef|ScalarRef $from, ArrayRef|Str $fields, diff --git a/t/compat/ast/02update.t b/t/compat/ast/02update.t index d55e7fd..0b68b14 100644 --- a/t/compat/ast/02update.t +++ b/t/compat/ast/02update.t @@ -25,12 +25,16 @@ my $bar_id = { -type => 'identifier', elements => [qw/bar/] }; my $foo_eq_1 = field_op_value($foo_id, '==', 1); my $bar_eq_str = field_op_value($bar_id, '==', 'some str'); -local $TODO = 'Work out what this should be'; eq_or_diff $visitor->update_ast('test', { foo => 1 }), { -type => 'update', tablespec => mk_name('test'), - + columns => [ + mk_name('foo') + ], + values => [ + mk_value(1) + ] }, "simple update";