| 588 | */ |
| 589 | |
| 590 | void |
| 591 | PQdisplayTuples(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) |
nothing calls this directly
no test coverage detected