1 /*-------------------------------------------------------------------------
4 * Support for finding the values associated with Param nodes.
7 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
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.
29 copyParamList(ParamListInfo from
)
35 if (from
== NULL
|| from
->numParams
<= 0)
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
];
55 if (prm
->isnull
|| !OidIsValid(prm
->ptype
))
57 get_typlenbyval(prm
->ptype
, &typLen
, &typByVal
);
58 prm
->value
= datumCopy(prm
->value
, typByVal
, typLen
);
65 * Extract an array of parameter type OIDs from a ParamListInfo.
67 * The result is allocated in CurrentMemoryContext.
70 getParamListTypes(ParamListInfo params
,
71 Oid
**param_types
, int *num_params
)
76 if (params
== NULL
|| params
->numParams
<= 0)
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
= ¶ms
->params
[i
];
91 ptypes
[i
] = prm
->ptype
;