Re: Error on failed COMMIT

Поиск
Список
Период
Сортировка
От Dave Cramer
Тема Re: Error on failed COMMIT
Дата
Msg-id CADK3HHLa1NXEFosiSe=-Kg4aMdnJ-wLgkZdXA2zEP=pw8Njcgw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Error on failed COMMIT  (Robert Haas <robertmhaas@gmail.com>)
Список pgsql-hackers



If we did change the server behavior, it seems unlikely that
every driver would adjust their behavior to the new server behavior
all at once and that they would all get it right while also all
preserving backward compatibility with current releases in case a
newer driver is used with an older server. I don't think that's
likely. What would probably happen is that many drivers would ignore
the change, leaving applications to cope with the differences between
server versions, and some would change the driver behavior
categorically, breaking compatibility with older server versions, and
some would make mistakes in implementing support for the new behavior.
And maybe we would also find that the new behavior isn't ideal for
everybody any more than the current behavior is ideal for everybody.

To test how the driver would currently react if the server did respond with an error I made a small change 

diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 0a6f80963b..9405b0cfd9 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -2666,8 +2666,7 @@ IsTransactionExitStmt(Node *parsetree)
        {
                TransactionStmt *stmt = (TransactionStmt *) parsetree;

-               if (stmt->kind == TRANS_STMT_COMMIT ||
-                       stmt->kind == TRANS_STMT_PREPARE ||
+               if (stmt->kind == TRANS_STMT_PREPARE ||
                        stmt->kind == TRANS_STMT_ROLLBACK ||
                        stmt->kind == TRANS_STMT_ROLLBACK_TO)
                        return true;

I have no idea how badly this breaks other things but it does throw an error on commit if the transaction is in error.
With absolutely no changes to the driver this code does what I would expect and executes the conn.rollback()

try {
conn.setAutoCommit(false);
try {
conn.createStatement().execute("insert into notnullable values (NULL)");
} catch (SQLException ex ) {
ex.printStackTrace();
//ignore this exception
}
conn.commit();
} catch ( SQLException ex ) {
ex.printStackTrace();
conn.rollback();
}
conn.close();
Dave Cramer



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Dave Cramer
Дата:
Сообщение: Re: Error on failed COMMIT
Следующее
От: Shay Rojansky
Дата:
Сообщение: Re: Error on failed COMMIT