single_txn_on_no_tty_stdin.patch
text/x-diff
Filename: single_txn_on_no_tty_stdin.patch
Type: text/x-diff
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: context
| File | + | − |
|---|---|---|
| doc/src/sgml/ref/psql-ref.sgml | 4 | 0 |
| src/bin/psql/help.c | 2 | 0 |
| src/bin/psql/settings.h | 1 | 0 |
| src/bin/psql/startup.c | 8 | 0 |
*** a/doc/src/sgml/ref/psql-ref.sgml
--- b/doc/src/sgml/ref/psql-ref.sgml
***************
*** 512,521 **** PostgreSQL documentation
<listitem>
<para>
When <application>psql</application> executes a script with the
! <option>-f</> option, adding this option wraps
! <command>BEGIN</>/<command>COMMIT</> around the script to execute it
! as a single transaction. This ensures that either all the commands
! complete successfully, or no changes are applied.
</para>
<para>
--- 512,521 ----
<listitem>
<para>
When <application>psql</application> executes a script with the
! <option>-f</> option or from a non-interactive standard input, adding
! this option wraps <command>BEGIN</>/<command>COMMIT</> around the script
! to execute it as a single transaction. This ensures that either all
! the commands complete successfully, or no changes are applied.
</para>
<para>
*** a/src/bin/psql/help.c
--- b/src/bin/psql/help.c
***************
*** 97,103 **** usage(void)
printf(_(" -V, --version output version information, then exit\n"));
printf(_(" -X, --no-psqlrc do not read startup file (~/.psqlrc)\n"));
printf(_(" -1 (\"one\"), --single-transaction\n"
! " execute command file as a single transaction\n"));
printf(_(" -?, --help show this help, then exit\n"));
printf(_("\nInput and output options:\n"));
--- 97,104 ----
printf(_(" -V, --version output version information, then exit\n"));
printf(_(" -X, --no-psqlrc do not read startup file (~/.psqlrc)\n"));
printf(_(" -1 (\"one\"), --single-transaction\n"
! " execute command file or non-interactive stdin\n"
! " as a single transaction\n"));
printf(_(" -?, --help show this help, then exit\n"));
printf(_("\nInput and output options:\n"));
*** a/src/bin/psql/settings.h
--- b/src/bin/psql/settings.h
***************
*** 76,81 **** typedef struct _psqlSettings
--- 76,82 ----
bool notty; /* stdin or stdout is not a tty (as determined
* on startup) */
+ bool stdin_notty; /* stdin is not a tty (on startup) */
enum trivalue getPassword; /* prompt the user for a username and password */
FILE *cur_cmd_source; /* describe the status of the current main
* loop */
*** a/src/bin/psql/startup.c
--- b/src/bin/psql/startup.c
***************
*** 133,139 **** main(int argc, char *argv[])
/* We must get COLUMNS here before readline() sets it */
pset.popt.topt.env_columns = getenv("COLUMNS") ? atoi(getenv("COLUMNS")) : 0;
! pset.notty = (!isatty(fileno(stdin)) || !isatty(fileno(stdout)));
pset.getPassword = TRI_DEFAULT;
--- 133,140 ----
/* We must get COLUMNS here before readline() sets it */
pset.popt.topt.env_columns = getenv("COLUMNS") ? atoi(getenv("COLUMNS")) : 0;
! pset.stdin_notty = !isatty(fileno(stdin));
! pset.notty = (pset.stdin_notty || !isatty(fileno(stdout)));
pset.getPassword = TRI_DEFAULT;
***************
*** 314,320 **** main(int argc, char *argv[])
if (!pset.notty)
initializeInput(options.no_readline ? 0 : 1);
! successResult = MainLoop(stdin);
}
/* clean up */
--- 315,326 ----
if (!pset.notty)
initializeInput(options.no_readline ? 0 : 1);
! if (options.single_txn && pset.stdin_notty)
! /* stdin is NOT a tty and -1, process as a file */
! successResult = process_file("-", true, false);
! else
! /* no single transation, process as if interactive */
! successResult = MainLoop(stdin);
}
/* clean up */