Re: CDBI and mod_perl

[prev] [thread] [next] [Date index for 2005/02/12]

From: Rod McChesney
Subject: Re: CDBI and mod_perl
Date: 01:55 on 12 Feb 2005
This is a new but related issue: combining do_transaction
(http://www.class-dbi.com/cgi-bin/wiki/index.cgi?AtomicUpdates) with
the db_Main override doesn't work if you are running with AutoCommit
off. It seems that DBI::connect_cache stores a closure that reapplies
the handle's original attributes every time it's called. So the "local
$class->db_Main->{AutoCommit}" thing does not work as expected. The
workaround I've come up with is this (not overly attractive) code:

sub db_Main {
    my $dbh;
    my @args = ('dsn', 'user', 'password', { AutoCommit => 0  }); # or whatever
    if ($ENV{'MOD_PERL'} and !$Apache::ServerStarting) {
        $dbh = DBI->connect(@args);
    } else {
	my $internal_db_name = 'IMA_DB';
	my @dbnames = Ima::DBI->db_names;
	if (@dbnames == 1 and $dbnames[0] eq $internal_db_name) {
            # Have a cached handle
	    $dbh = __PACKAGE__->db_IMA_DB;
	} else {
            # First time through, connect
	    $dbh = Ima::DBI->set_db($internal_db_name, @args);
	}
    }
    return $dbh;
}

In other words, outside of mod_perl, use the Ima::DBI mechanism with
some internal name to get its caching set up. Then dynamically scoped
dbh attributes work as expected. 

BTW, for mod_perl, does it not work correctly to just use DBI::connect instead
of Perrin's code that caches the handle in pnotes? I'm not a mod_perl
expert so I'm likely missing something, but it seems from the docs
that connect()
is redefined by Apache to do the right thing.

Rod

(message missing)

Column Names
Justin Tocci 05:19 on 10 Feb 2005

Re: Column Names
Peter Speltz 20:36 on 10 Feb 2005

Re: Column Names
Rod McChesney 20:56 on 10 Feb 2005

CDBI and mod_perl
Rod McChesney 20:58 on 10 Feb 2005

Re: CDBI and mod_perl
Perrin Harkins 21:37 on 10 Feb 2005

Re: CDBI and mod_perl
Drew Wilson 21:54 on 10 Feb 2005

Re: CDBI and mod_perl
karjala_lists 13:59 on 15 Feb 2005

Re: CDBI and mod_perl
Perrin Harkins 22:16 on 10 Feb 2005

Re: CDBI and mod_perl
Drew Wilson 22:27 on 10 Feb 2005

Re: CDBI and mod_perl
Perrin Harkins 22:46 on 10 Feb 2005

Re: CDBI and mod_perl
Edward J. Sabol 23:42 on 10 Feb 2005

Re: CDBI and mod_perl
Rod McChesney 01:55 on 12 Feb 2005

Re: CDBI and mod_perl
Edward J. Sabol 19:43 on 12 Feb 2005

Re: CDBI and mod_perl
Rod McChesney 18:48 on 14 Feb 2005

Re: CDBI and mod_perl
Perrin Harkins 21:23 on 14 Feb 2005

Re: CDBI and mod_perl
Edward J. Sabol 06:53 on 14 Feb 2005

Re: CDBI and mod_perl
Perrin Harkins 21:14 on 14 Feb 2005

Re: CDBI and mod_perl
Perrin Harkins 19:59 on 15 Feb 2005

Re: CDBI and mod_perl
Tim Bunce 22:33 on 15 Feb 2005

Re: CDBI and mod_perl
Tony Bowden 22:12 on 18 Feb 2005

Re: CDBI and mod_perl
=?ISO-8859-1?Q?Ask_Bj=F8rn_Hansen?= 22:19 on 18 Feb 2005

Re: CDBI and mod_perl
Perrin Harkins 22:36 on 18 Feb 2005

Re: CDBI and mod_perl
Tony Bowden 11:23 on 19 Feb 2005

Re: CDBI and mod_perl
Perrin Harkins 13:56 on 19 Feb 2005

Re: CDBI and mod_perl
Tony Bowden 15:57 on 19 Feb 2005

Re: CDBI and mod_perl
Perrin Harkins 16:21 on 19 Feb 2005

Re: CDBI and mod_perl
Perrin Harkins 16:24 on 19 Feb 2005

Re: CDBI and mod_perl
Tony Bowden 09:54 on 20 Feb 2005

Re: CDBI and mod_perl
Perrin Harkins 21:31 on 20 Feb 2005

Re: CDBI and mod_perl
Tony Bowden 22:19 on 20 Feb 2005

Generated at 12:48 on 22 Feb 2005 by mariachi v0.52