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

Function PQsetResultAttrs

src/interfaces/libpq/fe-exec.c:257–296  ·  view source on GitHub ↗

* PQsetResultAttrs * * Set the attributes for a given result. This function fails if there are * already attributes contained in the provided result. The call is * ignored if numAttributes is zero or attDescs is NULL. If the * function fails, it returns zero. If the function succeeds, it * returns a non-zero value. */

Source from the content-addressed store, hash-verified

255 * returns a non-zero value.
256 */
257int
258PQsetResultAttrs(PGresult *res, int numAttributes, PGresAttDesc *attDescs)
259{
260 int i;
261
262 /* If attrs already exist, they cannot be overwritten. */
263 if (!res || res->numAttributes > 0)
264 return false;
265
266 /* ignore no-op request */
267 if (numAttributes <= 0 || !attDescs)
268 return true;
269
270 res->attDescs = (PGresAttDesc *)
271 PQresultAlloc(res, numAttributes * sizeof(PGresAttDesc));
272
273 if (!res->attDescs)
274 return false;
275
276 res->numAttributes = numAttributes;
277 memcpy(res->attDescs, attDescs, numAttributes * sizeof(PGresAttDesc));
278
279 /* deep-copy the attribute names, and determine format */
280 res->binary = 1;
281 for (i = 0; i < res->numAttributes; i++)
282 {
283 if (res->attDescs[i].name)
284 res->attDescs[i].name = pqResultStrdup(res, res->attDescs[i].name);
285 else
286 res->attDescs[i].name = res->null_field;
287
288 if (!res->attDescs[i].name)
289 return false;
290
291 if (res->attDescs[i].format == 0)
292 res->binary = 0;
293 }
294
295 return true;
296}
297
298/*
299 * PQcopyResult

Callers 1

PQcopyResultFunction · 0.85

Calls 2

PQresultAllocFunction · 0.85
pqResultStrdupFunction · 0.85

Tested by

no test coverage detected