From: Justin Guenther Date: Thu, 18 May 2006 18:32:06 +0000 (+0000) Subject: added bind information to exception thrown from DBIx::Class::Storage::DBI::_execute() X-Git-Tag: v0.07002~91 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ec0ff6f689dea45b268ad810e664933154892c58;p=dbsrgits%2FDBIx-Class.git added bind information to exception thrown from DBIx::Class::Storage::DBI::_execute() --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 7752224..1b43dae 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -509,25 +509,27 @@ sub _execute { my ($sql, @bind) = $self->sql_maker->$op($ident, @args); unshift(@bind, @$extra_bind) if $extra_bind; if ($self->debug) { - my @debug_bind = map { defined $_ ? qq{`$_'} : q{`NULL'} } @bind; - $self->debugfh->print("$sql: " . join(', ', @debug_bind) . "\n"); + my $bind_str = join(', ', map { + defined $_ ? qq{`$_'} : q{`NULL'} + } @bind); + $self->debugfh->print("$sql ($bind_str)\n"); } my $sth = eval { $self->sth($sql,$op) }; if (!$sth || $@) { - $self->throw_exception('no sth generated via sql (' . ($@ || $self->_dbh->errstr) . "): $sql"); + $self->throw_exception( + 'no sth generated via sql (' . ($@ || $self->_dbh->errstr) . "): $sql" + ); } - @bind = map { ref $_ ? ''.$_ : $_ } @bind; # stringify args - my $rv; - if ($sth) { - $rv = eval { $sth->execute(@bind) }; - - if ($@ || !$rv) { - $self->throw_exception("Error executing '$sql': ".($@ || $sth->errstr)); - } - } else { - $self->throw_exception("'$sql' did not generate a statement."); + my $rv = eval { $sth->execute(@bind) }; + if ($@ || !$rv) { + my $bind_str = join(', ', map { + defined $_ ? qq{`$_'} : q{`NULL'} + } @bind); + $self->throw_exception( + "Error executing '$sql' ($bind_str): ".($@ || $sth->errstr) + ); } return (wantarray ? ($rv, $sth, @bind) : $rv); }