From: | "Matthew O(dot) Persico" <persicom(at)acedsl(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: General database programming question |
Date: | 2001-09-14 02:27:25 |
Message-ID: | 3BA16B0D.CF109315@acedsl.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Denis Gasparin wrote:
>
Use this:
> //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();
>
because it will catch any problem with the commit. Solution #2 won't.
Of course the ultimate solution is this (syntax altered for clarity,
assuming this is pseudocode anyway):
/* SOLUTION 3 */
db.begin(); //begin transaction
try{
db.query("UPDATE...."); //Execute a db query
db.commit(); //commit changes to database
}
except{
try{
//the query has generated an exception
db.rollback();
}
except{
// You're hosed. Leave and hope for the best
exit;
}
}
if your language allows "nested" try/exception blocks.
--
Matthew O. Persico
http://www.acecape.com/dsl
AceDSL:The best ADSL in Verizon area
From | Date | Subject | |
---|---|---|---|
Next Message | Mike S. Nowostawsky | 2001-09-14 03:44:29 | get certain # of recs |
Previous Message | peace_flower | 2001-09-14 01:57:34 | Where do they find the time??? Great Bridge closed now!!!?? |