From: Norbert Buchmuller Date: Tue, 3 Mar 2009 21:37:11 +0000 (+0000) Subject: Added tests and updated POD for bindtype = 'columns' case in \[$sql, @bind] when... X-Git-Tag: v1.70~229 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=26f2dca517107ff07fdeff59ddb7f09e76612621;p=dbsrgits%2FSQL-Abstract.git Added tests and updated POD for bindtype = 'columns' case in \[$sql, @bind] when column_meta is a reference in the [column_meta => value] format bind values. --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index a3a4b0a..144b9cf 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -1881,8 +1881,11 @@ This would create: Note that you must pass the bind values in the same format as they are returned by C. That means that if you set L to C, you must -provide the bind values in the C<< [ column_name => value ] >> format, so eg. -the above example will look like: +provide the bind values in the C<< [ column_meta => value ] >> format, where +C is an opaque scalar value; most commonly the column name, but +you can use any scalar scalar value (including references and blessed +references), L will simply pass it through intact. So eg. the +above example will look like: my %where = ( date_column => \[q/= date '2008-09-30' - ?::integer/, [ dummy => 10 ]/] diff --git a/t/01generate.t b/t/01generate.t index 30d034b..0d94876 100644 --- a/t/01generate.t +++ b/t/01generate.t @@ -483,6 +483,42 @@ my @tests = ( args => ['test', '*', { a => {-in => \["(SELECT d FROM to_date(?, 'MM/DD/YY') AS d)", '02/02/02']}, b => 8 }], exception_like => qr/bindtype 'columns' selected, you need to pass: \[column_name => bind_value\]/, }, + #53 + { + func => 'insert', + new => {bindtype => 'columns'}, + args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", [{dummy => 1} => '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'], [{dummy => 1} => '02/02/02']], + }, + #54 + { + func => 'update', + new => {bindtype => 'columns'}, + args => ['test', {a => 1, b => \["to_date(?, 'MM/DD/YY')", [{dummy => 1} => '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'], [{dummy => 1} => '02/02/02'], [a => '1'], [a => '2']], + }, + #55 + { + func => 'select', + new => {bindtype => 'columns'}, + args => ['test', '*', { a => \["= to_date(?, 'MM/DD/YY')", [{dummy => 1} => '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 => [[{dummy => 1} => '02/02/02']], + }, + #56 + { + func => 'select', + new => {bindtype => 'columns'}, + args => ['test', '*', { a => {'<' => \["to_date(?, 'MM/DD/YY')", [{dummy => 1} => '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 => [[{dummy => 1} => '02/02/02'], [b => 8]], + }, );