Subject: | [PATCH] Don't return an active statement handle |
Ima::DBI uses DBI->prepare_cached(). By default the cache is stupid, it
will return an active statement handle. This is bad if you do something
like...
my $sth = $obj->sql_foo;
$sth->execute("foo");
my $another_sth = $different_obj_same_class->sql_foo;
$another_sth->execute("bar");
Currently both calls to sql_foo() will return the same statement handle.
DBI will warn but its very dangerous.
Recently (in DBI 1.40) DBI introduced an extra parameter to
prepare_cached(). If you set it to 3 (yeah, intuitive) it will Do The
Right Thing which is rather than returning an active statement handle
from the cache it will make a new one. This makes prepare_cached() much
safer.
This patch changes Ima::DBI to use that new feature. It requires
raising the minimum DBI to 1.40. If that's undesirable I can make it
optional.
This is required for the CDBI iterator patch in 24959.
Subject: | no_cache_if_active.patch |
Auto-merging (0, 27456) /local/Ima-DBI to /vendor/Ima-DBI (base /vendor/Ima-DBI:27454).
A t/active_handles.t
U MANIFEST
U lib/Ima/DBI.pm
U Makefile.PL
==== Patch <-> level 1
Source: 9c88509d-e914-0410-b01c-b9530614cbfe:/local/Ima-DBI:27456
Target: 9c88509d-e914-0410-b01c-b9530614cbfe:/vendor/Ima-DBI:27454
Log:
r27455@windhund: schwern | 2007-02-21 16:57:36 -0800
Local copy
r27456@windhund: schwern | 2007-02-21 17:11:00 -0800
Make Ima::DBI use the new "$if_active" parameter to prepare_cached() to
avoid returning an active statement handle from the cache.
=== t/active_handles.t
==================================================================
--- t/active_handles.t (revision 27454)
+++ t/active_handles.t (patch - level 1)
@@ -0,0 +1,30 @@
+#!/usr/bin/perl -w
+
+package My::DBI;
+
+use strict;
+use base 'Ima::DBI';
+
+use Cwd;
+use Test::More tests => 4;
+use Test::NoWarnings;
+
+sub new { return bless {}; }
+
+# Test set_db
+__PACKAGE__->set_db('test1', 'dbi:ExampleP:', '', '',
+ { AutoCommit => 1, Taint => 0 });
+
+__PACKAGE__->set_sql('test', 'select mode,size,name from ?', 'test1');
+
+my $obj = My::DBI->new;
+
+my $sth1 = $obj->sql_test;
+$sth1->execute(cwd);
+ok $sth1->{Active};
+
+my $sth2 = $obj->sql_test;
+$sth2->execute(cwd);
+ok $sth2->{Active};
+
+isnt $sth1, $sth2;
=== MANIFEST
==================================================================
--- MANIFEST (revision 27454)
+++ MANIFEST (patch - level 1)
@@ -6,5 +6,6 @@
META.yml
README
t/DBI.t
+t/active_handles.t
t/pod-coverage.t
t/pod.t
=== lib/Ima/DBI.pm
==================================================================
--- lib/Ima/DBI.pm (revision 27454)
+++ lib/Ima/DBI.pm (patch - level 1)
@@ -379,7 +379,7 @@
# This is to do proper '%%' translation.
my $sql = $class->transform_sql($statement => @_);
return $cache
- ? $dbh->prepare_cached($sql)
+ ? $dbh->prepare_cached($sql, {}, 3)
: $dbh->prepare($sql);
};
}
=== Makefile.PL
==================================================================
--- Makefile.PL (revision 27454)
+++ Makefile.PL (patch - level 1)
@@ -17,10 +17,11 @@
NAME => 'Ima::DBI',
VERSION_FROM => 'lib/Ima/DBI.pm',
PREREQ_PM => {
- 'DBI' => 1.20,
+ 'DBI' => 1.40,
'Class::Data::Inheritable' => 0.02,
'DBIx::ContextualFetch' => 1.00,
'Test::More' => 0.18,
+ 'Test::NoWarnings' => 0.08,
},
(
$] > 5.005
==== BEGIN SVK PATCH BLOCK ====
Version: svk v2.0.0 (darwin)
eJyNlc1u20YQx3VoEYRA0QcoUGxjBnYC09pdLj+NqHZiKXUTu0bjNkAvzHJ3ZLGmSIWk/BHTB8qO
g/TQQ4Dcihx6LHrpA/Rd8ihdUlEaJ86HIECr3Znfzuz+Z7aXbS+vkLLTwaVOcHnv5zu+v8ULMbhK
WKnbJcioSDPdKmPYg1g3yzjd0VmZ8CGo1TwdZ6IeFDzbgaIeRGIXik6HKJw7xXUbxAzbUENepEmu
ew0+KDIAnZTuileumPU30IlX5qBWGmyQwV6UR2miwqAOs2xlouyJ8k9HkARZmhavl2jtjUsRpzkE
NX7FKtVX2VNdpdQ4yCgDoWI6VLNFQ5p5N4ZsBu5HMehuubG6ud7r3tt+19K6AKmOKArfNXXPQQkp
N/gu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