MCPcopy Create free account
hub / github.com/apache/cloudberry / PrintQueryResults

Function PrintQueryResults

src/bin/psql/common.c:1114–1174  ·  view source on GitHub ↗

* PrintQueryResults: print out (or store or execute) query results as required * * Note: Utility function for use by SendQuery() only. * * Returns true if the query executed successfully, false otherwise. */

Source from the content-addressed store, hash-verified

1112 * Returns true if the query executed successfully, false otherwise.
1113 */
1114static bool
1115PrintQueryResults(PGresult *results)
1116{
1117 bool success;
1118 const char *cmdstatus;
1119
1120 if (!results)
1121 return false;
1122
1123 switch (PQresultStatus(results))
1124 {
1125 case PGRES_TUPLES_OK:
1126 /* store or execute or print the data ... */
1127 if (pset.gset_prefix)
1128 success = StoreQueryTuple(results);
1129 else if (pset.gexec_flag)
1130 success = ExecQueryTuples(results);
1131 else if (pset.crosstab_flag)
1132 success = PrintResultsInCrosstab(results);
1133 else
1134 success = PrintQueryTuples(results);
1135 /* if it's INSERT/UPDATE/DELETE RETURNING, also print status */
1136 cmdstatus = PQcmdStatus(results);
1137 if (strncmp(cmdstatus, "INSERT", 6) == 0 ||
1138 strncmp(cmdstatus, "UPDATE", 6) == 0 ||
1139 strncmp(cmdstatus, "DELETE", 6) == 0)
1140 PrintQueryStatus(results);
1141 break;
1142
1143 case PGRES_COMMAND_OK:
1144 PrintQueryStatus(results);
1145 success = true;
1146 break;
1147
1148 case PGRES_EMPTY_QUERY:
1149 success = true;
1150 break;
1151
1152 case PGRES_COPY_OUT:
1153 case PGRES_COPY_IN:
1154 /* nothing to do here */
1155 success = true;
1156 break;
1157
1158 case PGRES_BAD_RESPONSE:
1159 case PGRES_NONFATAL_ERROR:
1160 case PGRES_FATAL_ERROR:
1161 success = false;
1162 break;
1163
1164 default:
1165 success = false;
1166 pg_log_error("unexpected PQresultStatus: %d",
1167 PQresultStatus(results));
1168 break;
1169 }
1170
1171 fflush(pset.queryFout);

Callers 2

SendQueryFunction · 0.85
DescribeQueryFunction · 0.85

Calls 7

PQresultStatusFunction · 0.85
StoreQueryTupleFunction · 0.85
ExecQueryTuplesFunction · 0.85
PrintResultsInCrosstabFunction · 0.85
PrintQueryTuplesFunction · 0.85
PQcmdStatusFunction · 0.85
PrintQueryStatusFunction · 0.85

Tested by

no test coverage detected