mod_perl ApacheDBI AutoCommit

Discussion in 'Perl Misc' started by Christophe Goer, Nov 12, 2003.

  1. Hello,

    I'm facing quite a big problem since i started to use ApacheDBI with
    mod_perl and Apache.

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

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

    I used to open connection 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 EmilSignal 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.

    by 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}, 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.

    Am i missing someting?

    Thanks a lot for your help

    Christophe
     
    Christophe Goer, Nov 12, 2003
    #1
    1. Advertising

  2. 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??

    Christophe


    Christophe Goer wrote:
    > Hello,
    >
    > I'm facing quite a big problem since i started to use ApacheDBI with
    > mod_perl and Apache.
    >
    > I'm working on Apache 1.3 with mod_perl and Postgres 7.2.
    >
    > before ApacheDBI, I was caching my $dbh with an home made singleton object.
    >
    > I used to open connection 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 EmilSignal 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.
    >
    > by 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}, 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.
    >
    > Am i missing someting?
    >
    > Thanks a lot for your help
    >
    > Christophe
    >
     
    Christophe Goer, Nov 12, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maruda
    Replies:
    1
    Views:
    1,729
    John C. Bollinger
    Dec 31, 2005
  2. Chris

    MySql autocommit off?

    Chris, Jul 15, 2003, in forum: Python
    Replies:
    0
    Views:
    976
    Chris
    Jul 15, 2003
  3. Jia Lu
    Replies:
    2
    Views:
    513
    Jia Lu
    Dec 1, 2006
  4. Paul McNett
    Replies:
    1
    Views:
    363
    Gerhard Häring
    Feb 5, 2008
  5. Replies:
    2
    Views:
    456
    Big and Blue
    Jan 25, 2006
Loading...

Share This Page