Subject: | Make dbh_do reconnect to the database if necessary |
When executing a cursor-based search, make sure that the
database handle is reconnected. Without this change, a
cursor-based search attempted on a disconnected database
handle fails (depending on how the DBD handles disconnected
handles).
Subject: | 0001-Make-dbh_do-reconnect-to-the-database-if-necessary.patch |
From 0637f12dace28101c5d26f39b07e034f143d1c0c Mon Sep 17 00:00:00 2001
From: Michael Hendricks <michael@ndrix.org>
Date: Wed, 17 Sep 2008 10:34:20 -0600
Subject: [PATCH] Make dbh_do reconnect to the database if necessary
When executing a cursor-based search, make sure that the
database handle is reconnected. Without this change, a
cursor-based search attempted on a disconnected database
handle fails (depending on how the DBD handles disconnected
handles).
Signed-off-by: Michael Hendricks <michael@ndrix.org>
---
lib/DBIx/Class/Storage/DBI.pm | 2 +-
t/disconnected_search.t | 13 +++++++++++++
2 files changed, 14 insertions(+), 1 deletions(-)
create mode 100644 t/disconnected_search.t
diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm
index 806cef8..3239a47 100644
--- a/lib/DBIx/Class/Storage/DBI.pm
+++ b/lib/DBIx/Class/Storage/DBI.pm
@@ -588,7 +588,7 @@ sub dbh_do {
my $self = shift;
my $code = shift;
- my $dbh = $self->_dbh;
+ my $dbh = $self->dbh;
return $self->$code($dbh, @_) if $self->{_in_dbh_do}
|| $self->{transaction_depth};
diff --git a/t/disconnected_search.t b/t/disconnected_search.t
new file mode 100644
index 0000000..0c52663
--- /dev/null
+++ b/t/disconnected_search.t
@@ -0,0 +1,13 @@
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+use Test::Warn;
+use lib qw(t/lib);
+use DBICTest;
+
+my $schema = DBICTest->init_schema();
+my $dbh = $schema->storage->dbh->disconnect;
+warnings_are {
+ $schema->resultset('Artist')->search( name => 'Chris LeDoux' )->first;
+} [], 'searching through a disconnected dbh';
--
1.5.6