Commit 9e9a5b71 authored by Bruce Momjian's avatar Bruce Momjian

Use psql_error() for most psql error calls, per request from Magnus.

parent f6752ee5
...@@ -110,7 +110,7 @@ HandleSlashCmds(PsqlScanState scan_state, ...@@ -110,7 +110,7 @@ HandleSlashCmds(PsqlScanState scan_state,
if (status == PSQL_CMD_UNKNOWN) if (status == PSQL_CMD_UNKNOWN)
{ {
if (pset.cur_cmd_interactive) if (pset.cur_cmd_interactive)
fprintf(stderr, _("Invalid command \\%s. Try \\? for help.\n"), cmd); psql_error("Invalid command \\%s. Try \\? for help.\n", cmd);
else else
psql_error("invalid command \\%s\n", cmd); psql_error("invalid command \\%s\n", cmd);
status = PSQL_CMD_ERROR; status = PSQL_CMD_ERROR;
...@@ -904,7 +904,7 @@ exec_command(const char *cmd, ...@@ -904,7 +904,7 @@ exec_command(const char *cmd,
if (strcmp(pw1, pw2) != 0) if (strcmp(pw1, pw2) != 0)
{ {
fprintf(stderr, _("Passwords didn't match.\n")); psql_error("Passwords didn't match.\n");
success = false; success = false;
} }
else else
...@@ -922,7 +922,7 @@ exec_command(const char *cmd, ...@@ -922,7 +922,7 @@ exec_command(const char *cmd,
if (!encrypted_password) if (!encrypted_password)
{ {
fprintf(stderr, _("Password encryption failed.\n")); psql_error("Password encryption failed.\n");
success = false; success = false;
} }
else else
...@@ -1441,7 +1441,7 @@ exec_command(const char *cmd, ...@@ -1441,7 +1441,7 @@ exec_command(const char *cmd,
while ((value = psql_scan_slash_option(scan_state, while ((value = psql_scan_slash_option(scan_state,
OT_NORMAL, NULL, true))) OT_NORMAL, NULL, true)))
{ {
fprintf(stderr, "+ opt(%d) = |%s|\n", i++, value); psql_error("+ opt(%d) = |%s|\n", i++, value);
free(value); free(value);
} }
} }
...@@ -1519,7 +1519,8 @@ do_connect(char *dbname, char *user, char *host, char *port) ...@@ -1519,7 +1519,8 @@ do_connect(char *dbname, char *user, char *host, char *port)
* to connect to the wrong database by using defaults, so require * to connect to the wrong database by using defaults, so require
* all parameters to be specified. * all parameters to be specified.
*/ */
fputs(_("All connection parameters must be supplied because no database connection exists\n"), stderr); psql_error("All connection parameters must be supplied because no "
"database connection exists\n");
return false; return false;
} }
...@@ -1608,7 +1609,7 @@ do_connect(char *dbname, char *user, char *host, char *port) ...@@ -1608,7 +1609,7 @@ do_connect(char *dbname, char *user, char *host, char *port)
/* pset.db is left unmodified */ /* pset.db is left unmodified */
if (o_conn) if (o_conn)
fputs(_("Previous connection kept\n"), stderr); psql_error("Previous connection kept\n");
} }
else else
{ {
......
...@@ -42,7 +42,7 @@ pg_strdup(const char *string) ...@@ -42,7 +42,7 @@ pg_strdup(const char *string)
if (!string) if (!string)
{ {
fprintf(stderr, _("%s: pg_strdup: cannot duplicate null pointer (internal error)\n"), psql_error("%s: pg_strdup: cannot duplicate null pointer (internal error)\n",
pset.progname); pset.progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
...@@ -161,7 +161,7 @@ psql_error(const char *fmt,...) ...@@ -161,7 +161,7 @@ psql_error(const char *fmt,...)
va_list ap; va_list ap;
fflush(stdout); fflush(stdout);
if (pset.queryFout != stdout) if (pset.queryFout && pset.queryFout != stdout)
fflush(pset.queryFout); fflush(pset.queryFout);
if (pset.inputfile) if (pset.inputfile)
...@@ -219,6 +219,7 @@ static PGcancel *volatile cancelConn = NULL; ...@@ -219,6 +219,7 @@ static PGcancel *volatile cancelConn = NULL;
static CRITICAL_SECTION cancelConnLock; static CRITICAL_SECTION cancelConnLock;
#endif #endif
/* Used from signal handlers, no buffering */
#define write_stderr(str) write(fileno(stderr), str, strlen(str)) #define write_stderr(str) write(fileno(stderr), str, strlen(str))
...@@ -350,19 +351,19 @@ CheckConnection(void) ...@@ -350,19 +351,19 @@ CheckConnection(void)
exit(EXIT_BADCONN); exit(EXIT_BADCONN);
} }
fputs(_("The connection to the server was lost. Attempting reset: "), stderr); psql_error("The connection to the server was lost. Attempting reset: ");
PQreset(pset.db); PQreset(pset.db);
OK = ConnectionUp(); OK = ConnectionUp();
if (!OK) if (!OK)
{ {
fputs(_("Failed.\n"), stderr); psql_error("Failed.\n");
PQfinish(pset.db); PQfinish(pset.db);
pset.db = NULL; pset.db = NULL;
ResetCancelConn(); ResetCancelConn();
UnsyncVariables(); UnsyncVariables();
} }
else else
fputs(_("Succeeded.\n"), stderr); psql_error("Succeeded.\n");
} }
return OK; return OK;
...@@ -910,7 +911,7 @@ SendQuery(const char *query) ...@@ -910,7 +911,7 @@ SendQuery(const char *query)
{ {
if (on_error_rollback_warning == false && pset.sversion < 80000) if (on_error_rollback_warning == false && pset.sversion < 80000)
{ {
fprintf(stderr, _("The server (version %d.%d) does not support savepoints for ON_ERROR_ROLLBACK.\n"), psql_error("The server (version %d.%d) does not support savepoints for ON_ERROR_ROLLBACK.\n",
pset.sversion / 10000, (pset.sversion / 100) % 100); pset.sversion / 10000, (pset.sversion / 100) % 100);
on_error_rollback_warning = true; on_error_rollback_warning = true;
} }
......
...@@ -132,7 +132,7 @@ describeTablespaces(const char *pattern, bool verbose) ...@@ -132,7 +132,7 @@ describeTablespaces(const char *pattern, bool verbose)
if (pset.sversion < 80000) if (pset.sversion < 80000)
{ {
fprintf(stderr, _("The server (version %d.%d) does not support tablespaces.\n"), psql_error("The server (version %d.%d) does not support tablespaces.\n",
pset.sversion / 10000, (pset.sversion / 100) % 100); pset.sversion / 10000, (pset.sversion / 100) % 100);
return true; return true;
} }
...@@ -219,13 +219,13 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool ...@@ -219,13 +219,13 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
if (strlen(functypes) != strspn(functypes, "antwS+")) if (strlen(functypes) != strspn(functypes, "antwS+"))
{ {
fprintf(stderr, _("\\df only takes [antwS+] as options\n")); psql_error("\\df only takes [antwS+] as options\n");
return true; return true;
} }
if (showWindow && pset.sversion < 80400) if (showWindow && pset.sversion < 80400)
{ {
fprintf(stderr, _("\\df does not take a \"w\" option with server version %d.%d\n"), psql_error("\\df does not take a \"w\" option with server version %d.%d\n",
pset.sversion / 10000, (pset.sversion / 100) % 100); pset.sversion / 10000, (pset.sversion / 100) % 100);
return true; return true;
} }
...@@ -786,7 +786,7 @@ listDefaultACLs(const char *pattern) ...@@ -786,7 +786,7 @@ listDefaultACLs(const char *pattern)
if (pset.sversion < 90000) if (pset.sversion < 90000)
{ {
fprintf(stderr, _("The server (version %d.%d) does not support altering default privileges.\n"), psql_error("The server (version %d.%d) does not support altering default privileges.\n",
pset.sversion / 10000, (pset.sversion / 100) % 100); pset.sversion / 10000, (pset.sversion / 100) % 100);
return true; return true;
} }
...@@ -1052,7 +1052,7 @@ describeTableDetails(const char *pattern, bool verbose, bool showSystem) ...@@ -1052,7 +1052,7 @@ describeTableDetails(const char *pattern, bool verbose, bool showSystem)
if (PQntuples(res) == 0) if (PQntuples(res) == 0)
{ {
if (!pset.quiet) if (!pset.quiet)
fprintf(stderr, _("Did not find any relation named \"%s\".\n"), psql_error("Did not find any relation named \"%s\".\n",
pattern); pattern);
PQclear(res); PQclear(res);
return false; return false;
...@@ -1225,8 +1225,7 @@ describeOneTableDetails(const char *schemaname, ...@@ -1225,8 +1225,7 @@ describeOneTableDetails(const char *schemaname,
if (PQntuples(res) == 0) if (PQntuples(res) == 0)
{ {
if (!pset.quiet) if (!pset.quiet)
fprintf(stderr, _("Did not find any relation with OID %s.\n"), psql_error("Did not find any relation with OID %s.\n", oid);
oid);
goto error_return; goto error_return;
} }
...@@ -3126,7 +3125,7 @@ listCollations(const char *pattern, bool verbose, bool showSystem) ...@@ -3126,7 +3125,7 @@ listCollations(const char *pattern, bool verbose, bool showSystem)
if (pset.sversion < 90100) if (pset.sversion < 90100)
{ {
fprintf(stderr, _("The server (version %d.%d) does not support collations.\n"), psql_error("The server (version %d.%d) does not support collations.\n",
pset.sversion / 10000, (pset.sversion / 100) % 100); pset.sversion / 10000, (pset.sversion / 100) % 100);
return true; return true;
} }
...@@ -3257,7 +3256,7 @@ listTSParsers(const char *pattern, bool verbose) ...@@ -3257,7 +3256,7 @@ listTSParsers(const char *pattern, bool verbose)
if (pset.sversion < 80300) if (pset.sversion < 80300)
{ {
fprintf(stderr, _("The server (version %d.%d) does not support full text search.\n"), psql_error("The server (version %d.%d) does not support full text search.\n",
pset.sversion / 10000, (pset.sversion / 100) % 100); pset.sversion / 10000, (pset.sversion / 100) % 100);
return true; return true;
} }
...@@ -3334,7 +3333,7 @@ listTSParsersVerbose(const char *pattern) ...@@ -3334,7 +3333,7 @@ listTSParsersVerbose(const char *pattern)
if (PQntuples(res) == 0) if (PQntuples(res) == 0)
{ {
if (!pset.quiet) if (!pset.quiet)
fprintf(stderr, _("Did not find any text search parser named \"%s\".\n"), psql_error("Did not find any text search parser named \"%s\".\n",
pattern); pattern);
PQclear(res); PQclear(res);
return false; return false;
...@@ -3490,7 +3489,7 @@ listTSDictionaries(const char *pattern, bool verbose) ...@@ -3490,7 +3489,7 @@ listTSDictionaries(const char *pattern, bool verbose)
if (pset.sversion < 80300) if (pset.sversion < 80300)
{ {
fprintf(stderr, _("The server (version %d.%d) does not support full text search.\n"), psql_error("The server (version %d.%d) does not support full text search.\n",
pset.sversion / 10000, (pset.sversion / 100) % 100); pset.sversion / 10000, (pset.sversion / 100) % 100);
return true; return true;
} }
...@@ -3558,7 +3557,7 @@ listTSTemplates(const char *pattern, bool verbose) ...@@ -3558,7 +3557,7 @@ listTSTemplates(const char *pattern, bool verbose)
if (pset.sversion < 80300) if (pset.sversion < 80300)
{ {
fprintf(stderr, _("The server (version %d.%d) does not support full text search.\n"), psql_error("The server (version %d.%d) does not support full text search.\n",
pset.sversion / 10000, (pset.sversion / 100) % 100); pset.sversion / 10000, (pset.sversion / 100) % 100);
return true; return true;
} }
...@@ -3626,7 +3625,7 @@ listTSConfigs(const char *pattern, bool verbose) ...@@ -3626,7 +3625,7 @@ listTSConfigs(const char *pattern, bool verbose)
if (pset.sversion < 80300) if (pset.sversion < 80300)
{ {
fprintf(stderr, _("The server (version %d.%d) does not support full text search.\n"), psql_error("The server (version %d.%d) does not support full text search.\n",
pset.sversion / 10000, (pset.sversion / 100) % 100); pset.sversion / 10000, (pset.sversion / 100) % 100);
return true; return true;
} }
...@@ -3704,7 +3703,7 @@ listTSConfigsVerbose(const char *pattern) ...@@ -3704,7 +3703,7 @@ listTSConfigsVerbose(const char *pattern)
if (PQntuples(res) == 0) if (PQntuples(res) == 0)
{ {
if (!pset.quiet) if (!pset.quiet)
fprintf(stderr, _("Did not find any text search configuration named \"%s\".\n"), psql_error("Did not find any text search configuration named \"%s\".\n",
pattern); pattern);
PQclear(res); PQclear(res);
return false; return false;
...@@ -3824,7 +3823,7 @@ listForeignDataWrappers(const char *pattern, bool verbose) ...@@ -3824,7 +3823,7 @@ listForeignDataWrappers(const char *pattern, bool verbose)
if (pset.sversion < 80400) if (pset.sversion < 80400)
{ {
fprintf(stderr, _("The server (version %d.%d) does not support foreign-data wrappers.\n"), psql_error("The server (version %d.%d) does not support foreign-data wrappers.\n",
pset.sversion / 10000, (pset.sversion / 100) % 100); pset.sversion / 10000, (pset.sversion / 100) % 100);
return true; return true;
} }
...@@ -3904,7 +3903,7 @@ listForeignServers(const char *pattern, bool verbose) ...@@ -3904,7 +3903,7 @@ listForeignServers(const char *pattern, bool verbose)
if (pset.sversion < 80400) if (pset.sversion < 80400)
{ {
fprintf(stderr, _("The server (version %d.%d) does not support foreign servers.\n"), psql_error("The server (version %d.%d) does not support foreign servers.\n",
pset.sversion / 10000, (pset.sversion / 100) % 100); pset.sversion / 10000, (pset.sversion / 100) % 100);
return true; return true;
} }
...@@ -3983,7 +3982,7 @@ listUserMappings(const char *pattern, bool verbose) ...@@ -3983,7 +3982,7 @@ listUserMappings(const char *pattern, bool verbose)
if (pset.sversion < 80400) if (pset.sversion < 80400)
{ {
fprintf(stderr, _("The server (version %d.%d) does not support user mappings.\n"), psql_error("The server (version %d.%d) does not support user mappings.\n",
pset.sversion / 10000, (pset.sversion / 100) % 100); pset.sversion / 10000, (pset.sversion / 100) % 100);
return true; return true;
} }
...@@ -4041,7 +4040,7 @@ listForeignTables(const char *pattern, bool verbose) ...@@ -4041,7 +4040,7 @@ listForeignTables(const char *pattern, bool verbose)
if (pset.sversion < 90100) if (pset.sversion < 90100)
{ {
fprintf(stderr, _("The server (version %d.%d) does not support foreign tables.\n"), psql_error("The server (version %d.%d) does not support foreign tables.\n",
pset.sversion / 10000, (pset.sversion / 100) % 100); pset.sversion / 10000, (pset.sversion / 100) % 100);
return true; return true;
} }
...@@ -4115,7 +4114,7 @@ listExtensions(const char *pattern) ...@@ -4115,7 +4114,7 @@ listExtensions(const char *pattern)
if (pset.sversion < 90100) if (pset.sversion < 90100)
{ {
fprintf(stderr, _("The server (version %d.%d) does not support extensions.\n"), psql_error("The server (version %d.%d) does not support extensions.\n",
pset.sversion / 10000, (pset.sversion / 100) % 100); pset.sversion / 10000, (pset.sversion / 100) % 100);
return true; return true;
} }
...@@ -4169,7 +4168,7 @@ listExtensionContents(const char *pattern) ...@@ -4169,7 +4168,7 @@ listExtensionContents(const char *pattern)
if (pset.sversion < 90100) if (pset.sversion < 90100)
{ {
fprintf(stderr, _("The server (version %d.%d) does not support extensions.\n"), psql_error("The server (version %d.%d) does not support extensions.\n",
pset.sversion / 10000, (pset.sversion / 100) % 100); pset.sversion / 10000, (pset.sversion / 100) % 100);
return true; return true;
} }
...@@ -4196,10 +4195,10 @@ listExtensionContents(const char *pattern) ...@@ -4196,10 +4195,10 @@ listExtensionContents(const char *pattern)
if (!pset.quiet) if (!pset.quiet)
{ {
if (pattern) if (pattern)
fprintf(stderr, _("Did not find any extension named \"%s\".\n"), psql_error("Did not find any extension named \"%s\".\n",
pattern); pattern);
else else
fprintf(stderr, _("Did not find any extensions.\n")); psql_error("Did not find any extensions.\n");
} }
PQclear(res); PQclear(res);
return false; return false;
......
...@@ -155,7 +155,7 @@ do_lo_export(const char *loid_arg, const char *filename_arg) ...@@ -155,7 +155,7 @@ do_lo_export(const char *loid_arg, const char *filename_arg)
/* of course this status is documented nowhere :( */ /* of course this status is documented nowhere :( */
if (status != 1) if (status != 1)
{ {
fputs(PQerrorMessage(pset.db), stderr); psql_error("%s", PQerrorMessage(pset.db));
return fail_lo_xact("\\lo_export", own_transaction); return fail_lo_xact("\\lo_export", own_transaction);
} }
...@@ -190,7 +190,7 @@ do_lo_import(const char *filename_arg, const char *comment_arg) ...@@ -190,7 +190,7 @@ do_lo_import(const char *filename_arg, const char *comment_arg)
if (loid == InvalidOid) if (loid == InvalidOid)
{ {
fputs(PQerrorMessage(pset.db), stderr); psql_error("%s", PQerrorMessage(pset.db));
return fail_lo_xact("\\lo_import", own_transaction); return fail_lo_xact("\\lo_import", own_transaction);
} }
...@@ -252,7 +252,7 @@ do_lo_unlink(const char *loid_arg) ...@@ -252,7 +252,7 @@ do_lo_unlink(const char *loid_arg)
if (status == -1) if (status == -1)
{ {
fputs(PQerrorMessage(pset.db), stderr); psql_error("%s", PQerrorMessage(pset.db));
return fail_lo_xact("\\lo_unlink", own_transaction); return fail_lo_xact("\\lo_unlink", own_transaction);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment