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

Function PQsetvalue

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

* Sets the value for a tuple field. The tup_num must be less than or * equal to PQntuples(res). If it is equal, a new tuple is created and * added to the result. * Returns a non-zero value for success and zero for failure. * (On failure, we report the specific problem via pqInternalNotice.) */

Source from the content-addressed store, hash-verified

457 * (On failure, we report the specific problem via pqInternalNotice.)
458 */
459int
460PQsetvalue(PGresult *res, int tup_num, int field_num, char *value, int len)
461{
462 PGresAttValue *attval;
463 const char *errmsg = NULL;
464
465 /* Note that this check also protects us against null "res" */
466 if (!check_field_number(res, field_num))
467 return false;
468
469 /* Invalid tup_num, must be <= ntups */
470 if (tup_num < 0 || tup_num > res->ntups)
471 {
472 pqInternalNotice(&res->noticeHooks,
473 "row number %d is out of range 0..%d",
474 tup_num, res->ntups);
475 return false;
476 }
477
478 /* need to allocate a new tuple? */
479 if (tup_num == res->ntups)
480 {
481 PGresAttValue *tup;
482 int i;
483
484 tup = (PGresAttValue *)
485 pqResultAlloc(res, res->numAttributes * sizeof(PGresAttValue),
486 true);
487
488 if (!tup)
489 goto fail;
490
491 /* initialize each column to NULL */
492 for (i = 0; i < res->numAttributes; i++)
493 {
494 tup[i].len = NULL_LEN;
495 tup[i].value = res->null_field;
496 }
497
498 /* add it to the array */
499 if (!pqAddTuple(res, tup, &errmsg))
500 goto fail;
501 }
502
503 attval = &res->tuples[tup_num][field_num];
504
505 /* treat either NULL_LEN or NULL value pointer as a NULL field */
506 if (len == NULL_LEN || value == NULL)
507 {
508 attval->len = NULL_LEN;
509 attval->value = res->null_field;
510 }
511 else if (len <= 0)
512 {
513 attval->len = 0;
514 attval->value = res->null_field;
515 }
516 else

Callers 1

PQcopyResultFunction · 0.85

Calls 5

check_field_numberFunction · 0.85
pqInternalNoticeFunction · 0.85
pqResultAllocFunction · 0.85
pqAddTupleFunction · 0.85
libpq_gettextFunction · 0.85

Tested by

no test coverage detected