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

Function exec_eval_using_params

src/pl/plpgsql/src/pl_exec.c:8496–8568  ·  view source on GitHub ↗

* exec_eval_using_params --- evaluate params of USING clause * * The result data structure is created in the stmt_mcontext, and should * be freed by resetting that context. */

Source from the content-addressed store, hash-verified

8494 * be freed by resetting that context.
8495 */
8496static ParamListInfo
8497exec_eval_using_params(PLpgSQL_execstate *estate, List *params)
8498{
8499 ParamListInfo paramLI;
8500 int nargs;
8501 MemoryContext stmt_mcontext;
8502 MemoryContext oldcontext;
8503 int i;
8504 ListCell *lc;
8505
8506 /* Fast path for no parameters: we can just return NULL */
8507 if (params == NIL)
8508 return NULL;
8509
8510 nargs = list_length(params);
8511 stmt_mcontext = get_stmt_mcontext(estate);
8512 oldcontext = MemoryContextSwitchTo(stmt_mcontext);
8513 paramLI = makeParamList(nargs);
8514 MemoryContextSwitchTo(oldcontext);
8515
8516 i = 0;
8517 foreach(lc, params)
8518 {
8519 PLpgSQL_expr *param = (PLpgSQL_expr *) lfirst(lc);
8520 ParamExternData *prm = &paramLI->params[i];
8521 int32 ppdtypmod;
8522
8523 /*
8524 * Always mark params as const, since we only use the result with
8525 * one-shot plans.
8526 */
8527 prm->pflags = PARAM_FLAG_CONST;
8528
8529 prm->value = exec_eval_expr(estate, param,
8530 &prm->isnull,
8531 &prm->ptype,
8532 &ppdtypmod);
8533
8534 oldcontext = MemoryContextSwitchTo(stmt_mcontext);
8535
8536 if (prm->ptype == UNKNOWNOID)
8537 {
8538 /*
8539 * Treat 'unknown' parameters as text, since that's what most
8540 * people would expect. The SPI functions can coerce unknown
8541 * constants in a more intelligent way, but not unknown Params.
8542 * This code also takes care of copying into the right context.
8543 * Note we assume 'unknown' has the representation of C-string.
8544 */
8545 prm->ptype = TEXTOID;
8546 if (!prm->isnull)
8547 prm->value = CStringGetTextDatum(DatumGetCString(prm->value));
8548 }
8549 /* pass-by-ref non null values must be copied into stmt_mcontext */
8550 else if (!prm->isnull)
8551 {
8552 int16 typLen;
8553 bool typByVal;

Callers 3

exec_stmt_return_queryFunction · 0.85
exec_stmt_dynexecuteFunction · 0.85

Calls 10

list_lengthFunction · 0.85
get_stmt_mcontextFunction · 0.85
MemoryContextSwitchToFunction · 0.85
makeParamListFunction · 0.85
exec_eval_exprFunction · 0.85
DatumGetCStringFunction · 0.85
get_typlenbyvalFunction · 0.85
datumCopyFunction · 0.85
exec_eval_cleanupFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected