From 51844146e504931f0cfa1048e0ea3bbc4e8ea619 Mon Sep 17 00:00:00 2001 From: "Marc G. Fournier" Date: Wed, 12 Mar 1997 20:41:14 +0000 Subject: [PATCH] From: Dan McGuirk Subject: [HACKERS] abort failed transaction patch This patch allows you to end a transaction that has failed on an error using the 'ABORT' statement without generating another error message. (By default you get an error unless you use 'END' to terminate the transaction, which has already been aborted anyway.) --- src/backend/access/transam/xact.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index e58502ccaa..3cb49b8e27 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.6 1996/11/27 07:14:51 vadim Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.7 1997/03/12 20:41:14 scrappy Exp $ * * NOTES * Transaction aborts can now occur two ways: @@ -30,6 +30,7 @@ * default state. In case 2, there may be more commands coming * our way which are part of the same transaction block and we have * to ignore these commands until we see an END transaction. + * (or an ABORT! --djm) * * Internal aborts are now handled by AbortTransactionBlock(), just as * they always have been, and user aborts are now handled by @@ -1265,7 +1266,7 @@ AbortTransactionBlock(void) * state after the upcoming CommitTransactionCommand(). * ---------------- */ - elog(NOTICE, "AbortTransactionBlock and not inprogress state"); + elog(NOTICE, "AbortTransactionBlock and not in in-progress state"); AbortTransaction(); s->blockState = TBLOCK_ENDABORT; } @@ -1285,7 +1286,17 @@ UserAbortTransactionBlock() */ if (s->state == TRANS_DISABLED) return; - + + /* + * if the transaction has already been automatically aborted with an error, + * and the user subsequently types 'abort', allow it. (the behavior is + * the same as if they had typed 'end'.) + */ + if (s->blockState == TBLOCK_ABORT) { + s->blockState = TBLOCK_ENDABORT; + return; + } + if (s->blockState == TBLOCK_INPROGRESS) { /* ---------------- * here we were inside a transaction block and we @@ -1320,7 +1331,7 @@ UserAbortTransactionBlock() * state after the upcoming CommitTransactionCommand(). * ---------------- */ - elog(NOTICE, "UserAbortTransactionBlock and not inprogress state"); + elog(NOTICE, "UserAbortTransactionBlock and not in in-progress state"); AbortTransaction(); s->blockState = TBLOCK_ENDABORT; }