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

Function StoreQueryTuple

src/bin/psql/common.c:761–816  ·  view source on GitHub ↗

* StoreQueryTuple: assuming query result is OK, save data into variables * * Returns true if successful, false otherwise. */

Source from the content-addressed store, hash-verified

759 * Returns true if successful, false otherwise.
760 */
761static bool
762StoreQueryTuple(const PGresult *result)
763{
764 bool success = true;
765
766 if (PQntuples(result) < 1)
767 {
768 pg_log_error("no rows returned for \\gset");
769 success = false;
770 }
771 else if (PQntuples(result) > 1)
772 {
773 pg_log_error("more than one row returned for \\gset");
774 success = false;
775 }
776 else
777 {
778 int i;
779
780 for (i = 0; i < PQnfields(result); i++)
781 {
782 char *colname = PQfname(result, i);
783 char *varname;
784 char *value;
785
786 /* concatenate prefix and column name */
787 varname = psprintf("%s%s", pset.gset_prefix, colname);
788
789 if (VariableHasHook(pset.vars, varname))
790 {
791 pg_log_warning("attempt to \\gset into specially treated variable \"%s\" ignored",
792 varname);
793 continue;
794 }
795
796 if (!PQgetisnull(result, 0, i))
797 value = PQgetvalue(result, 0, i);
798 else
799 {
800 /* for NULL value, unset rather than set the variable */
801 value = NULL;
802 }
803
804 if (!SetVariable(pset.vars, varname, value))
805 {
806 free(varname);
807 success = false;
808 break;
809 }
810
811 free(varname);
812 }
813 }
814
815 return success;
816}
817
818

Callers 2

PrintQueryResultsFunction · 0.85
ExecQueryUsingCursorFunction · 0.85

Calls 8

PQntuplesFunction · 0.85
PQnfieldsFunction · 0.85
PQfnameFunction · 0.85
psprintfFunction · 0.85
VariableHasHookFunction · 0.85
PQgetisnullFunction · 0.85
PQgetvalueFunction · 0.85
SetVariableFunction · 0.85

Tested by

no test coverage detected