Errors (for example I/O errors or disk full) while printing out result
tables were completely ignored, which could result in silently
truncated output in scripts, for example. Fix by adding some basic
error checking and reporting.
Author: Daniel Verite <daniel@manitou-mail.org>
Author: David Zhang <david.zhang@highgo.ca>
Discussion: https://www.postgresql.org/message-id/flat/
9a0b3c8d-ee14-4b1d-9d0a-
2c993bdabacc@manitou-mail.org
PrintQueryTuples(const PGresult *results)
{
printQueryOpt my_popt = pset.popt;
+ bool result = true;
/* one-shot expanded output requested via \gx */
if (pset.g_expanded)
disable_sigpipe_trap();
printQuery(results, &my_popt, fout, false, pset.logfile);
+ if (ferror(fout))
+ {
+ pg_log_error("could not print result table: %m");
+ result = false;
+ }
if (is_pipe)
{
fclose(fout);
}
else
+ {
printQuery(results, &my_popt, pset.queryFout, false, pset.logfile);
+ if (ferror(pset.queryFout))
+ {
+ pg_log_error("could not print result table: %m");
+ result = false;
+ }
+ }
- return true;
+ return result;
}