Subject: | DBIx::Simple destroy my dbh even if it does not create it |
Hi,
DBIx::Simple destroy the databasehandle if the object is destroyed. Thats fine if DBIx::Simple
create the handle. But that prevent my modules and larger scripts to use DBIx::Simple, since
they get a database handle just for usage.
This patch prevents DBIx::Simple to destroy a handle, that is not created by DBIx::Simple.
This seems very important for anything that is larger than a script to me.
--
Boris
Subject: | destroy_only_if_created.patch |
Fix: destroy dbh only, if it was created from DBIx-Simple
---
commit 74535e338391a346d0642b404662121d013618cd
tree 049bf94c0eeef1aa3200d75e875e7a4f9e7f4947
parent df2d95344e3f3c462600cb56ee8f6e15a20329ac
author Boris Zentner <bzm@2bz.de> Sun, 05 Nov 2006 18:14:33 +0100
committer Boris Zentner <bzm@2bz.de> Sun, 05 Nov 2006 18:14:33 +0100
lib/DBIx/Simple.pm | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/lib/DBIx/Simple.pm b/lib/DBIx/Simple.pm
index 73851c7..5f3da39 100644
--- a/lib/DBIx/Simple.pm
+++ b/lib/DBIx/Simple.pm
@@ -44,6 +44,8 @@ sub connect {
} else {
$arguments[3]->{PrintError} = 0
unless defined $arguments[3] and defined $arguments[3]{PrintError};
+ # destroy dbh only if we create dbh
+ $self->{_destroy_dbh} = 1;
$self->{dbh} = DBI->connect(@arguments);
}
@@ -108,7 +110,7 @@ sub _die {
# Conditional, because destruction order is not guaranteed
# during global destruction.
- $self->{dbh}->disconnect() if defined $self->{dbh};
+ $self->{dbh}->disconnect() if defined $self->{dbh} and defined $self->{_destroy_dbh};
Data::Swap::swap(
$self,
@@ -680,6 +682,8 @@ Destroys (finishes) active statements an
object is destroyed, this happens automatically. After disconnecting, you can
no longer use the database object or any of its result objects.
+The underlying dbh is only destroyed, if DBIx::Simple was used to create the handle.
+
=back
=head2 DBIx::Simple::Dummy
@@ -721,7 +725,7 @@ Fetches a single row and returns a refer
values. This is the same array every time.
Subsequent fetches (using any method) may change the values in the variables
-passed and the returned reference's array.
+Passed and the returned reference's array.
=item C<into(LIST)>
@@ -760,7 +764,7 @@ In scalar context, returns an array refe
Keys are lower cased if C<lc_columns> was true when the query was executed.
-=item C<map_arrays($column_number)>
+=Item C<map_arrays($column_number)>
Constructs a hash of array references keyed by the values in the chosen column.
@@ -871,7 +875,7 @@ line numbers in DBIx/Simple.pm.
=head1 LICENSE
There is no license. This software was released into the public domain. Do with
-it what you want, but on your own risk. The author disclaims any
+It what you want, but on your own risk. The author disclaims any
responsibility.
=head1 AUTHOR