Thanks! It seems to be working correctly after implementing your changes.
Brian
Perrin Harkins wrote:
I plan to submit a patch for Ima::DBI to fix this, but in the meantime I
am handling it by overriding db_Main and doing the connections myself.
Here's the code I use:
my $db_options = {
RaiseError => 1,
AutoCommit => 0,
FetchHashKeyName => 'NAME_lc',
ShowErrorStatement => 1,
ChopBlanks => 1,
RootClass => 'DBIx::ContextualFetch'
};
# override default to avoid using Ima::DBI closure
sub db_Main {
my $dbh;
if ( $ENV{'MOD_PERL'} and !$Apache::ServerStarting ) {
$dbh = Apache->request()->pnotes('dbh');
}
if ( !$dbh ) {
# $config is my config object. replace with your own
settings...
$dbh = DBI->connect_cached(
$config->get('DbDSN'), $config->get('DbUser'),
$config->get('DbPass'), $db_options
);
if ( $ENV{'MOD_PERL'} and !$Apache::ServerStarting ) {
Apache->request()->pnotes( 'dbh', $dbh );
}
}
return $dbh;
}
sub dbi_commit {
my $self = shift;
$self->db_Main()->commit();
}
sub dbi_rollback {
my $self = shift;
$self->db_Main()->rollback();
}
Note that it was necessary to override dbi_commit and dbi_rollback as
well because now Ima::DBI doesn't know about this handle. I also
stashed the handle in pnotes() for some extra speed because Class::DBI
requests it so frequently. Stashing in pnotes() is safe because it gets
cleared out at the end of each request even if your code dies. Make
sure you keep the other db options intact or various things in
Class::DBI will break.
- Perrin
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html