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
--- /dev/null
+use strict;
+use warnings;
+
+use Test::More tests => 5;
+use Test::Differences;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+use Test::SQL::Abstract::Util qw/
+ mk_name
+ mk_value
+ mk_alias
+ :dumper_sort
+/;
+
+use_ok('SQL::Abstract') or BAIL_OUT( "$@" );
+
+my $sqla = SQL::Abstract->create(1);
+
+is $sqla->dispatch(
+ { -type => 'update',
+ tablespec => mk_name('test'),
+ columns => [
+ mk_name(qw/me id/),
+ mk_name(qw/hostname/),
+ ],
+ values => [
+ mk_expr('+', mk_name(qw/me id/), mk_value(5)),
+ mk_value('localhost'),
+ ]
+ }
+), "UPDATE test SET me.id = me.id + 5, hostnameme = localhost"
+ "update clause";
use strict;
use warnings;
-use Test::More tests => 5;
+use Test::More tests => 6;
use Test::Exception;
+use FindBin;
+use lib "$FindBin::Bin/lib";
+use Test::SQL::Abstract::Util qw/
+ mk_name
+ mk_value
+ mk_alias
+/;
+
use_ok('SQL::Abstract') or BAIL_OUT( "$@" );
my $sqla = SQL::Abstract->create(1);
)
} qr/^'~' is not a valid operator in an expression/;
+{
local $TODO = "Work out how to get nice errors for these";
throws_ok {
)
} qr/foobar/, "alias: iden instead of ident";
+}
+
+throws_ok {
+ $sqla->dispatch(
+ { -type => 'update',
+ tablespec => mk_name('test'),
+ columns => [
+ mk_name(qw/me id/),
+ mk_alias(mk_name(qw/foo id/) ,'foo_id')
+ ]
+ }
+ )
+} qr/^'values' is required in update AST/, "Invalid clause in update"
use Test::SQL::Abstract::Util qw/
mk_name
mk_value
+ mk_expr
field_op_value
:dumper_sort
/;
"Complex AST [ {a => [1,2],b => 3}, { c => 4 }, { d => [5,6,7], e => { '!=' => [8,9] }, q => {'not in' => [10,11] } } ]";
-sub upper { expr(UPPER => @_) }
+sub upper { mk_expr(UPPER => @_) }
-sub expr {
- my ($op, @args) = @_;
-
- return {
- -type => 'expr',
- op => $op,
- args => [@args]
- };
-}
mk_name
mk_value
mk_alias
+ mk_expr
field_op_value
/],
groups => [
return { -type => 'value', value => $_[0] }
}
+sub mk_expr {
+ my ($op, @args) = @_;
+
+ return {
+ -type => 'expr',
+ op => $op,
+ args => [@args]
+ };
+}
sub field_op_value {
my ($field, $op, $value) = @_;