Skip to content

Commit

Permalink
Adjust extra lines generated by psql to be valid SQL comments.
Browse files Browse the repository at this point in the history
psql's --echo-hidden, --log-file, and --single-step options
generate extra lines to clearly separate queries from other output.
Presently, these extra lines are not valid SQL comments, which
makes them a hazard for anyone trying to copy/paste the decorated
queries into a client or query editor.  This commit replaces the
starting and ending asterisks in these extra lines with forward
slashes so that they are valid SQL comments that can be copy/pasted
without incident.

Author: Kirk Wolak
Reviewed-by: Pavel Stehule, Laurenz Albe, Tom Lane, Alvaro Herrera, Andrey Borodin
Discussion: https://postgr.es/m/CACLU5mTFJRJYtbvmZ26txGgmXWQo0hkGhH2o3hEquUPmSbGtBw%40mail.gmail.com
  • Loading branch information
nathan-bossart committed Jul 27, 2023
1 parent 03734a7 commit 19c590f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/bin/psql/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -5395,16 +5395,16 @@ echo_hidden_command(const char *query)
{
if (pset.echo_hidden != PSQL_ECHO_HIDDEN_OFF)
{
printf(_("********* QUERY **********\n"
printf(_("/******** QUERY *********/\n"
"%s\n"
"**************************\n\n"), query);
"/************************/\n\n"), query);
fflush(stdout);
if (pset.logfile)
{
fprintf(pset.logfile,
_("********* QUERY **********\n"
_("/******** QUERY *********/\n"
"%s\n"
"**************************\n\n"), query);
"/************************/\n\n"), query);
fflush(pset.logfile);
}

Expand Down
16 changes: 8 additions & 8 deletions src/bin/psql/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,16 +589,16 @@ PSQLexec(const char *query)

if (pset.echo_hidden != PSQL_ECHO_HIDDEN_OFF)
{
printf(_("********* QUERY **********\n"
printf(_("/******** QUERY *********/\n"
"%s\n"
"**************************\n\n"), query);
"/************************/\n\n"), query);
fflush(stdout);
if (pset.logfile)
{
fprintf(pset.logfile,
_("********* QUERY **********\n"
_("/******** QUERY *********/\n"
"%s\n"
"**************************\n\n"), query);
"/************************/\n\n"), query);
fflush(pset.logfile);
}

Expand Down Expand Up @@ -1060,9 +1060,9 @@ SendQuery(const char *query)
char buf[3];

fflush(stderr);
printf(_("***(Single step mode: verify command)*******************************************\n"
printf(_("/**(Single step mode: verify command)******************************************/\n"
"%s\n"
"***(press return to proceed or enter x and return to cancel)********************\n"),
"/**(press return to proceed or enter x and return to cancel)*******************/\n"),
query);
fflush(stdout);
if (fgets(buf, sizeof(buf), stdin) != NULL)
Expand All @@ -1080,9 +1080,9 @@ SendQuery(const char *query)
if (pset.logfile)
{
fprintf(pset.logfile,
_("********* QUERY **********\n"
_("/******** QUERY *********/\n"
"%s\n"
"**************************\n\n"), query);
"/************************/\n\n"), query);
fflush(pset.logfile);
}

Expand Down

0 comments on commit 19c590f

Please sign in to comment.