PostgreSQL Source Code git master
params.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ParamExternData
 
struct  ParamListInfoData
 
struct  ParamExecData
 
struct  ParamsErrorCbData
 

Macros

#define PARAM_FLAG_CONST   0x0001 /* parameter is constant */
 

Typedefs

typedef struct ExprState ExprState
 
typedef struct Param Param
 
typedef struct ParseState ParseState
 
typedef struct ParamExternData ParamExternData
 
typedef struct ParamListInfoDataParamListInfo
 
typedef ParamExternData *(* ParamFetchHook) (ParamListInfo params, int paramid, bool speculative, ParamExternData *workspace)
 
typedef void(* ParamCompileHook) (ParamListInfo params, Param *param, ExprState *state, Datum *resv, bool *resnull)
 
typedef void(* ParserSetupHook) (ParseState *pstate, void *arg)
 
typedef struct ParamListInfoData ParamListInfoData
 
typedef struct ParamExecData ParamExecData
 
typedef struct ParamsErrorCbData ParamsErrorCbData
 

Functions

ParamListInfo makeParamList (int numParams)
 
ParamListInfo copyParamList (ParamListInfo from)
 
Size EstimateParamListSpace (ParamListInfo paramLI)
 
void SerializeParamList (ParamListInfo paramLI, char **start_address)
 
ParamListInfo RestoreParamList (char **start_address)
 
char * BuildParamLogString (ParamListInfo params, char **knownTextValues, int maxlen)
 
void ParamsErrorCallback (void *arg)
 

Macro Definition Documentation

◆ PARAM_FLAG_CONST

#define PARAM_FLAG_CONST   0x0001 /* parameter is constant */

Definition at line 87 of file params.h.

Typedef Documentation

◆ ExprState

typedef struct ExprState ExprState

Definition at line 18 of file params.h.

◆ Param

typedef struct Param Param

Definition at line 19 of file params.h.

◆ ParamCompileHook

typedef void(* ParamCompileHook) (ParamListInfo params, Param *param, ExprState *state, Datum *resv, bool *resnull)

Definition at line 103 of file params.h.

◆ ParamExecData

typedef struct ParamExecData ParamExecData

◆ ParamExternData

◆ ParamFetchHook

typedef ParamExternData *(* ParamFetchHook) (ParamListInfo params, int paramid, bool speculative, ParamExternData *workspace)

Definition at line 99 of file params.h.

◆ ParamListInfo

Definition at line 97 of file params.h.

◆ ParamListInfoData

◆ ParamsErrorCbData

◆ ParserSetupHook

typedef void(* ParserSetupHook) (ParseState *pstate, void *arg)

Definition at line 107 of file params.h.

◆ ParseState

typedef struct ParseState ParseState

Definition at line 20 of file params.h.

Function Documentation

◆ BuildParamLogString()

char * BuildParamLogString ( ParamListInfo  params,
char **  knownTextValues,
int  maxlen 
)

Definition at line 333 of file params.c.

334{
335 MemoryContext tmpCxt,
336 oldCxt;
338
339 /*
340 * NB: think not of returning params->paramValuesStr! It may have been
341 * generated with a different maxlen, and so be unsuitable. Besides that,
342 * this is the function used to create that string.
343 */
344
345 /*
346 * No work if the param fetch hook is in use. Also, it's not possible to
347 * do this in an aborted transaction. (It might be possible to improve on
348 * this last point when some knownTextValues exist, but it seems tricky.)
349 */
350 if (params->paramFetch != NULL ||
352 return NULL;
353
354 /* Initialize the output stringinfo, in caller's memory context */
356
357 /* Use a temporary context to call output functions, just in case */
359 "BuildParamLogString",
361 oldCxt = MemoryContextSwitchTo(tmpCxt);
362
363 for (int paramno = 0; paramno < params->numParams; paramno++)
364 {
365 ParamExternData *param = &params->params[paramno];
366
368 "%s$%d = ",
369 paramno > 0 ? ", " : "",
370 paramno + 1);
371
372 if (param->isnull || !OidIsValid(param->ptype))
373 appendStringInfoString(&buf, "NULL");
374 else
375 {
376 if (knownTextValues != NULL && knownTextValues[paramno] != NULL)
377 appendStringInfoStringQuoted(&buf, knownTextValues[paramno],
378 maxlen);
379 else
380 {
381 Oid typoutput;
382 bool typisvarlena;
383 char *pstring;
384
385 getTypeOutputInfo(param->ptype, &typoutput, &typisvarlena);
386 pstring = OidOutputFunctionCall(typoutput, param->value);
387 appendStringInfoStringQuoted(&buf, pstring, maxlen);
388 }
389 }
390 }
391
392 MemoryContextSwitchTo(oldCxt);
393 MemoryContextDelete(tmpCxt);
394
395 return buf.data;
396}
#define OidIsValid(objectId)
Definition: c.h:777
char * OidOutputFunctionCall(Oid functionId, Datum val)
Definition: fmgr.c:1763
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
Definition: lsyscache.c:3074
MemoryContext CurrentMemoryContext
Definition: mcxt.c:160
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:469
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:160
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
static char * buf
Definition: pg_test_fsync.c:72
unsigned int Oid
Definition: postgres_ext.h:32
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:230
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
void appendStringInfoStringQuoted(StringInfo str, const char *s, int maxlen)
Definition: stringinfo_mb.c:34
bool isnull
Definition: params.h:92
Datum value
Definition: params.h:91
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
Definition: params.h:124
ParamFetchHook paramFetch
Definition: params.h:111
bool IsAbortedTransactionBlockState(void)
Definition: xact.c:408

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, appendStringInfo(), appendStringInfoString(), appendStringInfoStringQuoted(), buf, CurrentMemoryContext, getTypeOutputInfo(), initStringInfo(), IsAbortedTransactionBlockState(), ParamExternData::isnull, MemoryContextDelete(), MemoryContextSwitchTo(), ParamListInfoData::numParams, OidIsValid, OidOutputFunctionCall(), ParamListInfoData::paramFetch, ParamListInfoData::params, ParamExternData::ptype, and ParamExternData::value.

Referenced by errdetail_params(), exec_bind_message(), and ExplainQueryParameters().

◆ copyParamList()

ParamListInfo copyParamList ( ParamListInfo  from)

Definition at line 78 of file params.c.

79{
80 ParamListInfo retval;
81
82 if (from == NULL || from->numParams <= 0)
83 return NULL;
84
85 retval = makeParamList(from->numParams);
86
87 for (int i = 0; i < from->numParams; i++)
88 {
89 ParamExternData *oprm;
90 ParamExternData *nprm = &retval->params[i];
91 ParamExternData prmdata;
92 int16 typLen;
93 bool typByVal;
94
95 /* give hook a chance in case parameter is dynamic */
96 if (from->paramFetch != NULL)
97 oprm = from->paramFetch(from, i + 1, false, &prmdata);
98 else
99 oprm = &from->params[i];
100
101 /* flat-copy the parameter info */
102 *nprm = *oprm;
103
104 /* need datumCopy in case it's a pass-by-reference datatype */
105 if (nprm->isnull || !OidIsValid(nprm->ptype))
106 continue;
107 get_typlenbyval(nprm->ptype, &typLen, &typByVal);
108 nprm->value = datumCopy(nprm->value, typByVal, typLen);
109 }
110
111 return retval;
112}
int16_t int16
Definition: c.h:536
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:132
int i
Definition: isn.c:77
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition: lsyscache.c:2418
ParamListInfo makeParamList(int numParams)
Definition: params.c:44

References datumCopy(), get_typlenbyval(), i, ParamExternData::isnull, makeParamList(), ParamListInfoData::numParams, OidIsValid, ParamListInfoData::paramFetch, ParamListInfoData::params, ParamExternData::ptype, and ParamExternData::value.

Referenced by PerformCursorOpen(), and SPI_cursor_open_internal().

◆ EstimateParamListSpace()

Size EstimateParamListSpace ( ParamListInfo  paramLI)

Definition at line 167 of file params.c.

168{
169 Size sz = sizeof(int);
170
171 if (paramLI == NULL || paramLI->numParams <= 0)
172 return sz;
173
174 for (int i = 0; i < paramLI->numParams; i++)
175 {
176 ParamExternData *prm;
177 ParamExternData prmdata;
178 Oid typeOid;
179 int16 typLen;
180 bool typByVal;
181
182 /* give hook a chance in case parameter is dynamic */
183 if (paramLI->paramFetch != NULL)
184 prm = paramLI->paramFetch(paramLI, i + 1, false, &prmdata);
185 else
186 prm = &paramLI->params[i];
187
188 typeOid = prm->ptype;
189
190 sz = add_size(sz, sizeof(Oid)); /* space for type OID */
191 sz = add_size(sz, sizeof(uint16)); /* space for pflags */
192
193 /* space for datum/isnull */
194 if (OidIsValid(typeOid))
195 get_typlenbyval(typeOid, &typLen, &typByVal);
196 else
197 {
198 /* If no type OID, assume by-value, like copyParamList does. */
199 typLen = sizeof(Datum);
200 typByVal = true;
201 }
202 sz = add_size(sz,
203 datumEstimateSpace(prm->value, prm->isnull, typByVal, typLen));
204 }
205
206 return sz;
207}
uint16_t uint16
Definition: c.h:540
size_t Size
Definition: c.h:613
Size datumEstimateSpace(Datum value, bool isnull, bool typByVal, int typLen)
Definition: datum.c:412
uint64_t Datum
Definition: postgres.h:70
Size add_size(Size s1, Size s2)
Definition: shmem.c:495

References add_size(), datumEstimateSpace(), get_typlenbyval(), i, ParamExternData::isnull, ParamListInfoData::numParams, OidIsValid, ParamListInfoData::paramFetch, ParamListInfoData::params, ParamExternData::ptype, and ParamExternData::value.

Referenced by ExecInitParallelPlan().

◆ makeParamList()

ParamListInfo makeParamList ( int  numParams)

Definition at line 44 of file params.c.

45{
46 ParamListInfo retval;
47 Size size;
48
49 size = offsetof(ParamListInfoData, params) +
50 numParams * sizeof(ParamExternData);
51
52 retval = (ParamListInfo) palloc(size);
53 retval->paramFetch = NULL;
54 retval->paramFetchArg = NULL;
55 retval->paramCompile = NULL;
56 retval->paramCompileArg = NULL;
58 retval->parserSetupArg = retval;
59 retval->paramValuesStr = NULL;
60 retval->numParams = numParams;
61
62 return retval;
63}
void * palloc(Size size)
Definition: mcxt.c:1365
static void paramlist_parser_setup(ParseState *pstate, void *arg)
Definition: params.c:120
struct ParamListInfoData * ParamListInfo
Definition: params.h:97
struct ParamExternData ParamExternData
char * paramValuesStr
Definition: params.h:117
ParserSetupHook parserSetup
Definition: params.h:115
ParamCompileHook paramCompile
Definition: params.h:113
void * parserSetupArg
Definition: params.h:116
void * paramCompileArg
Definition: params.h:114
void * paramFetchArg
Definition: params.h:112

References ParamListInfoData::numParams, palloc(), ParamListInfoData::paramCompile, ParamListInfoData::paramCompileArg, ParamListInfoData::paramFetch, ParamListInfoData::paramFetchArg, paramlist_parser_setup(), ParamListInfoData::paramValuesStr, ParamListInfoData::parserSetup, and ParamListInfoData::parserSetupArg.

Referenced by _SPI_convert_params(), copyParamList(), EvaluateParams(), exec_bind_message(), exec_eval_using_params(), plpgsql_estate_setup(), postquel_sub_params(), and RestoreParamList().

◆ ParamsErrorCallback()

void ParamsErrorCallback ( void *  arg)

Definition at line 405 of file params.c.

406{
408
409 if (data == NULL ||
410 data->params == NULL ||
411 data->params->paramValuesStr == NULL)
412 return;
413
414 if (data->portalName && data->portalName[0] != '\0')
415 errcontext("portal \"%s\" with parameters: %s",
416 data->portalName, data->params->paramValuesStr);
417 else
418 errcontext("unnamed portal with parameters: %s",
419 data->params->paramValuesStr);
420}
#define errcontext
Definition: elog.h:198
void * arg
const void * data

References arg, data, and errcontext.

Referenced by exec_bind_message(), and exec_execute_message().

◆ RestoreParamList()

ParamListInfo RestoreParamList ( char **  start_address)

Definition at line 290 of file params.c.

291{
292 ParamListInfo paramLI;
293 int nparams;
294
295 memcpy(&nparams, *start_address, sizeof(int));
296 *start_address += sizeof(int);
297
298 paramLI = makeParamList(nparams);
299
300 for (int i = 0; i < nparams; i++)
301 {
302 ParamExternData *prm = &paramLI->params[i];
303
304 /* Read type OID. */
305 memcpy(&prm->ptype, *start_address, sizeof(Oid));
306 *start_address += sizeof(Oid);
307
308 /* Read flags. */
309 memcpy(&prm->pflags, *start_address, sizeof(uint16));
310 *start_address += sizeof(uint16);
311
312 /* Read datum/isnull. */
313 prm->value = datumRestore(start_address, &prm->isnull);
314 }
315
316 return paramLI;
317}
Datum datumRestore(char **start_address, bool *isnull)
Definition: datum.c:521
uint16 pflags
Definition: params.h:93

References datumRestore(), i, ParamExternData::isnull, makeParamList(), ParamListInfoData::params, ParamExternData::pflags, ParamExternData::ptype, and ParamExternData::value.

Referenced by ExecParallelGetQueryDesc().

◆ SerializeParamList()

void SerializeParamList ( ParamListInfo  paramLI,
char **  start_address 
)

Definition at line 228 of file params.c.

229{
230 int nparams;
231
232 /* Write number of parameters. */
233 if (paramLI == NULL || paramLI->numParams <= 0)
234 nparams = 0;
235 else
236 nparams = paramLI->numParams;
237 memcpy(*start_address, &nparams, sizeof(int));
238 *start_address += sizeof(int);
239
240 /* Write each parameter in turn. */
241 for (int i = 0; i < nparams; i++)
242 {
243 ParamExternData *prm;
244 ParamExternData prmdata;
245 Oid typeOid;
246 int16 typLen;
247 bool typByVal;
248
249 /* give hook a chance in case parameter is dynamic */
250 if (paramLI->paramFetch != NULL)
251 prm = paramLI->paramFetch(paramLI, i + 1, false, &prmdata);
252 else
253 prm = &paramLI->params[i];
254
255 typeOid = prm->ptype;
256
257 /* Write type OID. */
258 memcpy(*start_address, &typeOid, sizeof(Oid));
259 *start_address += sizeof(Oid);
260
261 /* Write flags. */
262 memcpy(*start_address, &prm->pflags, sizeof(uint16));
263 *start_address += sizeof(uint16);
264
265 /* Write datum/isnull. */
266 if (OidIsValid(typeOid))
267 get_typlenbyval(typeOid, &typLen, &typByVal);
268 else
269 {
270 /* If no type OID, assume by-value, like copyParamList does. */
271 typLen = sizeof(Datum);
272 typByVal = true;
273 }
274 datumSerialize(prm->value, prm->isnull, typByVal, typLen,
275 start_address);
276 }
277}
void datumSerialize(Datum value, bool isnull, bool typByVal, int typLen, char **start_address)
Definition: datum.c:459

References datumSerialize(), get_typlenbyval(), i, ParamExternData::isnull, ParamListInfoData::numParams, OidIsValid, ParamListInfoData::paramFetch, ParamListInfoData::params, ParamExternData::pflags, ParamExternData::ptype, and ParamExternData::value.

Referenced by ExecInitParallelPlan().