From: Ash Berlin Date: Sun, 29 Mar 2009 17:31:39 +0000 (+0100) Subject: Fix behavoiur of * in names X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8b398780f00bb3e9c43ed749d86a1dd01af59716;p=dbsrgits%2FSQL-Abstract-2.0-ish.git Fix behavoiur of * in names --- diff --git a/lib/SQL/Abstract/AST/v1.pm b/lib/SQL/Abstract/AST/v1.pm index 821245c..34d340e 100644 --- a/lib/SQL/Abstract/AST/v1.pm +++ b/lib/SQL/Abstract/AST/v1.pm @@ -130,12 +130,18 @@ class SQL::Abstract::AST::v1 extends SQL::Abstract { my $post; $post = pop @names if $names[-1] eq '*'; - my $ret = - $quote->[0] . - join( $join, @names ) . - $quote->[-1]; + my $ret; + $ret = $quote->[0] . + join( $join, @names ) . + $quote->[-1] + if @names; + + $ret = $ret + ? $ret . $sep . $post + : $post + if defined $post; + - $ret .= $sep . $post if defined $post; return $ret; } diff --git a/t/001_basic.t b/t/001_basic.t index 849a982..6eea38a 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 9; +use Test::More tests => 10; use Test::Differences; use_ok('SQL::Abstract') or BAIL_OUT( "$@" ); @@ -13,6 +13,10 @@ my $sqla = SQL::Abstract->create(1); is $sqla->dispatch( { -type => 'name', args => [qw/me id/] }), "me.id", "Simple name generator"; +is $sqla->dispatch( { -type => 'name', args => ['*'] } ), + "*", + "* name generator"; + is $sqla->dispatch( { -type => 'name', args => [qw/me */]}), "me.*", "Simple name generator"; diff --git a/t/003_quote.t b/t/003_quote.t index 61df9dc..6f26fb6 100644 --- a/t/003_quote.t +++ b/t/003_quote.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 2; +use Test::More tests => 5; use Test::Exception; use_ok('SQL::Abstract') or BAIL_OUT( "$@" ); @@ -11,3 +11,18 @@ my $sqla = SQL::Abstract->create(1); lives_ok { $sqla->quote_chars('[]'); } "coercion of quote_chars from Str works"; + + +is $sqla->dispatch( { -type => 'name', args => [qw/me id/] }), + "[me].[id]", + "me.id"; + + +is $sqla->dispatch( { -type => 'name', args => [qw/me */] }), + "[me].*", + "me.*"; + + +is $sqla->dispatch( { -type => 'name', args => [qw/*/] }), + "*", + "*";