Re: Ima::DBI and connections at Apache startup

[prev] [thread] [next] [Date index for 2004/10/06]

From: Tim Bunce
Subject: Re: Ima::DBI and connections at Apache startup
Date: 12:24 on 06 Oct 2004
On Wed, Oct 06, 2004 at 03:01:43PM +1000, Brad Bowman wrote:
> 
> > > Another BIG hitch with my plan is that Class::DBI needs to
> > > consistently get the same handle from db_Main for transactions
> > > to work.
> > 
> > That shouldn't be a problem at all.  You always get the same handle in
> > the same process when you use connect_cached/Apache::DBI and send the
> > same connect string.
> 
> That's what I expected, but it didn't seem that way in my tests (below)
> 
> AutoCommit seems to be reset at DBI.pm line 640 in 'connect'
> after the cache is hit.  This would also effect Apache::DBI::connect.

That's an interesting observation. 

> I guess this is to ensure the handle is in the state expected from
> the given attributes (& defaults) but it does have the side effect
> of breaking transactions when you don't connect with AutoCommit = 1,
> and later "begin_work".
> 
> I guess "Don't do that" is the answer.  Perhaps the reseting
> code should warn you if AutoCommit isn't the same.

I can argue it either way. Really DBI->connect is doing too much and
some of the logic ought to be done by $drh->connect, which would
then mean the handle returned by $drh->connect_cached would not
need be "mucked about with" by DBI->connect.  This is an area that
may change in DBI v2.0.

Tim.

> @c = ('XXX','XXX','XXX',{AutoCommit=>1});
> 
>   DB<2>  x  $a = DBI->connect_cached(@c);
> 0  DBI::db=HASH(0x83fb060)
>      empty hash
>   DB<3>   x $a->{Active}
> 0  1
>   DB<4>   x $a->{AutoCommit}
> 0  1
>   DB<5>   x $a->begin_work
> 0  1
>   DB<6>   x $a->{AutoCommit}
> 0  ''
>   DB<7>   x $a->rollback
> 0  1
>   DB<8>   x DBI->connect_cached(@c)->{AutoCommit}
> 0  1
>   DB<9>   x DBI->connect_cached(@c)->begin_work
> 0  1
>   DB<10>   x DBI->connect_cached(@c)->{AutoCommit}
> 0  1
>   DB<11>   x DBI->connect_cached(@c)->rollback
> rollback ineffective with AutoCommit enabled at (eval 14)[/usr/share/perl/5.6.1/perl5db.pl:1521] line 2.
> Rollback ineffective while AutoCommit is on at (eval 14)[/usr/share/perl/5.6.1/perl5db.pl:1521] line 2.
> DBD::mysql::db rollback failed: Rollback ineffective while AutoCommit is on at (eval 14)[/usr/share/perl/5.6.1/perl5db.pl:1521] line 2.
> 0  ''
>   DB<12> x DBI->connect_cached(@c)->{Driver}{CachedKids}
> 0  HASH(0x842f11c)
>    'XXX:localhost~~XXX~~XXX~~AutoCommit~~PrintError~~Username~~dbi_connect_method~~1~~1~~www-data~~connect_cached' => DBI::db=HASH(0x83fb060)
>         empty hash
> 
> 
> 
> -- 
>  Among the maxims on Lord Naoshige's wall there was this one: "Matters
>  of great concern should be treated lightly." Master Ittei commented,
>  "Matters of small concern should be treated seriously."
>    -- Hagakure http://bereft.net/hagakure/
> 

(message missing)

Ima::DBI and connections at Apache startup
Brad Bowman 08:03 on 04 Oct 2004

Re: Ima::DBI and connections at Apache startup
Perrin Harkins 17:15 on 04 Oct 2004

Re: Ima::DBI and connections at Apache startup
Brad Bowman 01:15 on 05 Oct 2004

Re: Ima::DBI and connections at Apache startup
Brad Bowman 04:47 on 05 Oct 2004

Re: Ima::DBI and connections at Apache startup
Perrin Harkins 14:27 on 05 Oct 2004

Problem with has_many and searching
John Day 16:06 on 05 Oct 2004

Re: Ima::DBI and connections at Apache startup
Perrin Harkins 14:26 on 05 Oct 2004

Re: Ima::DBI and connections at Apache startup
Brad Bowman 05:01 on 06 Oct 2004

Re: Ima::DBI and connections at Apache startup
Tim Bunce 12:24 on 06 Oct 2004

Re: Ima::DBI and connections at Apache startup
Perrin Harkins 15:23 on 06 Oct 2004

Re: Problem with has_many and searching
Perrin Harkins 16:21 on 05 Oct 2004

Re: Problem with has_many and searching
John Day 17:26 on 05 Oct 2004

Re: Ima::DBI and connections at Apache startup
Tony Bowden 17:31 on 06 Oct 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52