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

Function SetResultVariables

src/bin/psql/common.c:412–441  ·  view source on GitHub ↗

* Set special variables from a query result * - ERROR: true/false, whether an error occurred on this query * - SQLSTATE: code of error, or "00000" if no error, or "" if unknown * - ROW_COUNT: how many rows were returned or affected, or "0" * - LAST_ERROR_SQLSTATE: same for last error * - LAST_ERROR_MESSAGE: message of last error * * Note: current policy is to apply this only to the results

Source from the content-addressed store, hash-verified

410 * entered by the user, not queries generated by slash commands.
411 */
412static void
413SetResultVariables(PGresult *results, bool success)
414{
415 if (success)
416 {
417 const char *ntuples = PQcmdTuples(results);
418
419 SetVariable(pset.vars, "ERROR", "false");
420 SetVariable(pset.vars, "SQLSTATE", "00000");
421 SetVariable(pset.vars, "ROW_COUNT", *ntuples ? ntuples : "0");
422 }
423 else
424 {
425 const char *code = PQresultErrorField(results, PG_DIAG_SQLSTATE);
426 const char *mesg = PQresultErrorField(results, PG_DIAG_MESSAGE_PRIMARY);
427
428 SetVariable(pset.vars, "ERROR", "true");
429
430 /*
431 * If there is no SQLSTATE code, use an empty string. This can happen
432 * for libpq-detected errors (e.g., lost connection, ENOMEM).
433 */
434 if (code == NULL)
435 code = "";
436 SetVariable(pset.vars, "SQLSTATE", code);
437 SetVariable(pset.vars, "ROW_COUNT", "0");
438 SetVariable(pset.vars, "LAST_ERROR_SQLSTATE", code);
439 SetVariable(pset.vars, "LAST_ERROR_MESSAGE", mesg ? mesg : "");
440 }
441}
442
443
444/*

Callers 3

ProcessResultFunction · 0.85
DescribeQueryFunction · 0.85
ExecQueryUsingCursorFunction · 0.85

Calls 3

PQcmdTuplesFunction · 0.85
SetVariableFunction · 0.85
PQresultErrorFieldFunction · 0.85

Tested by

no test coverage detected