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

Function convert_prep_stmt_params

contrib/postgres_fdw/postgres_fdw.c:4263–4333  ·  view source on GitHub ↗

* convert_prep_stmt_params * Create array of text strings representing parameter values * * tupleid is ctid to send, or NULL if none * slot is slot to get remaining parameters from, or NULL if none * * Data is constructed in temp_cxt; caller should reset that after use. */

Source from the content-addressed store, hash-verified

4261 * Data is constructed in temp_cxt; caller should reset that after use.
4262 */
4263static const char **
4264convert_prep_stmt_params(PgFdwModifyState *fmstate,
4265 ItemPointer tupleid,
4266 TupleTableSlot **slots,
4267 int numSlots)
4268{
4269 const char **p_values;
4270 int i;
4271 int j;
4272 int pindex = 0;
4273 MemoryContext oldcontext;
4274
4275 oldcontext = MemoryContextSwitchTo(fmstate->temp_cxt);
4276
4277 p_values = (const char **) palloc(sizeof(char *) * fmstate->p_nums * numSlots);
4278
4279 /* ctid is provided only for UPDATE/DELETE, which don't allow batching */
4280 Assert(!(tupleid != NULL && numSlots > 1));
4281
4282 /* 1st parameter should be ctid, if it's in use */
4283 if (tupleid != NULL)
4284 {
4285 Assert(numSlots == 1);
4286 /* don't need set_transmission_modes for TID output */
4287 p_values[pindex] = OutputFunctionCall(&fmstate->p_flinfo[pindex],
4288 PointerGetDatum(tupleid));
4289 pindex++;
4290 }
4291
4292 /* get following parameters from slots */
4293 if (slots != NULL && fmstate->target_attrs != NIL)
4294 {
4295 TupleDesc tupdesc = RelationGetDescr(fmstate->rel);
4296 int nestlevel;
4297 ListCell *lc;
4298
4299 nestlevel = set_transmission_modes();
4300
4301 for (i = 0; i < numSlots; i++)
4302 {
4303 j = (tupleid != NULL) ? 1 : 0;
4304 foreach(lc, fmstate->target_attrs)
4305 {
4306 int attnum = lfirst_int(lc);
4307 Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
4308 Datum value;
4309 bool isnull;
4310
4311 /* Ignore generated columns; they are set to DEFAULT */
4312 if (attr->attgenerated)
4313 continue;
4314 value = slot_getattr(slots[i], attnum, &isnull);
4315 if (isnull)
4316 p_values[pindex] = NULL;
4317 else
4318 p_values[pindex] = OutputFunctionCall(&fmstate->p_flinfo[j],
4319 value);
4320 pindex++;

Callers 1

execute_foreign_modifyFunction · 0.85

Calls 7

MemoryContextSwitchToFunction · 0.85
OutputFunctionCallFunction · 0.85
set_transmission_modesFunction · 0.85
slot_getattrFunction · 0.85
reset_transmission_modesFunction · 0.85
pallocFunction · 0.50
foreachFunction · 0.50

Tested by

no test coverage detected