Tweak pg_exec_query_string so that we close down transaction command

before reporting command-complete message for the final command of a
query string.  This way, any errors detected during finish_xact_command
(such as RI violations) will appear to be part of the final command,
rather than coming out after the command is reported complete.  This
avoids confusing PQendcopy and other not-overly-bright clients.
Per Lee Harr's bug report of 25-Feb-02.
This commit is contained in:
Tom Lane 2002-02-27 23:16:07 +00:00
parent 36addaff3d
commit fdc60bd9d9
1 changed files with 21 additions and 3 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.249 2002/02/27 19:35:12 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.250 2002/02/27 23:16:07 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
@ -859,6 +859,22 @@ pg_exec_query_string(char *query_string, /* string to execute */
} /* end loop over queries generated from a
* 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
@ -878,13 +894,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();
@ -1689,7 +1707,7 @@ PostgresMain(int argc, char *argv[], const char *username)
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.249 $ $Date: 2002/02/27 19:35:12 $\n");
puts("$Revision: 1.250 $ $Date: 2002/02/27 23:16:07 $\n");
}
/*