Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbe690e2

Browse files
committed
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 berespected, to avoid user confusion.Original patch by Fabien COELHO, but this version is quite differentfrom the original submission.
1 parent92ec037 commitbe690e2

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

‎doc/src/sgml/ref/psql-ref.sgml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -512,11 +512,11 @@ PostgreSQL documentation
512512
<term><option>--single-transaction</option></term>
513513
<listitem>
514514
<para>
515-
When <application>psql</application> executes a script with the
516-
<option>-f</> option, adding this option wraps
517-
<command>BEGIN</>/<command>COMMIT</> around thescript to execute it
518-
as a single transaction. This ensures that either all the commands
519-
complete successfully, or no changes areapplied.
515+
When <application>psql</application> executes a script, adding
516+
thisoption wraps <command>BEGIN</>/<command>COMMIT</> around the
517+
script to execute it as a single transaction. This ensures that
518+
either all the commands complete successfully, or no changes are
519+
applied.
520520
</para>
521521

522522
<para>

‎src/bin/psql/command.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,9 +2043,11 @@ process_file(char *filename, bool single_txn, bool use_relative_path)
20432043
PGresult*res;
20442044

20452045
if (!filename)
2046-
returnEXIT_FAILURE;
2047-
2048-
if (strcmp(filename,"-")!=0)
2046+
{
2047+
fd=stdin;
2048+
filename=NULL;
2049+
}
2050+
elseif (strcmp(filename,"-")!=0)
20492051
{
20502052
canonicalize_path(filename);
20512053

‎src/bin/psql/help.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ usage(void)
9797
printf(_(" -V, --version output version information, then exit\n"));
9898
printf(_(" -X, --no-psqlrc do not read startup file (~/.psqlrc)\n"));
9999
printf(_(" -1 (\"one\"), --single-transaction\n"
100-
" executecommand fileas a single transaction\n"));
100+
" execute as a single transaction (if non-interactive)\n"));
101101
printf(_(" -?, --help show this help, then exit\n"));
102102

103103
printf(_("\nInput and output options:\n"));

‎src/bin/psql/startup.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,27 @@ main(int argc, char *argv[])
150150

151151
parse_psql_options(argc,argv,&options);
152152

153+
/*
154+
* If no action was specified and we're in non-interactive mode, treat
155+
* it as if the user had specified "-f -". This lets single-transaction
156+
* mode work in this case.
157+
*/
158+
if (options.action==ACT_NOTHING&&pset.notty)
159+
{
160+
options.action=ACT_FILE;
161+
options.action_string=NULL;
162+
}
163+
164+
/* Bail out if -1 was specified but will be ignored. */
165+
if (options.single_txn&&options.action!=ACT_FILE)
166+
{
167+
if (options.action==ACT_NOTHING)
168+
fprintf(stderr,_("%s: -1 can only be used in non-interactive mode\n"),pset.progname);
169+
else
170+
fprintf(stderr,_("%s: -1 is incompatible with -c and -l\n"),pset.progname);
171+
exit(EXIT_FAILURE);
172+
}
173+
153174
if (!pset.popt.topt.fieldSep.separator&&
154175
!pset.popt.topt.fieldSep.separator_zero)
155176
{
@@ -309,11 +330,9 @@ main(int argc, char *argv[])
309330
process_psqlrc(argv[0]);
310331

311332
connection_warnings(true);
312-
if (!pset.quiet&& !pset.notty)
333+
if (!pset.quiet)
313334
printf(_("Type \"help\" for help.\n\n"));
314-
if (!pset.notty)
315-
initializeInput(options.no_readline ?0 :1);
316-
335+
initializeInput(options.no_readline ?0 :1);
317336
successResult=MainLoop(stdin);
318337
}
319338

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp