* 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
| 320 | * PG_COPYRES_NOTICEHOOKS - Copy the source result's notice hooks. |
| 321 | */ |
| 322 | PGresult * |
| 323 | PQcopyResult(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) |
no test coverage detected