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

Function PQdisplayTuples

src/interfaces/libpq/fe-print.c:590–684  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

588 */
589
590void
591PQdisplayTuples(const PGresult *res,
592 FILE *fp, /* where to send the output */
593 int fillAlign, /* pad the fields with spaces */
594 const char *fieldSep, /* field separator */
595 int printHeader, /* display headers? */
596 int quiet
597)
598{
599#define DEFAULT_FIELD_SEP " "
600
601 int i,
602 j;
603 int nFields;
604 int nTuples;
605 int *fLength = NULL;
606
607 if (fieldSep == NULL)
608 fieldSep = DEFAULT_FIELD_SEP;
609
610 /* Get some useful info about the results */
611 nFields = PQnfields(res);
612 nTuples = PQntuples(res);
613
614 if (fp == NULL)
615 fp = stdout;
616
617 /* Figure the field lengths to align to */
618 /* will be somewhat time consuming for very large results */
619 if (fillAlign)
620 {
621 fLength = (int *) malloc(nFields * sizeof(int));
622 if (!fLength)
623 {
624 fprintf(stderr, libpq_gettext("out of memory\n"));
625 return;
626 }
627
628 for (j = 0; j < nFields; j++)
629 {
630 fLength[j] = strlen(PQfname(res, j));
631 for (i = 0; i < nTuples; i++)
632 {
633 int flen = PQgetlength(res, i, j);
634
635 if (flen > fLength[j])
636 fLength[j] = flen;
637 }
638 }
639 }
640
641 if (printHeader)
642 {
643 /* first, print out the attribute names */
644 for (i = 0; i < nFields; i++)
645 {
646 fputs(PQfname(res, i), fp);
647 if (fillAlign)

Callers

nothing calls this directly

Calls 7

PQnfieldsFunction · 0.85
PQntuplesFunction · 0.85
libpq_gettextFunction · 0.85
PQfnameFunction · 0.85
PQgetlengthFunction · 0.85
fillFunction · 0.85
PQgetvalueFunction · 0.85

Tested by

no test coverage detected