Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fdc60bd

Browse files
committed
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.
1 parent 36addaf commit fdc60bd

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/backend/tcop/postgres.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.249 2002/02/27 19:35:12 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.250 2002/02/27 23:16:07 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -859,6 +859,22 @@ pg_exec_query_string(char *query_string, /* string to execute */
859859
} /* end loop over queries generated from a
860860
* parsetree */
861861

862+
/*
863+
* If this is the last parsetree of the query string, close down
864+
* transaction statement before reporting command-complete. This is
865+
* so that any end-of-transaction errors are reported before the
866+
* command-complete message is issued, to avoid confusing clients
867+
* who will expect either a command-complete message or an error,
868+
* not one and then the other. But for compatibility with
869+
* historical Postgres behavior, we do not force a transaction
870+
* boundary between queries appearing in a single query string.
871+
*/
872+
if (lnext(parsetree_item) == NIL && xact_started)
873+
{
874+
finish_xact_command();
875+
xact_started = false;
876+
}
877+
862878
/*
863879
* It is possible that the original query was removed due to
864880
* 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 */
878894
* Tell client that we're done with this query. Note we emit
879895
* exactly one EndCommand report for each raw parsetree, thus
880896
* one for each SQL command the client sent, regardless of
881-
* rewriting.
897+
* rewriting. (But a command aborted by error will not send
898+
* an EndCommand report at all.)
882899
*/
883900
EndCommand(commandTag, dest);
884901
} /* end loop over parsetrees */
885902

886903
/*
887904
* Close down transaction statement, if one is open.
905+
* (Note that this will only happen if the querystring was empty.)
888906
*/
889907
if (xact_started)
890908
finish_xact_command();
@@ -1689,7 +1707,7 @@ PostgresMain(int argc, char *argv[], const char *username)
16891707
if (!IsUnderPostmaster)
16901708
{
16911709
puts("\nPOSTGRES backend interactive interface ");
1692-
puts("$Revision: 1.249 $ $Date: 2002/02/27 19:35:12 $\n");
1710+
puts("$Revision: 1.250 $ $Date: 2002/02/27 23:16:07 $\n");
16931711
}
16941712

16951713
/*

0 commit comments

Comments
 (0)