diff options
-rw-r--r-- | src/backend/tcop/postgres.c | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 717d4f76049..7a1b148edb8 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -8,7 +8,7 @@ * * * 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 * this is the "main" module of the postgres backend and @@ -646,6 +646,15 @@ pg_exec_query_string(char *query_string, /* string to execute */ 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 * COMMIT/ABORT. It is important that this test occur before we * try to do parse analysis, rewrite, or planning, since all those @@ -707,18 +716,7 @@ pg_exec_query_string(char *query_string, /* string to execute */ /* * 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, * these must outlive the execution context). */ @@ -859,6 +857,22 @@ pg_exec_query_string(char *query_string, /* string to execute */ * 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 * a DO INSTEAD rewrite rule. In that case we will still have * the default completion tag, which is fine for most purposes, @@ -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 * exactly one EndCommand report for each raw parsetree, thus * 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); } /* end loop over parsetrees */ /* * Close down transaction statement, if one is open. + * (Note that this will only happen if the querystring was empty.) */ if (xact_started) finish_xact_command(); @@ -1688,7 +1704,7 @@ PostgresMain(int argc, char *argv[], const char *username) if (!IsUnderPostmaster) { 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"); } /* |