[Bast-commits] r7808 - in DBIx-Class/0.08/trunk:
lib/DBIx/Class/Storage t
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Wed Oct 21 01:10:39 GMT 2009
Author: caelum
Date: 2009-10-21 01:10:39 +0000 (Wed, 21 Oct 2009)
New Revision: 7808
Modified:
DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI.pm
DBIx-Class/0.08/trunk/t/100populate.t
Log:
add test for populate with literal sql mixed with binds, improve error messages
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI.pm 2009-10-21 01:10:38 UTC (rev 7807)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI.pm 2009-10-21 01:10:39 UTC (rev 7808)
@@ -1361,9 +1361,10 @@
# 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 @@
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 @@
);
}
- $self->_query_start( $sql, @bind );
+ $self->_query_start( $sql, ['__BULK__'] );
my $sth = $self->sth($sql);
my $rv = do {
@@ -1426,7 +1427,7 @@
}
};
- $self->_query_end( $sql, @bind );
+ $self->_query_end( $sql, ['__BULK__'] );
return (wantarray ? ($rv, $sth, @bind) : $rv);
}
Modified: DBIx-Class/0.08/trunk/t/100populate.t
===================================================================
--- DBIx-Class/0.08/trunk/t/100populate.t 2009-10-21 01:10:38 UTC (rev 7807)
+++ DBIx-Class/0.08/trunk/t/100populate.t 2009-10-21 01:10:39 UTC (rev 7808)
@@ -114,9 +114,11 @@
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 @@
$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([
{
More information about the Bast-commits
mailing list