Back-patch fix for errors reported at transaction end.

This commit is contained in:
Tom Lane 2002-02-27 23:17:01 +00:00
parent 567f9d054f
commit b233e5903a

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.245.2.1 2002/02/26 23:48:45 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.245.2.2 2002/02/27 23:17:01 tgl Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
@ -645,6 +645,15 @@ pg_exec_query_string(char *query_string, /* string to execute */
/* Transaction control statements need some special handling */ /* Transaction control statements need some special handling */
isTransactionStmt = IsA(parsetree, TransactionStmt); isTransactionStmt = IsA(parsetree, TransactionStmt);
/*
* First we set the command-completion tag to the main query
* (as opposed to each of the others that may be generated by
* analyze and rewrite). Also set ps_status to the main query tag.
*/
commandTag = CreateCommandTag(parsetree);
set_ps_display(commandTag);
/* /*
* If we are in an aborted transaction, ignore all commands except * If we are in an aborted transaction, ignore all commands except
* COMMIT/ABORT. It is important that this test occur before we * COMMIT/ABORT. It is important that this test occur before we
@ -707,18 +716,7 @@ pg_exec_query_string(char *query_string, /* string to execute */
/* /*
* OK to analyze and rewrite this query. * OK to analyze and rewrite this query.
*/ *
/*
* First we set the command-completion tag to the main query
* (as opposed to each of the others that may be generated by
* analyze and rewrite). Also set ps_status to the main query tag.
*/
commandTag = CreateCommandTag(parsetree);
set_ps_display(commandTag);
/*
* Switch to appropriate context for constructing querytrees (again, * Switch to appropriate context for constructing querytrees (again,
* these must outlive the execution context). * these must outlive the execution context).
*/ */
@ -858,6 +856,22 @@ pg_exec_query_string(char *query_string, /* string to execute */
} /* end loop over queries generated from a } /* end loop over queries generated from a
* parsetree */ * parsetree */
/*
* If this is the last parsetree of the query string, close down
* transaction statement before reporting command-complete. This is
* so that any end-of-transaction errors are reported before the
* command-complete message is issued, to avoid confusing clients
* who will expect either a command-complete message or an error,
* not one and then the other. But for compatibility with
* historical Postgres behavior, we do not force a transaction
* boundary between queries appearing in a single query string.
*/
if (lnext(parsetree_item) == NIL && xact_started)
{
finish_xact_command();
xact_started = false;
}
/* /*
* It is possible that the original query was removed due to * It is possible that the original query was removed due to
* a DO INSTEAD rewrite rule. In that case we will still have * a DO INSTEAD rewrite rule. In that case we will still have
@ -877,13 +891,15 @@ pg_exec_query_string(char *query_string, /* string to execute */
* Tell client that we're done with this query. Note we emit * Tell client that we're done with this query. Note we emit
* exactly one EndCommand report for each raw parsetree, thus * exactly one EndCommand report for each raw parsetree, thus
* one for each SQL command the client sent, regardless of * one for each SQL command the client sent, regardless of
* rewriting. * rewriting. (But a command aborted by error will not send
* an EndCommand report at all.)
*/ */
EndCommand(commandTag, dest); EndCommand(commandTag, dest);
} /* end loop over parsetrees */ } /* end loop over parsetrees */
/* /*
* Close down transaction statement, if one is open. * Close down transaction statement, if one is open.
* (Note that this will only happen if the querystring was empty.)
*/ */
if (xact_started) if (xact_started)
finish_xact_command(); finish_xact_command();
@ -1688,7 +1704,7 @@ PostgresMain(int argc, char *argv[], const char *username)
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
{ {
puts("\nPOSTGRES backend interactive interface "); puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.245.2.1 $ $Date: 2002/02/26 23:48:45 $\n"); puts("$Revision: 1.245.2.2 $ $Date: 2002/02/27 23:17:01 $\n");
} }
/* /*