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

Function pqBuildErrorMessage3

src/interfaces/libpq/fe-protocol3.c:1182–1345  ·  view source on GitHub ↗

* Construct an error message from the fields in the given PGresult, * appending it to the contents of "msg". */

Source from the content-addressed store, hash-verified

1180 * appending it to the contents of "msg".
1181 */
1182void
1183pqBuildErrorMessage3(PQExpBuffer msg, const PGresult *res,
1184 PGVerbosity verbosity, PGContextVisibility show_context)
1185{
1186 const char *val;
1187 const char *querytext = NULL;
1188 int querypos = 0;
1189
1190 /* If we couldn't allocate a PGresult, just say "out of memory" */
1191 if (res == NULL)
1192 {
1193 appendPQExpBufferStr(msg, libpq_gettext("out of memory\n"));
1194 return;
1195 }
1196
1197 /*
1198 * If we don't have any broken-down fields, just return the base message.
1199 * This mainly applies if we're given a libpq-generated error result.
1200 */
1201 if (res->errFields == NULL)
1202 {
1203 if (res->errMsg && res->errMsg[0])
1204 appendPQExpBufferStr(msg, res->errMsg);
1205 else
1206 appendPQExpBufferStr(msg, libpq_gettext("no error message available\n"));
1207 return;
1208 }
1209
1210 /* Else build error message from relevant fields */
1211 val = PQresultErrorField(res, PG_DIAG_SEVERITY);
1212 if (val)
1213 appendPQExpBuffer(msg, "%s: ", val);
1214
1215 if (verbosity == PQERRORS_SQLSTATE)
1216 {
1217 /*
1218 * If we have a SQLSTATE, print that and nothing else. If not (which
1219 * shouldn't happen for server-generated errors, but might possibly
1220 * happen for libpq-generated ones), fall back to TERSE format, as
1221 * that seems better than printing nothing at all.
1222 */
1223 val = PQresultErrorField(res, PG_DIAG_SQLSTATE);
1224 if (val)
1225 {
1226 appendPQExpBuffer(msg, "%s\n", val);
1227 return;
1228 }
1229 verbosity = PQERRORS_TERSE;
1230 }
1231
1232 if (verbosity == PQERRORS_VERBOSE)
1233 {
1234 val = PQresultErrorField(res, PG_DIAG_SQLSTATE);
1235 if (val)
1236 appendPQExpBuffer(msg, "%s: ", val);
1237 }
1238 val = PQresultErrorField(res, PG_DIAG_MESSAGE_PRIMARY);
1239 if (val)

Callers 2

pqGetErrorNotice3Function · 0.85

Calls 6

appendPQExpBufferStrFunction · 0.85
libpq_gettextFunction · 0.85
PQresultErrorFieldFunction · 0.85
appendPQExpBufferFunction · 0.85
appendPQExpBufferCharFunction · 0.85
reportErrorPositionFunction · 0.85

Tested by

no test coverage detected