Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb475d25

Browse files
committed
Cause psql to report both the returned data and the command status tag
for INSERT/UPDATE/DELETE RETURNING. Per discussion.
1 parentfbc7f59 commitb475d25

File tree

1 file changed

+42
-24
lines changed

1 file changed

+42
-24
lines changed

‎src/bin/psql/common.c

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2006, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.123 2006/08/11 19:20:59 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.124 2006/08/13 21:10:04 tgl Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"common.h"
@@ -683,6 +683,36 @@ ProcessCopyResult(PGresult *results)
683683
}
684684

685685

686+
/*
687+
* PrintQueryStatus: report command status as required
688+
*
689+
* Note: Utility function for use by PrintQueryResults() only.
690+
*/
691+
staticvoid
692+
PrintQueryStatus(PGresult*results)
693+
{
694+
charbuf[16];
695+
696+
if (!QUIET())
697+
{
698+
if (pset.popt.topt.format==PRINT_HTML)
699+
{
700+
fputs("<p>",pset.queryFout);
701+
html_escaped_print(PQcmdStatus(results),pset.queryFout);
702+
fputs("</p>\n",pset.queryFout);
703+
}
704+
else
705+
fprintf(pset.queryFout,"%s\n",PQcmdStatus(results));
706+
}
707+
708+
if (pset.logfile)
709+
fprintf(pset.logfile,"%s\n",PQcmdStatus(results));
710+
711+
snprintf(buf,sizeof(buf),"%u", (unsignedint)PQoidValue(results));
712+
SetVariable(pset.vars,"LASTOID",buf);
713+
}
714+
715+
686716
/*
687717
* PrintQueryResults: print out query results as required
688718
*
@@ -694,40 +724,28 @@ static bool
694724
PrintQueryResults(PGresult*results)
695725
{
696726
boolsuccess= false;
727+
constchar*cmdstatus;
697728

698729
if (!results)
699730
return false;
700731

701732
switch (PQresultStatus(results))
702733
{
703734
casePGRES_TUPLES_OK:
735+
/* print the data ... */
704736
success=PrintQueryTuples(results);
737+
/* if it's INSERT/UPDATE/DELETE RETURNING, also print status */
738+
cmdstatus=PQcmdStatus(results);
739+
if (strncmp(cmdstatus,"INSERT",6)==0||
740+
strncmp(cmdstatus,"UPDATE",6)==0||
741+
strncmp(cmdstatus,"DELETE",6)==0)
742+
PrintQueryStatus(results);
705743
break;
706744

707745
casePGRES_COMMAND_OK:
708-
{
709-
charbuf[10];
710-
711-
success= true;
712-
snprintf(buf,sizeof(buf),
713-
"%u", (unsignedint)PQoidValue(results));
714-
if (!QUIET())
715-
{
716-
if (pset.popt.topt.format==PRINT_HTML)
717-
{
718-
fputs("<p>",pset.queryFout);
719-
html_escaped_print(PQcmdStatus(results),
720-
pset.queryFout);
721-
fputs("</p>\n",pset.queryFout);
722-
}
723-
else
724-
fprintf(pset.queryFout,"%s\n",PQcmdStatus(results));
725-
}
726-
if (pset.logfile)
727-
fprintf(pset.logfile,"%s\n",PQcmdStatus(results));
728-
SetVariable(pset.vars,"LASTOID",buf);
729-
break;
730-
}
746+
PrintQueryStatus(results);
747+
success= true;
748+
break;
731749

732750
casePGRES_EMPTY_QUERY:
733751
success= true;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp