Remove the encoding *numbers* from the comments. They are useless, and
[PostgreSQL.git] / src / backend / nodes / params.c
blob2f1b1cbc8d992c7432f8db5459daa26346e699fe
1 /*-------------------------------------------------------------------------
3 * params.c
4 * Support for finding the values associated with Param nodes.
7 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * IDENTIFICATION
11 * $PostgreSQL$
13 *-------------------------------------------------------------------------
16 #include "postgres.h"
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 ParamListInfo
29 copyParamList(ParamListInfo from)
31 ParamListInfo retval;
32 Size size;
33 int i;
35 if (from == NULL || from->numParams <= 0)
36 return NULL;
38 /* sizeof(ParamListInfoData) includes the first array element */
39 size = sizeof(ParamListInfoData) +
40 (from->numParams - 1) *sizeof(ParamExternData);
42 retval = (ParamListInfo) palloc(size);
43 memcpy(retval, from, size);
46 * Flat-copy is not good enough for pass-by-ref data values, so make a
47 * pass over the array to copy those.
49 for (i = 0; i < retval->numParams; i++)
51 ParamExternData *prm = &retval->params[i];
52 int16 typLen;
53 bool typByVal;
55 if (prm->isnull || !OidIsValid(prm->ptype))
56 continue;
57 get_typlenbyval(prm->ptype, &typLen, &typByVal);
58 prm->value = datumCopy(prm->value, typByVal, typLen);
61 return retval;
65 * Extract an array of parameter type OIDs from a ParamListInfo.
67 * The result is allocated in CurrentMemoryContext.
69 void
70 getParamListTypes(ParamListInfo params,
71 Oid **param_types, int *num_params)
73 Oid *ptypes;
74 int i;
76 if (params == NULL || params->numParams <= 0)
78 *param_types = NULL;
79 *num_params = 0;
80 return;
83 ptypes = (Oid *) palloc(params->numParams * sizeof(Oid));
84 *param_types = ptypes;
85 *num_params = params->numParams;
87 for (i = 0; i < params->numParams; i++)
89 ParamExternData *prm = &params->params[i];
91 ptypes[i] = prm->ptype;