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

Function printQuery

src/fe_utils/print.c:3427–3490  ·  view source on GitHub ↗

* Use this to print query results * * result: result of a successful query * opt: formatting options * fout: where to print to * is_pager: true if caller has already redirected fout to be a pager pipe * flog: if not null, also print the data there (for --log-file option) */

Source from the content-addressed store, hash-verified

3425 * flog: if not null, also print the data there (for --log-file option)
3426 */
3427void
3428printQuery(const PGresult *result, const printQueryOpt *opt,
3429 FILE *fout, bool is_pager, FILE *flog)
3430{
3431 printTableContent cont;
3432 int i,
3433 r,
3434 c;
3435
3436 if (cancel_pressed)
3437 return;
3438
3439 printTableInit(&cont, &opt->topt, opt->title,
3440 PQnfields(result), PQntuples(result));
3441
3442 /* Assert caller supplied enough translate_columns[] entries */
3443 Assert(opt->translate_columns == NULL ||
3444 opt->n_translate_columns >= cont.ncolumns);
3445
3446 for (i = 0; i < cont.ncolumns; i++)
3447 {
3448 printTableAddHeader(&cont, PQfname(result, i),
3449 opt->translate_header,
3450 column_type_alignment(PQftype(result, i)));
3451 }
3452
3453 /* set cells */
3454 for (r = 0; r < cont.nrows; r++)
3455 {
3456 for (c = 0; c < cont.ncolumns; c++)
3457 {
3458 char *cell;
3459 bool mustfree = false;
3460 bool translate;
3461
3462 if (PQgetisnull(result, r, c))
3463 cell = opt->nullPrint ? opt->nullPrint : "";
3464 else
3465 {
3466 cell = PQgetvalue(result, r, c);
3467 if (cont.aligns[c] == 'r' && opt->topt.numericLocale)
3468 {
3469 cell = format_numeric_locale(cell);
3470 mustfree = true;
3471 }
3472 }
3473
3474 translate = (opt->translate_columns && opt->translate_columns[c]);
3475 printTableAddCell(&cont, cell, translate, mustfree);
3476 }
3477 }
3478
3479 /* set footers */
3480 if (opt->footers)
3481 {
3482 char **footer;
3483
3484 for (footer = opt->footers; *footer; footer++)

Callers 15

describeAggregatesFunction · 0.85
describeAccessMethodsFunction · 0.85
describeTablespacesFunction · 0.85
describeFunctionsFunction · 0.85
describeTypesFunction · 0.85
describeOperatorsFunction · 0.85
listAllDbsFunction · 0.85
permissionsListFunction · 0.85
listDefaultACLsFunction · 0.85
objectDescriptionFunction · 0.85
describeOneTableDetailsFunction · 0.85
listDbRoleSettingsFunction · 0.85

Calls 14

printTableInitFunction · 0.85
PQnfieldsFunction · 0.85
PQntuplesFunction · 0.85
printTableAddHeaderFunction · 0.85
PQfnameFunction · 0.85
column_type_alignmentFunction · 0.85
PQftypeFunction · 0.85
PQgetisnullFunction · 0.85
PQgetvalueFunction · 0.85
format_numeric_localeFunction · 0.85
printTableAddCellFunction · 0.85
printTableAddFooterFunction · 0.85

Tested by

no test coverage detected