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

Function exec_stmt_close

src/pl/plpgsql/src/pl_exec.c:4848–4884  ·  view source on GitHub ↗

---------- * exec_stmt_close Close a cursor * ---------- */

Source from the content-addressed store, hash-verified

4846 * ----------
4847 */
4848static int
4849exec_stmt_close(PLpgSQL_execstate *estate, PLpgSQL_stmt_close *stmt)
4850{
4851 PLpgSQL_var *curvar;
4852 Portal portal;
4853 char *curname;
4854 MemoryContext oldcontext;
4855
4856 /* ----------
4857 * Get the portal of the cursor by name
4858 * ----------
4859 */
4860 curvar = (PLpgSQL_var *) (estate->datums[stmt->curvar]);
4861 if (curvar->isnull)
4862 ereport(ERROR,
4863 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4864 errmsg("cursor variable \"%s\" is null", curvar->refname)));
4865
4866 /* Use eval_mcontext for short-lived string */
4867 oldcontext = MemoryContextSwitchTo(get_eval_mcontext(estate));
4868 curname = TextDatumGetCString(curvar->value);
4869 MemoryContextSwitchTo(oldcontext);
4870
4871 portal = SPI_cursor_find(curname);
4872 if (portal == NULL)
4873 ereport(ERROR,
4874 (errcode(ERRCODE_UNDEFINED_CURSOR),
4875 errmsg("cursor \"%s\" does not exist", curname)));
4876
4877 /* ----------
4878 * And close it.
4879 * ----------
4880 */
4881 SPI_cursor_close(portal);
4882
4883 return PLPGSQL_RC_OK;
4884}
4885
4886/*
4887 * exec_stmt_commit

Callers 1

exec_stmtsFunction · 0.85

Calls 5

MemoryContextSwitchToFunction · 0.85
SPI_cursor_findFunction · 0.85
SPI_cursor_closeFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected