if (nFields > 0)
{ /* only print rows with at least 1 field. */ int i,
j; int nTups; int *fieldMax = NULL; /* in case we don't use them */ unsignedchar *fieldNotNum = NULL; char *border = NULL; char **fields = NULL; constchar **fieldNames = NULL; int fieldMaxLen = 0; int numFieldName; int fs_len = strlen(po->fieldSep); int total_line_length = 0; bool usePipe = false; char *pagerenv;
fputs(s, fout);
len += strlen(s) + fs_len; if ((j + 1) < nFields)
fputs(po->fieldSep, fout);
}
fputc('\n', fout); for (len -= fs_len; len--; fputc('-', fout));
fputc('\n', fout);
}
} if (po->expanded && po->html3)
{ if (po->caption)
fprintf(fout, "<center><h2>%s</h2></center>\n", po->caption); else
fprintf(fout, "<center><h2>" "Query retrieved %d rows * %d fields" "</h2></center>\n",
nTups, nFields);
} for (i = 0; i < nTups; i++)
{ if (po->expanded)
{ if (po->html3)
fprintf(fout, "<table %s><caption align=\"top\">%d</caption>\n",
po->tableOpt ? po->tableOpt : "", i); else
fprintf(fout, libpq_gettext("-- RECORD %d --\n"), i);
} for (j = 0; j < nFields; j++)
{ if (!do_field(po, res, i, j, fs_len, fields, nFields,
fieldNames, fieldNotNum,
fieldMax, fieldMaxLen, fout)) gotoexit;
} if (po->html3 && po->expanded)
fputs("</table>\n", fout);
} if (!po->expanded && (po->align || po->html3))
{ if (po->html3)
{ if (po->header)
{ if (po->caption)
fprintf(fout, "<table %s><caption align=\"top\">%s</caption>\n",
po->tableOpt ? po->tableOpt : "",
po->caption); else
fprintf(fout, "<table %s><caption align=\"top\">" "Retrieved %d rows * %d fields" "</caption>\n",
po->tableOpt ? po->tableOpt : "", nTups, nFields);
} else
fprintf(fout, "<table %s>", po->tableOpt ? po->tableOpt : "");
} if (po->header)
border = do_header(fout, po, nFields, fieldMax, fieldNames,
fieldNotNum, fs_len, res); for (i = 0; i < nTups; i++)
output_row(fout, po, nFields, fields,
fieldNotNum, fieldMax, border, i);
} if (po->header && !po->html3)
fprintf(fout, "(%d row%s)\n\n", PQntuples(res),
(PQntuples(res) == 1) ? "" : "s"); if (po->html3 && !po->expanded)
fputs("</table>\n", fout);
exit:
free(fieldMax);
free(fieldNotNum);
free(border); if (fields)
{ /* if calloc succeeded, this shouldn't overflow size_t */
size_t numfields = ((size_t) nTups + 1) * (size_t) nFields;
while (numfields-- > 0)
free(fields[numfields]);
free(fields);
}
free(fieldNames); if (usePipe)
{ #ifdef WIN32
_pclose(fout); #else
pclose(fout);
/* we can't easily verify if EPIPE occurred, so say it did */ if (sigpipe_masked)
pq_reset_sigpipe(&osigset, sigpipe_pending, true); #endif/* WIN32 */
}
}
}
staticchar *
do_header(FILE *fout, const PQprintOpt *po, constint nFields, int *fieldMax, constchar **fieldNames, unsignedchar *fieldNotNum, constint fs_len, const PGresult *res)
{ int j; /* for loop index */ char *border = NULL;
if (po->html3)
fputs("<tr>", fout); else
{
size_t tot = 0; int n = 0; char *p = NULL;
/* Calculate the border size, checking for overflow. */ for (; n < nFields; n++)
{ /* Field plus separator, plus 2 extra '-' in standard format. */ if (pg_add_size_overflow(tot, fieldMax[n], &tot) ||
pg_add_size_overflow(tot, fs_len, &tot) ||
(po->standard && pg_add_size_overflow(tot, 2, &tot))) goto overflow;
} if (po->standard)
{ /* An extra separator at the front and back. */ if (pg_add_size_overflow(tot, fs_len, &tot) ||
pg_add_size_overflow(tot, fs_len, &tot) ||
pg_add_size_overflow(tot, 2, &tot)) goto overflow;
} if (pg_add_size_overflow(tot, 1, &tot)) /* terminator */ goto overflow;
border = malloc(tot); if (!border)
{
fprintf(stderr, libpq_gettext("out of memory\n")); return NULL;
}
p = border; if (po->standard)
{ char *fs = po->fieldSep;
while (*fs++)
*p++ = '+';
} for (j = 0; j < nFields; j++)
{ int len;
if (po->html3)
fprintf(fout, "<td align=\"%s\">%s</td>",
fieldNotNum[field_index] ? "left" : "right", p ? p : ""); else
{
fprintf(fout,
fieldNotNum[field_index] ?
(po->standard ? " %-*s " : "%-*s") :
(po->standard ? " %*s " : "%*s"),
fieldMax[field_index],
p ? p : ""); if (po->standard || field_index + 1 < nFields)
fputs(po->fieldSep, fout);
}
} if (po->html3)
fputs("</tr>", fout); elseif (po->standard)
fprintf(fout, "\n%s", border);
fputc('\n', fout);
}
/* *reallyoldprintingroutines
*/
void
PQdisplayTuples(const PGresult *res,
FILE *fp, /* where to send the output */ int fillAlign, /* pad the fields with spaces */ constchar *fieldSep, /* field separator */ int printHeader, /* display headers? */ int quiet
)
{ #define DEFAULT_FIELD_SEP " "
int i,
j; int nFields; int nTuples; int *fLength = NULL;
if (fieldSep == NULL)
fieldSep = DEFAULT_FIELD_SEP;
/* Get some useful info about the results */
nFields = PQnfields(res);
nTuples = PQntuples(res);
if (fp == NULL)
fp = stdout;
/* Figure the field lengths to align to */ /* will be somewhat time consuming for very large results */ if (fillAlign)
{
fLength = (int *) malloc(nFields * sizeof(int)); if (!fLength)
{
fprintf(stderr, libpq_gettext("out of memory\n")); return;
}
for (j = 0; j < nFields; j++)
{
fLength[j] = strlen(PQfname(res, j)); for (i = 0; i < nTuples; i++)
{ int flen = PQgetlength(res, i, j);
if (flen > fLength[j])
fLength[j] = flen;
}
}
}
if (printHeader)
{ /* first, print out the attribute names */ for (i = 0; i < nFields; i++)
{
fputs(PQfname(res, i), fp); if (fillAlign)
fill(strlen(PQfname(res, i)), fLength[i], ' ', fp);
fputs(fieldSep, fp);
}
fprintf(fp, "\n");
/* Underline the attribute names */ for (i = 0; i < nFields; i++)
{ if (fillAlign)
fill(0, fLength[i], '-', fp);
fputs(fieldSep, fp);
}
fprintf(fp, "\n");
}
/* next, print out the instances */ for (i = 0; i < nTuples; i++)
{ for (j = 0; j < nFields; j++)
{
fprintf(fp, "%s", PQgetvalue(res, i, j)); if (fillAlign)
fill(strlen(PQgetvalue(res, i, j)), fLength[j], ' ', fp);
fputs(fieldSep, fp);
}
fprintf(fp, "\n");
}
if (!quiet)
fprintf(fp, "\nQuery returned %d row%s.\n", PQntuples(res),
(PQntuples(res) == 1) ? "" : "s");
fflush(fp);
free(fLength);
}
void
PQprintTuples(const PGresult *res,
FILE *fout, /* output stream */ int PrintAttNames, /* print attribute names or not */ int TerseOutput, /* delimiter bars or not? */ int colWidth /* width of column, if 0, use variable width */
)
{ int nFields; int nTups; int i,
j; char formatString[80]; char *tborder = NULL;
/* simply send out max-length number of filler characters to fp */
staticvoid
fill(int length, int max, char filler, FILE *fp)
{ int count;
count = max - length; while (count-- >= 0)
putc(filler, fp);
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.16Bemerkung:
(vorverarbeitet am 2026-08-06)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.