* Execute CALL statement * * Inside a top-level CALL statement, transaction-terminating commands such as * COMMIT or a PL-specific equivalent are allowed. The terminology in the SQL * standard is that CALL establishes a non-atomic execution context. Most * other commands establish an atomic execution context, in which transaction * control actions are not allowed. If there are nested exec
| 2722 | * commits that might occur inside the procedure. |
| 2723 | */ |
| 2724 | void |
| 2725 | ExecuteCallStmt(CallStmt *stmt, ParamListInfo params, bool atomic, DestReceiver *dest) |
| 2726 | { |
| 2727 | LOCAL_FCINFO(fcinfo, FUNC_MAX_ARGS); |
| 2728 | ListCell *lc; |
| 2729 | FuncExpr *fexpr; |
| 2730 | int nargs; |
| 2731 | int i; |
| 2732 | AclResult aclresult; |
| 2733 | FmgrInfo flinfo; |
| 2734 | CallContext *callcontext; |
| 2735 | EState *estate; |
| 2736 | ExprContext *econtext; |
| 2737 | HeapTuple tp; |
| 2738 | PgStat_FunctionCallUsage fcusage; |
| 2739 | Datum retval; |
| 2740 | |
| 2741 | fexpr = stmt->funcexpr; |
| 2742 | Assert(fexpr); |
| 2743 | Assert(IsA(fexpr, FuncExpr)); |
| 2744 | |
| 2745 | aclresult = pg_proc_aclcheck(fexpr->funcid, GetUserId(), ACL_EXECUTE); |
| 2746 | if (aclresult != ACLCHECK_OK) |
| 2747 | aclcheck_error(aclresult, OBJECT_PROCEDURE, get_func_name(fexpr->funcid)); |
| 2748 | |
| 2749 | /* Prep the context object we'll pass to the procedure */ |
| 2750 | callcontext = makeNode(CallContext); |
| 2751 | callcontext->atomic = atomic; |
| 2752 | |
| 2753 | tp = SearchSysCache1(PROCOID, ObjectIdGetDatum(fexpr->funcid)); |
| 2754 | if (!HeapTupleIsValid(tp)) |
| 2755 | elog(ERROR, "cache lookup failed for function %u", fexpr->funcid); |
| 2756 | |
| 2757 | /* |
| 2758 | * If proconfig is set we can't allow transaction commands because of the |
| 2759 | * way the GUC stacking works: The transaction boundary would have to pop |
| 2760 | * the proconfig setting off the stack. That restriction could be lifted |
| 2761 | * by redesigning the GUC nesting mechanism a bit. |
| 2762 | */ |
| 2763 | if (!heap_attisnull(tp, Anum_pg_proc_proconfig, NULL)) |
| 2764 | callcontext->atomic = true; |
| 2765 | |
| 2766 | /* |
| 2767 | * In security definer procedures, we can't allow transaction commands. |
| 2768 | * StartTransaction() insists that the security context stack is empty, |
| 2769 | * and AbortTransaction() resets the security context. This could be |
| 2770 | * reorganized, but right now it doesn't work. |
| 2771 | */ |
| 2772 | if (((Form_pg_proc) GETSTRUCT(tp))->prosecdef) |
| 2773 | callcontext->atomic = true; |
| 2774 | |
| 2775 | ReleaseSysCache(tp); |
| 2776 | |
| 2777 | /* safety check; see ExecInitFunc() */ |
| 2778 | nargs = list_length(fexpr->args); |
| 2779 | if (nargs > FUNC_MAX_ARGS) |
| 2780 | ereport(ERROR, |
| 2781 | (errcode(ERRCODE_TOO_MANY_ARGUMENTS), |
no test coverage detected