diff options
author | Robert Haas <rhaas@postgresql.org> | 2012-08-09 09:59:45 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2012-08-09 10:02:50 -0400 |
commit | be690e291d59e8d0c9f4df59abe09f1ff6cc0da9 (patch) | |
tree | 7caef7285152bac1818ff8665808224093caa184 /src/bin/psql/startup.c | |
parent | 92ec0370eb65c4f059f2b60ee6e458b312bb7cbf (diff) |
Make psql -1 < file behave as expected.
Previously, the -1 option was silently ignored.
Also, emit an error if -1 is used in a context where it won't be
respected, to avoid user confusion.
Original patch by Fabien COELHO, but this version is quite different
from the original submission.
Diffstat (limited to 'src/bin/psql/startup.c')
-rw-r--r-- | src/bin/psql/startup.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index 9a6306b8cf2..8ba8f704218 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -150,6 +150,27 @@ main(int argc, char *argv[]) parse_psql_options(argc, argv, &options); + /* + * If no action was specified and we're in non-interactive mode, treat + * it as if the user had specified "-f -". This lets single-transaction + * mode work in this case. + */ + if (options.action == ACT_NOTHING && pset.notty) + { + options.action = ACT_FILE; + options.action_string = NULL; + } + + /* Bail out if -1 was specified but will be ignored. */ + if (options.single_txn && options.action != ACT_FILE) + { + if (options.action == ACT_NOTHING) + fprintf(stderr,_("%s: -1 can only be used in non-interactive mode\n"), pset.progname); + else + fprintf(stderr,_("%s: -1 is incompatible with -c and -l\n"), pset.progname); + exit(EXIT_FAILURE); + } + if (!pset.popt.topt.fieldSep.separator && !pset.popt.topt.fieldSep.separator_zero) { @@ -309,11 +330,9 @@ main(int argc, char *argv[]) process_psqlrc(argv[0]); connection_warnings(true); - if (!pset.quiet && !pset.notty) + if (!pset.quiet) printf(_("Type \"help\" for help.\n\n")); - if (!pset.notty) - initializeInput(options.no_readline ? 0 : 1); - + initializeInput(options.no_readline ? 0 : 1); successResult = MainLoop(stdin); } |