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

Function PQcopyResult

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

* PQcopyResult * * Returns a deep copy of the provided 'src' PGresult, which cannot be NULL. * The 'flags' argument controls which portions of the result will or will * NOT be copied. The created result is always put into the * PGRES_TUPLES_OK status. The source result error message is not copied, * although cmdStatus is. * * To set custom attributes, use PQsetResultAttrs. That function

Source from the content-addressed store, hash-verified

320 * PG_COPYRES_NOTICEHOOKS - Copy the source result's notice hooks.
321 */
322PGresult *
323PQcopyResult(const PGresult *src, int flags)
324{
325 PGresult *dest;
326 int i;
327
328 if (!src)
329 return NULL;
330
331 dest = PQmakeEmptyPGresult(NULL, PGRES_TUPLES_OK);
332 if (!dest)
333 return NULL;
334
335 /* Always copy these over. Is cmdStatus really useful here? */
336 dest->client_encoding = src->client_encoding;
337 strcpy(dest->cmdStatus, src->cmdStatus);
338
339 /* Wants attrs? */
340 if (flags & (PG_COPYRES_ATTRS | PG_COPYRES_TUPLES))
341 {
342 if (!PQsetResultAttrs(dest, src->numAttributes, src->attDescs))
343 {
344 PQclear(dest);
345 return NULL;
346 }
347 }
348
349 /* Wants to copy tuples? */
350 if (flags & PG_COPYRES_TUPLES)
351 {
352 int tup,
353 field;
354
355 for (tup = 0; tup < src->ntups; tup++)
356 {
357 for (field = 0; field < src->numAttributes; field++)
358 {
359 if (!PQsetvalue(dest, tup, field,
360 src->tuples[tup][field].value,
361 src->tuples[tup][field].len))
362 {
363 PQclear(dest);
364 return NULL;
365 }
366 }
367 }
368 }
369
370 /* Wants to copy notice hooks? */
371 if (flags & PG_COPYRES_NOTICEHOOKS)
372 dest->noticeHooks = src->noticeHooks;
373
374 /* Wants to copy PGEvents? */
375 if ((flags & PG_COPYRES_EVENTS) && src->nEvents > 0)
376 {
377 dest->events = dupEvents(src->events, src->nEvents,
378 &dest->memorySize);
379 if (!dest->events)

Callers 1

pqRowProcessorFunction · 0.85

Calls 5

PQmakeEmptyPGresultFunction · 0.85
PQsetResultAttrsFunction · 0.85
PQclearFunction · 0.85
PQsetvalueFunction · 0.85
dupEventsFunction · 0.85

Tested by

no test coverage detected