From: Norbert Buchmuller Date: Mon, 17 Nov 2008 04:29:33 +0000 (+0100) Subject: * Added test cases to test if arrayref bind values in insert/update are passed throu... X-Git-Tag: v0.08240~189^2~30 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e5938571f31c21e93865da521f2fa1c14e45827e;p=dbsrgits%2FDBIx-Class.git * Added test cases to test if arrayref bind values in insert/update are passed through sql_maker intact. * Added 'array_datatypes' parameter to the sql_maker constructor. --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 54c79f1..45dba23 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -857,7 +857,7 @@ sub dbh { sub _sql_maker_args { my ($self) = @_; - return ( bindtype=>'columns', limit_dialect => $self->dbh, %{$self->_sql_maker_opts} ); + return ( bindtype=>'columns', array_datatypes => 1, limit_dialect => $self->dbh, %{$self->_sql_maker_opts} ); } sub sql_maker { diff --git a/t/95sql_maker.t b/t/95sql_maker.t new file mode 100644 index 0000000..0971d12 --- /dev/null +++ b/t/95sql_maker.t @@ -0,0 +1,53 @@ +use strict; +use warnings; + +use Test::More; +use SQL::Abstract::Test import => ['is_same_sql_bind']; + + +BEGIN { + eval "use DBD::SQLite"; + plan $@ + ? ( skip_all => 'needs DBD::SQLite for testing' ) + : ( tests => 3 ); +} + +use lib qw(t/lib); + +use_ok('DBICTest'); + +my $schema = DBICTest->init_schema(); + +my $sql_maker = $schema->storage->sql_maker; + + +my ($sql, @bind) = $sql_maker->insert( + 'lottery', + { + 'day' => '2008-11-16', + 'numbers' => [13, 21, 34, 55, 89] + } +); + +is_same_sql_bind( + $sql, \@bind, + q/INSERT INTO lottery (day, numbers) VALUES (?, ?)/, + [ ['day' => '2008-11-16'], ['numbers' => [13, 21, 34, 55, 89]] ], + 'sql_maker passes arrayrefs in insert' +); + + +($sql, @bind) = $sql_maker->update( + 'lottery', + { + 'day' => '2008-11-16', + 'numbers' => [13, 21, 34, 55, 89] + } +); + +is_same_sql_bind( + $sql, \@bind, + q/UPDATE lottery SET day = ?, numbers = ?/, + [ ['day' => '2008-11-16'], ['numbers' => [13, 21, 34, 55, 89]] ], + 'sql_maker passes arrayrefs in update' +);