1 /*-------------------------------------------------------------------------
4 * Support for finding the values associated with Param nodes.
7 * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/backend/nodes/params.c
13 *-------------------------------------------------------------------------
18 #include "nodes/params.h"
19 #include "utils/datum.h"
20 #include "utils/lsyscache.h"
24 * Copy a ParamListInfo structure.
26 * The result is allocated in CurrentMemoryContext.
28 * Note: the intent of this function is to make a static, self-contained
29 * set of parameter values. If dynamic parameter hooks are present, we
30 * intentionally do not copy them into the result. Rather, we forcibly
31 * instantiate all available parameter values and copy the datum values.
34 copyParamList(ParamListInfo from)
40 if (from == NULL || from->numParams <= 0)
43 /* sizeof(ParamListInfoData) includes the first array element */
44 size = sizeof(ParamListInfoData) +
45 (from->numParams - 1) * sizeof(ParamExternData);
47 retval = (ParamListInfo) palloc(size);
48 retval->paramFetch = NULL;
49 retval->paramFetchArg = NULL;
50 retval->parserSetup = NULL;
51 retval->parserSetupArg = NULL;
52 retval->numParams = from->numParams;
54 for (i = 0; i < from->numParams; i++)
56 ParamExternData *oprm = &from->params[i];
57 ParamExternData *nprm = &retval->params[i];
61 /* give hook a chance in case parameter is dynamic */
62 if (!OidIsValid(oprm->ptype) && from->paramFetch != NULL)
63 (*from->paramFetch) (from, i + 1);
65 /* flat-copy the parameter info */
68 /* need datumCopy in case it's a pass-by-reference datatype */
69 if (nprm->isnull || !OidIsValid(nprm->ptype))
71 get_typlenbyval(nprm->ptype, &typLen, &typByVal);
72 nprm->value = datumCopy(nprm->value, typByVal, typLen);