From: Norbert Buchmuller Date: Sun, 15 Feb 2009 14:33:19 +0000 (+0000) Subject: Fixed a bug in hashpair with literal SQL and bind value (ie. col => { op => \[$sql... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cd87fd4cb496d50172d60c241bff1060879e431b;p=scpubgit%2FQ-Branch.git Fixed a bug in hashpair with literal SQL and bind value (ie. col => { op => \[$sql, @bind] }) when bindtype => 1. Added tests for hashpair with literal SQL and bind value (ie. col => { op => \[$sql, @bind] }) when bindtype => 1. --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index 6fb68e9..46d2a4f 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -547,7 +547,7 @@ sub _where_hashpair_HASHREF { $sql = join ' ', $self->_convert($self->_quote($k)), $self->_sqlcase($op), $sub_sql; - @bind = @sub_bind; + @bind = $self->_bindtype($k, @sub_bind); }, UNDEF => sub { # CASE: col => {op => undef} : sql "IS (NOT)? NULL" diff --git a/t/01generate.t b/t/01generate.t index b841181..0211b53 100644 --- a/t/01generate.t +++ b/t/01generate.t @@ -402,6 +402,43 @@ my @tests = ( stmt_q => 'SELECT * FROM `test` WHERE ( `a` < 42 AND `b` = ? )', bind => [qw(8)], }, + + #44 + { + func => 'insert', + new => {bindtype => 'columns'}, + args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", '02/02/02']}], + stmt => 'INSERT INTO test (a, b) VALUES (?, to_date(?, \'MM/DD/YY\'))', + stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, to_date(?, \'MM/DD/YY\'))', + bind => [[a => '1'], [b => '02/02/02']], + }, + #45 + { + func => 'update', + new => {bindtype => 'columns'}, + args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", '02/02/02']}, {a => {'between', [1,2]}}], + stmt => 'UPDATE test SET a = ?, b = to_date(?, \'MM/DD/YY\') WHERE ( a BETWEEN ? AND ? )', + stmt_q => 'UPDATE `test` SET `a` = ?, `b` = to_date(?, \'MM/DD/YY\') WHERE ( `a` BETWEEN ? AND ? )', + bind => [[a => '1'], [b => '02/02/02'], [a => '1'], [a => '2']], + }, + #46 + { + func => 'select', + new => {bindtype => 'columns'}, + args => ['test', '*', { a => \["= to_date(?, 'MM/DD/YY')", '02/02/02']}], + stmt => q{SELECT * FROM test WHERE ( a = to_date(?, 'MM/DD/YY') )}, + stmt_q => q{SELECT * FROM `test` WHERE ( `a` = to_date(?, 'MM/DD/YY') )}, + bind => [[a => '02/02/02']], + }, + #47 + { + func => 'select', + new => {bindtype => 'columns'}, + 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 => [[a => '02/02/02'], [b => 8]], + }, );