General database programming question

From: Denis Gasparin <denis(at)edinet(dot)it>
To: PostgreSQL-general <pgsql-general(at)postgresql(dot)org>
Subject: General database programming question
Date: 2001-09-13 10:43:14
Message-ID: 5.1.0.14.0.20010913090436.00a7f2f0@10.1.1.2
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi to all!
I want to ask a general database programming question. Here it is...
In a programming language that handles exceptions, where I have to put the
db.commit/db.rollback statement? These are some solutions...

//db is a generic database connection object

/* SOLUTION 1 */
db.begin(); //begin transaction
try:
db.query("UPDATE...."); //Execute a db query
db.commit(); //commit changes to database
except:
//the query has generated an exception
db.rollback();

/* SOLUTION 2 */
db.begin(); //begin transaction
try:
db.query("UPDATE...."); //Execute a db query
except:
//the query has generated an exception
db.rollback();
else:
//Here executes only if there are no exceptions in try statement
db.commit(); //commit changes to database

Which is the best solution according to your experience? Is there others
different solutions?

Thank for the tips...
Regards,

Eng. Denis Gasparin: denis(at)edistar(dot)com
---------------------------
Programmer & System Administrator - Edistar srl

Responses

Browse pgsql-general by date

  From Date Subject
Next Message R Talbot 2001-09-13 11:13:23 Re: Is Perl compiled into Version?
Previous Message Lynn Holt 2001-09-13 06:19:05 Re: pg_dump problem