From: Norbert Buchmuller Date: Sun, 16 Nov 2008 21:20:49 +0000 (+0000) Subject: Added test cases for passing arrayref bind values to insert() and update() when the... X-Git-Tag: v1.70~262 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d82b8afbe324acc0085c335a18a3f7a597b88609;p=dbsrgits%2FSQL-Abstract.git Added test cases for passing arrayref bind values to insert() and update() when the 'array_datatypes' constructor parameter is set to true. Fixed a bug in insert() when 'array_datatypes' is set to true and an arrayref is passed. --- diff --git a/lib/SQL/Abstract.pm b/lib/SQL/Abstract.pm index b3c4581..2a74a7f 100644 --- a/lib/SQL/Abstract.pm +++ b/lib/SQL/Abstract.pm @@ -145,6 +145,7 @@ sub _insert_ARRAYREF { # just generate values(?,?) part (no list of fields) ARRAYREF => sub { if ($self->{array_datatypes}) { # if array datatype are activated push @values, '?'; + push @all_bind, $v; } else { # else literal SQL with bind my ($sql, @bind) = @$v; diff --git a/t/01generate.t b/t/01generate.t index 5859c38..000d6f7 100644 --- a/t/01generate.t +++ b/t/01generate.t @@ -5,7 +5,7 @@ use warnings; use Test::More; use SQL::Abstract::Test import => ['is_same_sql_bind']; -plan tests => 64; +plan tests => 72; use SQL::Abstract; @@ -308,7 +308,43 @@ my @tests = ( 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 => ['02/02/02'], - } + }, + #33 + { + func => 'insert', + new => {array_datatypes => 1}, + args => ['test', {a => 1, b => [1, 1, 2, 3, 5, 8]}], + stmt => 'INSERT INTO test (a, b) VALUES (?, ?)', + stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, ?)', + bind => [1, [1, 1, 2, 3, 5, 8]], + }, + #34 + { + func => 'insert', + new => {bindtype => 'columns', array_datatypes => 1}, + args => ['test', {a => 1, b => [1, 1, 2, 3, 5, 8]}], + stmt => 'INSERT INTO test (a, b) VALUES (?, ?)', + stmt_q => 'INSERT INTO `test` (`a`, `b`) VALUES (?, ?)', + bind => [[a => 1], [b => [1, 1, 2, 3, 5, 8]]], + }, + #35 + { + func => 'update', + new => {array_datatypes => 1}, + args => ['test', {a => 1, b => [1, 1, 2, 3, 5, 8]}], + stmt => 'UPDATE test SET a = ?, b = ?', + stmt_q => 'UPDATE `test` SET `a` = ?, `b` = ?', + bind => [1, [1, 1, 2, 3, 5, 8]], + }, + #36 + { + func => 'update', + new => {bindtype => 'columns', array_datatypes => 1}, + args => ['test', {a => 1, b => [1, 1, 2, 3, 5, 8]}], + stmt => 'UPDATE test SET a = ?, b = ?', + stmt_q => 'UPDATE `test` SET `a` = ?, `b` = ?', + bind => [[a => 1], [b => [1, 1, 2, 3, 5, 8]]], + }, ); use Data::Dumper; @@ -333,5 +369,3 @@ for (@tests) { is_same_sql_bind($stmt_q, \@bind_q, $_->{stmt_q}, $_->{bind}); } - -