Re: [INTERFACES] transactions in libpq++ require new connection? - Mailing list pgsql-interfaces

From Tom Lane
Subject Re: [INTERFACES] transactions in libpq++ require new connection?
Date
Msg-id 1316.931483258@sss.pgh.pa.us
Whole thread Raw
In response to transactions in libpq++ require new connection?  (George Young <gry@ll.mit.edu>)
List pgsql-interfaces
George Young <gry@ll.mit.edu> writes:
> Currently, the PgTransaction class only has a public constructor which
> opens a new connection to the DB, and closes it on commit.

Ugh.  I agree that's pretty awful.

> I know I can roll my own by just Exec("begin"), etc, but having the
> transaction *committed* (not conn closed) in the destructor would be very
> handy.
> Also, there's no rollback member...

Actually, I think the cleanest design would be to have a commit() member
function.  If the object is destroyed without having committed, the
default behavior ought to be to abort (rollback), not commit.  The
reason I think this is that if you imagine a PgTransaction object that
is local to a function, and the function is exited by an exception,
you probably want abort to happen rather than commit.

There might be some cases where you'd rather it worked the other way
around --- if so, we could have a constructor option to set the default
behavior at destruct time.  But I think defaulting to abort would be the
safest behavior for a program that uses exceptions.
        regards, tom lane



pgsql-interfaces by date:

Previous
From: Rachel Greenham
Date:
Subject: JDBC problem - again
Next
From: leif@danmos.dk
Date:
Subject: [INTERFACES] Error from backend. Was: MSAccess problem deleting rows