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

Function PQprint

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

* PQprint() * * Format results of a query for printing. * * PQprintOpt is a typedef (structure) that contains * various flags and options. consult libpq-fe.h for * details * * This function should probably be removed sometime since psql * doesn't use it anymore. It is unclear to what extent this is used * by external clients, however. */

Source from the content-addressed store, hash-verified

65 * by external clients, however.
66 */
67void
68PQprint(FILE *fout, const PGresult *res, const PQprintOpt *po)
69{
70 int nFields;
71
72 nFields = PQnfields(res);
73
74 if (nFields > 0)
75 { /* only print rows with at least 1 field. */
76 int i,
77 j;
78 int nTups;
79 int *fieldMax = NULL; /* in case we don't use them */
80 unsigned char *fieldNotNum = NULL;
81 char *border = NULL;
82 char **fields = NULL;
83 const char **fieldNames = NULL;
84 int fieldMaxLen = 0;
85 int numFieldName;
86 int fs_len = strlen(po->fieldSep);
87 int total_line_length = 0;
88 bool usePipe = false;
89 char *pagerenv;
90
91#if defined(ENABLE_THREAD_SAFETY) && !defined(WIN32)
92 sigset_t osigset;
93 bool sigpipe_masked = false;
94 bool sigpipe_pending;
95#endif
96#if !defined(ENABLE_THREAD_SAFETY) && !defined(WIN32)
97 pqsigfunc oldsigpipehandler = NULL;
98#endif
99
100#ifdef TIOCGWINSZ
101 struct winsize screen_size;
102#else
103 struct winsize
104 {
105 int ws_row;
106 int ws_col;
107 } screen_size;
108#endif
109
110 nTups = PQntuples(res);
111 fieldNames = (const char **) calloc(nFields, sizeof(char *));
112 fieldNotNum = (unsigned char *) calloc(nFields, 1);
113 fieldMax = (int *) calloc(nFields, sizeof(int));
114 if (!fieldNames || !fieldNotNum || !fieldMax)
115 {
116 fprintf(stderr, libpq_gettext("out of memory\n"));
117 goto exit;
118 }
119 for (numFieldName = 0;
120 po->fieldName && po->fieldName[numFieldName];
121 numFieldName++)
122 ;
123 for (j = 0; j < nFields; j++)
124 {

Callers 2

printResultSetFunction · 0.85
mapred_run_queriesFunction · 0.85

Calls 10

PQnfieldsFunction · 0.85
PQntuplesFunction · 0.85
libpq_gettextFunction · 0.85
PQfnameFunction · 0.85
pq_block_sigpipeFunction · 0.85
do_fieldFunction · 0.85
do_headerFunction · 0.85
output_rowFunction · 0.85
pq_reset_sigpipeFunction · 0.85
pqsignalFunction · 0.70

Tested by 1

printResultSetFunction · 0.68