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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [INTERFACES] transactions in libpq++ require new connection?
Дата
Msg-id 1316.931483258@sss.pgh.pa.us
обсуждение исходный текст
Ответ на transactions in libpq++ require new connection?  (George Young <gry@ll.mit.edu>)
Список 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 по дате отправления:

Предыдущее
От: Rachel Greenham
Дата:
Сообщение: JDBC problem - again
Следующее
От: leif@danmos.dk
Дата:
Сообщение: [INTERFACES] Error from backend. Was: MSAccess problem deleting rows