Re: [INTERFACES] transactions in libpq++ require new connection?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: George Young <gry(at)ll(dot)mit(dot)edu>
Cc: pgsql-interfaces(at)postgreSQL(dot)org
Subject: Re: [INTERFACES] transactions in libpq++ require new connection?
Date: 1999-07-09 01:20:58
Message-ID: 1316.931483258@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

George Young <gry(at)ll(dot)mit(dot)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

Browse pgsql-interfaces by date

  From Date Subject
Next Message MAILER-DAEMON 1999-07-09 04:24:31 Undeliverable Message
Previous Message Tom Lane 1999-07-09 01:16:14 Re: [INTERFACES] Postgresql + lo