fix up txn_begin and the ping_count test
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI.pm
index 121a2ca..094b508 100644 (file)
@@ -441,14 +441,17 @@ sub connect_info {
     # _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 };
 }
 
@@ -527,8 +530,15 @@ sub dbh_do {
 
   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;
@@ -1053,7 +1063,7 @@ sub txn_begin {
     # 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;
   }
@@ -2310,7 +2320,10 @@ sub deploy {
     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}")};
@@ -2423,7 +2436,7 @@ sub DESTROY {
 
 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
@@ -2435,7 +2448,6 @@ cases if you choose the C<< AutoCommit => 0 >> path, just as you would
 be with raw DBI.
 
 
-
 =head1 AUTHORS
 
 Matt S. Trout <mst@shadowcatsystems.co.uk>