From: Ash Berlin Date: Sat, 4 Apr 2009 23:35:39 +0000 (+0100) Subject: Update clases test+functionality X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fc20481d8eb907b00a9ab2fe3fc9f3e79da87dd3;p=dbsrgits%2FSQL-Abstract-2.0-ish.git Update clases test+functionality --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 0379c16..26b3ce1 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -24,6 +24,12 @@ class SQL::Abstract { ); our %BINOP_MAP = ( + + '+' => '+', + '-' => '-', + '/' => '/', + '*' => '*', + '>' => '>', '>=' => '>=', '<' => '<', 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); } diff --git a/t/202_update.t b/t/202_update.t index f6544bc..8125098 100644 --- a/t/202_update.t +++ b/t/202_update.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 5; +use Test::More tests => 2; use Test::Differences; use FindBin; @@ -10,6 +10,7 @@ use Test::SQL::Abstract::Util qw/ mk_name mk_value mk_alias + mk_expr :dumper_sort /; @@ -29,5 +30,5 @@ is $sqla->dispatch( mk_value('localhost'), ] } -), "UPDATE test SET me.id = me.id + 5, hostnameme = localhost" +), "UPDATE test SET me.id = me.id + ?, hostname = ?", "update clause";