---------- * exec_stmt_close Close a cursor * ---------- */
| 4846 | * ---------- |
| 4847 | */ |
| 4848 | static int |
| 4849 | exec_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 |
no test coverage detected