From: Arthur Axel "fREW" Schmidt Date: Fri, 15 Oct 2010 00:31:47 +0000 (+0000) Subject: fix placeholder surround and add complex test X-Git-Tag: v1.70~40 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ad46269d24e7252a1b0bf635478c64ea522d57d1;p=dbsrgits%2FSQL-Abstract.git fix placeholder surround and add complex test --- diff --git a/lib/SQL/Abstract/Tree.pm b/lib/SQL/Abstract/Tree.pm index 8805828..092d88a 100644 --- a/lib/SQL/Abstract/Tree.pm +++ b/lib/SQL/Abstract/Tree.pm @@ -367,11 +367,11 @@ sub fill_in_placeholder { my ($self, $bindargs) = @_; if ($self->fill_in_placeholders) { - my $val = pop @{$bindargs} || ''; + my $val = shift @{$bindargs} || ''; my ($left, $right) = @{$self->placeholder_surround}; $val =~ s/\\/\\\\/g; $val =~ s/'/\\'/g; - return qq('$left$val$right') + return qq($left$val$right) } return '?' } diff --git a/t/15placeholders.t b/t/15placeholders.t index bba9b66..4ee0db8 100644 --- a/t/15placeholders.t +++ b/t/15placeholders.t @@ -12,7 +12,7 @@ my $placeholders = ['station', 'lolz']; placeholder_surround => [qw(; -)], }); - is($sqlat->fill_in_placeholder($placeholders), q(';lolz-'), + is($sqlat->fill_in_placeholder($placeholders), q(;lolz-), 'placeholders are populated correctly' ); } @@ -23,9 +23,20 @@ my $placeholders = ['station', 'lolz']; placeholder_surround => [qw(< >)], }); - is($sqlat->fill_in_placeholder($placeholders), q(''), + is($sqlat->fill_in_placeholder($placeholders), q(), 'placeholders are populated correctly and in order' ); } + +{ + my $sqlat = SQL::Abstract::Tree->new({ + fill_in_placeholders => 1, + placeholder_surround => [qw(' ')], + }); + + is $sqlat->format('SELECT ? as x, ? as y FROM Foo WHERE t > ? and z IN (?, ?, ?) ', ['frew', 'ribasushi', '2008-12-12', 1, 2, 3]), + q[SELECT 'frew' as x, 'ribasushi' as y FROM Foo WHERE t > '2008-12-12' AND z IN ('1', '2', '3')], 'Complex placeholders work'; +} + done_testing;