From: Norbert Buchmuller Date: Wed, 26 Nov 2008 18:58:34 +0000 (+0000) Subject: Support for the { operator => \["...", @bind] } construct (to embed literal SQL with... X-Git-Tag: v1.70~256 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b3be7bd08ab2e97184d5700fee0930f651b0c9a2;p=dbsrgits%2FSQL-Abstract.git Support for the { operator => \["...", @bind] } construct (to embed literal SQL with bind values). --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 848a60f..248ec3a 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -536,6 +536,14 @@ sub _where_hashpair_HASHREF { $$val; }, + ARRAYREFREF => sub { # CASE: col => {op => \[$sql, @bind]} + my ($sub_sql, @sub_bind) = @$$val; + $sql = join ' ', $self->_convert($self->_quote($k)), + $self->_sqlcase($op), + $sub_sql; + @bind = @sub_bind; + }, + UNDEF => sub { # CASE: col => {op => undef} : sql "IS (NOT)? NULL" my $is = ($op =~ $self->{equality_op}) ? 'is' : ($op =~ $self->{inequality_op}) ? 'is not' : diff --git a/t/01generate.t b/t/01generate.t index 18e015c..419d3e4 100644 --- a/t/01generate.t +++ b/t/01generate.t @@ -352,6 +352,14 @@ my @tests = ( stmt_q => 'SELECT * FROM `test` WHERE ( `a` > 1 + 1 AND `b` = ? )', bind => [8], }, + #38 + { + func => 'select', + args => ['test', '*', { a => {'<' => \["to_date(?, 'MM/DD/YY')", '02/02/02']}, b => 8 }], + stmt => 'SELECT * FROM test WHERE ( a < to_date(?, \'MM/DD/YY\') AND b = ? )', + stmt_q => 'SELECT * FROM `test` WHERE ( `a` < to_date(?, \'MM/DD/YY\') AND `b` = ? )', + bind => ['02/02/02', 8], + }, );