Hi Monks,

I face quite a big problem at the time that would force me to rewrite loads of code if i can't find an answer :-(

I'm working on Apache 1.3 with mod_perl and Postgres 7.2.

before using ApacheDBI, I was caching my $dbh with an home made singleton object.

I used to open connections with AutoCommit On, change AutoCommit on the fly this way :

my $dbh = DBI->connect( ... {AutoCommit => 1, ..} ) ... >> perform some method call here < < local $dbh->{AutoCommit} = 0; eval { # call to EmitSignal on the parent object $this->EmitSignal( $event_id, @extra_args ); # call to Update on another object call "Thread" $thread->Update(); #Serialize thread. $dbh->commit(); }; if ($@) { $dbh->rollback(); die $@; } local $dbh->{AutoCommit} = 1; ...
This was working fine, each of those (this->EmitSignal and $thread->Update) was retrieving the same $dbh from the singleton, autocommit was off and $dbh->commit was commiting all.

When i was logging $dbh->{AutoCommit}, there was no value (==0)

Since i installed ApacheDBI, this doesn't work anymore. When i log the $dbh retrieved from the different objects (Thread and the parent object), i've got the same reference, something like Apache::DBI::db=HASH(0x8f1b840) for all of them.

but my error_log gives me Warning in Perl code: commit ineffective with AutoCommit enabled at /home/httpd_akio/pgakio/lib/perl/Akio/ThreadManager.pm line 170

when i log $dbh->{AutoCommit} from Thread object for example, it's 1 and not 0!!

It seems that the $dbh->{AutoCommit} = 0; only affects the $dbh used in the block, and not the one used in the subroutines, something like if the Apache::DBI retrieve from the subroutines was the one created by the connect_on_init from the startup.pl.

The doc says : However, when the $dbh attribute is altered after connect() it affects all other handlers retrieving this database handle. Therefore it's best to restore the modified attributes to their original value at the end of database handle usage.

With further investigation in ApacheDBI, it seems that all the handlers are cached in global %Apache::DBI::Connected. So you only modify the local copy that is send by Apache::DBI.

Isn't it possible to change parameters of the cached handlers??

Am i missing someting?

Isn't it possible to affect directly the Apache::DBI object ?

Thanks a lot for your help monks.

Christophe

janitored by ybiC: <code> tags, as per Monastery convention


In reply to mod_perl ApacheDBI by lergot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.