From: Peter Rabbitson Date: Sat, 29 Aug 2009 06:07:18 +0000 (+0000) Subject: Make sure arrays work X-Git-Tag: v0.08111~50^2~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a77413354fab06f5c234166049de1ee19a95c7e1;p=dbsrgits%2FDBIx-Class.git Make sure arrays work --- diff --git a/lib/DBIx/Class/Storage/DBI/AutoCast.pm b/lib/DBIx/Class/Storage/DBI/AutoCast.pm index 15218eb..9eb5245 100644 --- a/lib/DBIx/Class/Storage/DBI/AutoCast.pm +++ b/lib/DBIx/Class/Storage/DBI/AutoCast.pm @@ -48,7 +48,7 @@ sub _prep_for_execute { my $col = $bound->[0]; my $type = $self->_map_data_type($col_info->{$col}{data_type}); - foreach my $data (@{$bound}[1..$#$bound]) { # <--- this will multiply the amount of ?'s no...? + foreach my $data (@{$bound}[1..$#$bound]) { $new_sql .= shift(@sql_part) . ($type ? "CAST(? AS $type)" : '?'); } diff --git a/t/93autocast.t b/t/93autocast.t index a8375be..682755a 100644 --- a/t/93autocast.t +++ b/t/93autocast.t @@ -33,9 +33,15 @@ my $rs = $schema->resultset ('CD')->search ({ 'tracks.last_updated_at' => { '!=', undef }, 'tracks.last_updated_on' => { '<', 2009 }, 'tracks.position' => 4, + 'tracks.single_track' => \[ '= ?', [ single_track => [1, 2, 3 ] ] ], }, { join => 'tracks' }); -my $bind = [ [ cdid => 5 ], [ 'tracks.last_updated_on' => 2009 ], [ 'tracks.position' => 4 ] ]; +my $bind = [ + [ cdid => 5 ], + [ 'tracks.last_updated_on' => 2009 ], + [ 'tracks.position' => 4 ], + [ 'single_track' => [ 1, 2, 3] ], +]; is_same_sql_bind ( $rs->as_query, @@ -48,6 +54,7 @@ is_same_sql_bind ( AND tracks.last_updated_at IS NOT NULL AND tracks.last_updated_on < ? AND tracks.position = ? + AND tracks.single_track = ? )', $bind, 'expected sql with casting off', @@ -66,6 +73,7 @@ is_same_sql_bind ( AND tracks.last_updated_at IS NOT NULL AND tracks.last_updated_on < CAST (? AS yyy) AND tracks.position = ? + AND tracks.single_track = CAST(? AS INT) )', $bind, 'expected sql with casting on',