From: Rafael Kitover Date: Wed, 21 Oct 2009 01:10:39 +0000 (+0000) Subject: add test for populate with literal sql mixed with binds, improve error messages X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=aac0bfd0de48a58cc3da1daff7614e178b4437c5;p=dbsrgits%2FDBIx-Class-Historic.git add test for populate with literal sql mixed with binds, improve error messages --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 5a6d4d7..86b7aca 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1361,9 +1361,10 @@ sub insert_bulk { # check for bad data my $bad_slice = sub { - my ($msg, $slice_idx) = @_; - $self->throw_exception(sprintf "%s for populate slice:\n%s", + my ($msg, $col_idx, $slice_idx) = @_; + $self->throw_exception(sprintf "%s for column '%s' in populate slice:\n%s", $msg, + $cols->[$col_idx], Data::Dumper::Concise::Dumper({ map { $cols->[$_] => $data->[$slice_idx][$_] } (0 .. $#$cols) }), @@ -1380,20 +1381,20 @@ sub insert_bulk { if ($is_literal_sql) { if (not ref $val) { - $bad_slice->('bind found where literal SQL expected', $datum_idx); + $bad_slice->('bind found where literal SQL expected', $col_idx, $datum_idx); } elsif ((my $reftype = ref $val) ne 'SCALAR') { $bad_slice->("$reftype reference found where literal SQL expected", - $datum_idx); + $col_idx, $datum_idx); } elsif ($$val ne $$sqla_bind){ $bad_slice->("inconsistent literal SQL value, expecting: '$$sqla_bind'", - $datum_idx); + $col_idx, $datum_idx); } } elsif (my $reftype = ref $val) { $bad_slice->("$reftype reference found where bind expected", - $datum_idx); + $col_idx, $datum_idx); } } } @@ -1412,7 +1413,7 @@ sub insert_bulk { ); } - $self->_query_start( $sql, @bind ); + $self->_query_start( $sql, ['__BULK__'] ); my $sth = $self->sth($sql); my $rv = do { @@ -1426,7 +1427,7 @@ sub insert_bulk { } }; - $self->_query_end( $sql, @bind ); + $self->_query_end( $sql, ['__BULK__'] ); return (wantarray ? ($rv, $sth, @bind) : $rv); } diff --git a/t/100populate.t b/t/100populate.t index ada70d9..9e7bc88 100644 --- a/t/100populate.t +++ b/t/100populate.t @@ -114,9 +114,11 @@ is($link7->id, 7, 'Link 7 id'); is($link7->url, undef, 'Link 7 url'); is($link7->title, 'gtitle', 'Link 7 title'); -# test _execute_array_empty (insert_bulk with all literal sql) my $rs = $schema->resultset('Artist'); $rs->delete; + +# test _execute_array_empty (insert_bulk with all literal sql) + $rs->populate([ (+{ name => \"'DT'", @@ -133,6 +135,26 @@ is((grep { $rs->delete; +# test mixed binds with literal sql + +$rs->populate([ + (+{ + name => \"'DT'", + rank => 500, + charfield => \"'mtfnpy'", + }) x 5 +]); + +is((grep { + $_->name eq 'DT' && + $_->rank == 500 && + $_->charfield eq 'mtfnpy' +} $rs->all), 5, 'populate with all literal SQL'); + +$rs->delete; + +### + throws_ok { $rs->populate([ {