psql: Improve error display for psql -f -
authorPeter Eisentraut <peter_e@gmx.net>
Thu, 1 Mar 2012 17:58:10 +0000 (19:58 +0200)
committerPeter Eisentraut <peter_e@gmx.net>
Thu, 1 Mar 2012 17:58:10 +0000 (19:58 +0200)
Running "psql -f -" used to print

psql:<stdin>:1: ERROR:  blah

but that got broken between 8.4 and 9.0 (commit
b291c0fba83a1e93868e2f69c03be195d620f30c), and now it printed

psql:-:1: ERROR:  blah

This reverts to the old behavior and cleans up some code that was left
dead or useless by the mentioned commit.

src/bin/psql/command.c
src/bin/psql/startup.c

index 8421ad008602d097cdeef29da8d4dd1db75bedda..aa000735dc5c82a2b031ee804593ac18a9e30305 100644 (file)
@@ -2062,14 +2062,17 @@ process_file(char *filename, bool single_txn, bool use_relative_path)
        }
 
        fd = fopen(filename, PG_BINARY_R);
+
+       if (!fd)
+       {
+           psql_error("%s: %s\n", filename, strerror(errno));
+           return EXIT_FAILURE;
+       }
    }
    else
-       fd = stdin;
-
-   if (!fd)
    {
-       psql_error("%s: %s\n", filename, strerror(errno));
-       return EXIT_FAILURE;
+       fd = stdin;
+       filename = "<stdin>";   /* for future error messages */
    }
 
    oldfilename = pset.inputfile;
index aff57728a2a67d669b00bc81b1b3efd78fff1020..166c227d6b6a8fef2ac002541b02b4ca6d866b8e 100644 (file)
@@ -313,8 +313,6 @@ main(int argc, char *argv[])
            printf(_("Type \"help\" for help.\n\n"));
        if (!pset.notty)
            initializeInput(options.no_readline ? 0 : 1);
-       if (options.action_string)      /* -f - was used */
-           pset.inputfile = "<stdin>";
 
        successResult = MainLoop(stdin);
    }