# _connect() never looks past $args[0] in this case
%attrs = ()
} else {
- %attrs = (%{ $self->_dbi_connect_attributes }, %attrs);
+ %attrs = (
+ %{ $self->_default_dbi_connect_attributes || {} },
+ %attrs,
+ );
}
$self->_dbi_connect_info([@args, keys %attrs ? \%attrs : ()]);
$self->_connect_info;
}
-sub _dbi_connect_attributes {
+sub _default_dbi_connect_attributes {
return { AutoCommit => 1 };
}
local $self->{_in_dbh_do} = 1;
+ $self->_do_with_reconnect($code, @_);
+}
+
+sub _do_with_reconnect {
+ my $self = shift;
+ my $code = shift;
my @result;
my $want_array = wantarray;
+ my $dbh = $self->_dbh;
eval {
$self->_verify_pid if $dbh;
# this isn't ->_dbh-> because
# we should reconnect on begin_work
# for AutoCommit users
- $self->dbh_do(sub { $_[1]->begin_work });
+ $self->_do_with_reconnect(sub { $_[1]->begin_work });
} elsif ($self->auto_savepoint) {
$self->svp_begin;
}
return if $line =~ /^\s+$/; # skip whitespace only
$self->_query_start($line);
eval {
- $self->last_dbh->do($line);
+ # a previous error may invalidate $dbh - thus we need to use dbh()
+ # to guarantee a healthy $dbh (this is temporary until we get
+ # proper error handling on deploy() )
+ $self->dbh->do($line);
};
if ($@) {
carp qq{$@ (running "${line}")};
DBIx::Class can do some wonderful magic with handling exceptions,
disconnections, and transactions when you use C<< AutoCommit => 1 >>
-combined with C<txn_do> for transaction support.
+(the default) combined with C<txn_do> for transaction support.
If you set C<< AutoCommit => 0 >> in your connect info, then you are always
in an assumed transaction between commits, and you're telling us you'd
be with raw DBI.
-
=head1 AUTHORS
Matt S. Trout <mst@shadowcatsystems.co.uk>