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

Function do_field

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

Source from the content-addressed store, hash-verified

344
345
346static bool
347do_field(const PQprintOpt *po, const PGresult *res,
348 const int i, const int j, const int fs_len,
349 char **fields,
350 const int nFields, char const **fieldNames,
351 unsigned char *fieldNotNum, int *fieldMax,
352 const int fieldMaxLen, FILE *fout)
353{
354 const char *pval,
355 *p;
356 int plen;
357 bool skipit;
358
359 plen = PQgetlength(res, i, j);
360 pval = PQgetvalue(res, i, j);
361
362 if (plen < 1 || !pval || !*pval)
363 {
364 if (po->align || po->expanded)
365 skipit = true;
366 else
367 {
368 skipit = false;
369 goto efield;
370 }
371 }
372 else
373 skipit = false;
374
375 if (!skipit)
376 {
377 if (po->align && !fieldNotNum[j])
378 {
379 /* Detect whether field contains non-numeric data */
380 char ch = '0';
381
382 for (p = pval; *p; p += PQmblenBounded(p, res->client_encoding))
383 {
384 ch = *p;
385 if (!((ch >= '0' && ch <= '9') ||
386 ch == '.' ||
387 ch == 'E' ||
388 ch == 'e' ||
389 ch == ' ' ||
390 ch == '-'))
391 {
392 fieldNotNum[j] = 1;
393 break;
394 }
395 }
396
397 /*
398 * Above loop will believe E in first column is numeric; also, we
399 * insist on a digit in the last column for a numeric. This test
400 * is still not bulletproof but it handles most cases.
401 */
402 if (*pval == 'E' || *pval == 'e' ||
403 !(ch >= '0' && ch <= '9'))

Callers 1

PQprintFunction · 0.85

Calls 4

PQgetlengthFunction · 0.85
PQgetvalueFunction · 0.85
PQmblenBoundedFunction · 0.85
libpq_gettextFunction · 0.85

Tested by

no test coverage detected