]> granicus.if.org Git - postgresql/commitdiff
Use psql_error() for most psql error calls, per request from Magnus.
authorBruce Momjian <bruce@momjian.us>
Sun, 26 Aug 2012 02:58:42 +0000 (22:58 -0400)
committerBruce Momjian <bruce@momjian.us>
Sun, 26 Aug 2012 02:58:42 +0000 (22:58 -0400)
src/bin/psql/command.c
src/bin/psql/common.c
src/bin/psql/describe.c
src/bin/psql/large_obj.c

index 205bb507fbc476fb7c63091d011b8a70e0ba7090..dc04399d0b6c2f6564a158a9ed9eb1b4d6a387ac 100644 (file)
@@ -110,7 +110,7 @@ HandleSlashCmds(PsqlScanState scan_state,
        if (status == PSQL_CMD_UNKNOWN)
        {
                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
                        psql_error("invalid command \\%s\n", cmd);
                status = PSQL_CMD_ERROR;
@@ -904,7 +904,7 @@ exec_command(const char *cmd,
 
                if (strcmp(pw1, pw2) != 0)
                {
-                       fprintf(stderr, _("Passwords didn't match.\n"));
+                       psql_error("Passwords didn't match.\n");
                        success = false;
                }
                else
@@ -922,7 +922,7 @@ exec_command(const char *cmd,
 
                        if (!encrypted_password)
                        {
-                               fprintf(stderr, _("Password encryption failed.\n"));
+                               psql_error("Password encryption failed.\n");
                                success = false;
                        }
                        else
@@ -1441,7 +1441,7 @@ exec_command(const char *cmd,
                while ((value = psql_scan_slash_option(scan_state,
                                                                                           OT_NORMAL, NULL, true)))
                {
-                       fprintf(stderr, "+ opt(%d) = |%s|\n", i++, value);
+                       psql_error("+ opt(%d) = |%s|\n", i++, value);
                        free(value);
                }
        }
@@ -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
                 *      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;
        }
 
@@ -1608,7 +1609,7 @@ do_connect(char *dbname, char *user, char *host, char *port)
 
                        /* pset.db is left unmodified */
                        if (o_conn)
-                               fputs(_("Previous connection kept\n"), stderr);
+                               psql_error("Previous connection kept\n");
                }
                else
                {
index 330d5ce12cfa793407013923f258bba965fb89db..f5bd0f6d42d79c13f4f6b8852e23fac3aac41ec1 100644 (file)
@@ -42,7 +42,7 @@ pg_strdup(const char *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);
                exit(EXIT_FAILURE);
        }
@@ -161,7 +161,7 @@ psql_error(const char *fmt,...)
        va_list         ap;
 
        fflush(stdout);
-       if (pset.queryFout != stdout)
+       if (pset.queryFout && pset.queryFout != stdout)
                fflush(pset.queryFout);
 
        if (pset.inputfile)
@@ -219,6 +219,7 @@ static PGcancel *volatile cancelConn = NULL;
 static CRITICAL_SECTION cancelConnLock;
 #endif
 
+/* Used from signal handlers, no buffering */
 #define write_stderr(str)      write(fileno(stderr), str, strlen(str))
 
 
@@ -350,19 +351,19 @@ CheckConnection(void)
                        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);
                OK = ConnectionUp();
                if (!OK)
                {
-                       fputs(_("Failed.\n"), stderr);
+                       psql_error("Failed.\n");
                        PQfinish(pset.db);
                        pset.db = NULL;
                        ResetCancelConn();
                        UnsyncVariables();
                }
                else
-                       fputs(_("Succeeded.\n"), stderr);
+                       psql_error("Succeeded.\n");
        }
 
        return OK;
@@ -910,7 +911,7 @@ SendQuery(const char *query)
        {
                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);
                        on_error_rollback_warning = true;
                }
index 14985ba0b101c24a00c8d89fd149aba871450960..c2bcc5abe08b8e64b2566af8713afb11d90412aa 100644 (file)
@@ -132,7 +132,7 @@ describeTablespaces(const char *pattern, bool verbose)
 
        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);
                return true;
        }
@@ -219,13 +219,13 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
 
        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;
        }
 
        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);
                return true;
        }
@@ -786,7 +786,7 @@ listDefaultACLs(const char *pattern)
 
        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);
                return true;
        }
@@ -1052,7 +1052,7 @@ describeTableDetails(const char *pattern, bool verbose, bool showSystem)
        if (PQntuples(res) == 0)
        {
                if (!pset.quiet)
-                       fprintf(stderr, _("Did not find any relation named \"%s\".\n"),
+                       psql_error("Did not find any relation named \"%s\".\n",
                                        pattern);
                PQclear(res);
                return false;
@@ -1225,8 +1225,7 @@ describeOneTableDetails(const char *schemaname,
        if (PQntuples(res) == 0)
        {
                if (!pset.quiet)
-                       fprintf(stderr, _("Did not find any relation with OID %s.\n"),
-                                       oid);
+                       psql_error("Did not find any relation with OID %s.\n", oid);
                goto error_return;
        }
 
@@ -3126,7 +3125,7 @@ listCollations(const char *pattern, bool verbose, bool showSystem)
 
        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);
                return true;
        }
@@ -3257,7 +3256,7 @@ listTSParsers(const char *pattern, bool verbose)
 
        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);
                return true;
        }
@@ -3334,7 +3333,7 @@ listTSParsersVerbose(const char *pattern)
        if (PQntuples(res) == 0)
        {
                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);
                PQclear(res);
                return false;
@@ -3490,7 +3489,7 @@ listTSDictionaries(const char *pattern, bool verbose)
 
        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);
                return true;
        }
@@ -3558,7 +3557,7 @@ listTSTemplates(const char *pattern, bool verbose)
 
        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);
                return true;
        }
@@ -3626,7 +3625,7 @@ listTSConfigs(const char *pattern, bool verbose)
 
        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);
                return true;
        }
@@ -3704,7 +3703,7 @@ listTSConfigsVerbose(const char *pattern)
        if (PQntuples(res) == 0)
        {
                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);
                PQclear(res);
                return false;
@@ -3824,7 +3823,7 @@ listForeignDataWrappers(const char *pattern, bool verbose)
 
        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);
                return true;
        }
@@ -3904,7 +3903,7 @@ listForeignServers(const char *pattern, bool verbose)
 
        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);
                return true;
        }
@@ -3983,7 +3982,7 @@ listUserMappings(const char *pattern, bool verbose)
 
        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);
                return true;
        }
@@ -4041,7 +4040,7 @@ listForeignTables(const char *pattern, bool verbose)
 
        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);
                return true;
        }
@@ -4115,7 +4114,7 @@ listExtensions(const char *pattern)
 
        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);
                return true;
        }
@@ -4169,7 +4168,7 @@ listExtensionContents(const char *pattern)
 
        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);
                return true;
        }
@@ -4196,10 +4195,10 @@ listExtensionContents(const char *pattern)
                if (!pset.quiet)
                {
                        if (pattern)
-                               fprintf(stderr, _("Did not find any extension named \"%s\".\n"),
+                               psql_error("Did not find any extension named \"%s\".\n",
                                                pattern);
                        else
-                               fprintf(stderr, _("Did not find any extensions.\n"));
+                               psql_error("Did not find any extensions.\n");
                }
                PQclear(res);
                return false;
index ea95be15c0e28db2abb60d217163a5c869e2a631..dc6ff370fe5d4eac81f37e94b61446dcb9bbc2d2 100644 (file)
@@ -155,7 +155,7 @@ do_lo_export(const char *loid_arg, const char *filename_arg)
        /* of course this status is documented nowhere :( */
        if (status != 1)
        {
-               fputs(PQerrorMessage(pset.db), stderr);
+               psql_error("%s", PQerrorMessage(pset.db));
                return fail_lo_xact("\\lo_export", own_transaction);
        }
 
@@ -190,7 +190,7 @@ do_lo_import(const char *filename_arg, const char *comment_arg)
 
        if (loid == InvalidOid)
        {
-               fputs(PQerrorMessage(pset.db), stderr);
+               psql_error("%s", PQerrorMessage(pset.db));
                return fail_lo_xact("\\lo_import", own_transaction);
        }
 
@@ -252,7 +252,7 @@ do_lo_unlink(const char *loid_arg)
 
        if (status == -1)
        {
-               fputs(PQerrorMessage(pset.db), stderr);
+               psql_error("%s", PQerrorMessage(pset.db));
                return fail_lo_xact("\\lo_unlink", own_transaction);
        }