From: Ash Berlin Date: Fri, 6 Mar 2009 21:49:05 +0000 (+0000) Subject: Start producing join stmts X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=704c513833ed286daebbf137fa170fe29eb60ca5;p=dbsrgits%2FSQL-Abstract-2.0-ish.git Start producing join stmts --- diff --git a/.gitignore b/.gitignore index 53d9ffc..38677d1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ Makefile META.yml .*.sw[op] +blib/ +pm_to_blib +Makefile.old diff --git a/lib/SQL/Abstract/AST/v1.pm b/lib/SQL/Abstract/AST/v1.pm index f492580..f0ed698 100644 --- a/lib/SQL/Abstract/AST/v1.pm +++ b/lib/SQL/Abstract/AST/v1.pm @@ -68,7 +68,16 @@ class SQL::Abstract::AST::v1 extends SQL::Abstract { } method _join(ArrayRef $ast) { - + my (undef, @items) = @$ast; + + croak "invalid component in JOIN: $_" unless ArrayRef->check($items[0]); + my @output = 'JOIN'; + + # TODO: Validation of inputs + return 'JOIN '. $self->dispatch(shift @items) . + ' ON (' . + $self->_recurse_where( \@items ) . ')'; + } method _list(ArrayRef $ast) { diff --git a/t/200_join.t b/t/200_join.t new file mode 100644 index 0000000..2e89ebc --- /dev/null +++ b/t/200_join.t @@ -0,0 +1,18 @@ +use strict; +use warnings; + +use Test::More tests => 2; +use Test::Differences; + +use_ok('SQL::Abstract') or BAIL_OUT( "$@" ); + +my $sqla = SQL::Abstract->create(1); + +is $sqla->dispatch( + [ -join => + [-name => qw/foo/], + [ '==', [-name => qw/foo id/], [ -name => qw/me foo_id/ ] ] + ] +), "JOIN foo ON (foo.id = me.foo_id)", + "simple join clause"; +