Re: Pg + perl + apache - Mailing list pgsql-general

From Lincoln Yeoh
Subject Re: Pg + perl + apache
Date
Msg-id 5.2.1.1.1.20040218181941.02755b60@mbox.jaring.my
Whole thread Raw
In response to Re: Pg + perl + apache  ("Michael L. Artz" <dragon@october29.net>)
Responses Re: Pg + perl + apache  ("Greg Sabino Mullane" <greg@turnstep.com>)
List pgsql-general
You could try something like this:

Assuming you are using perl+DBI (as per your examples).

If you are using modperl:
[modperl can override the "connect to db" for connection reuse/pooling]

begin cgi web app:
connect to db
rollback
do stuff
do more stuff
commit if ok
by default rollback
disconnect.

If you are using fastcgi:
[fastcgi - explicit DB connection reuse]
connect to db
while (fastcgi connection) {
  rollback
  do stuff
  do more stuff
  commit if ok
  by default rollback
}
rollback
disconnect

You probably want to do a rollback before you do stuff so that the
transaction times are correct. AFAIK Perl DBI automatically does a BEGIN
after a rollback or commit, so if the previous transaction was rolled back
or committed 1 hour ago, you'd be reusing a transaction that begun 1 hour
ago for something that's happening now.

This would cause select 'now'::timestamp or SELECT CURRENT_TIMESTAMP return
times that are 1 hour ago, which is usually not what you want.

Hope that helps,
At 12:40 AM 2/16/2004 -0500, Michael L. Artz wrote:

>Thanks, that did help to debug the application.  I found that my errors
>weren't so random after all ... if I went to a page with a bad query, then
>I would start getting the error.
>
>should throw an error for *both* queries?  So I guess I need to issue a
>commit after I do my queries, or else turn autocommit on.



pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Grant / Revoke functionality
Next
From: Lincoln Yeoh
Date:
Subject: Re: PostgreSQL Indexing versus MySQL