summaryrefslogtreecommitdiff
path: root/src/bin/psql
diff options
context:
space:
mode:
authorTom Lane2022-05-12 19:17:30 +0000
committerTom Lane2022-05-12 19:17:30 +0000
commit23e7b38bfe396f919fdb66057174d29e17086418 (patch)
tree335c3962ef8afe0f6193d0413dbc51642276b147 /src/bin/psql
parent93909599cdba64c8759d646983c0a4ef93de1e50 (diff)
Pre-beta mechanical code beautification.
Run pgindent, pgperltidy, and reformat-dat-files. I manually fixed a couple of comments that pgindent uglified.
Diffstat (limited to 'src/bin/psql')
-rw-r--r--src/bin/psql/common.c59
-rw-r--r--src/bin/psql/describe.c10
-rw-r--r--src/bin/psql/t/001_basic.pl57
-rw-r--r--src/bin/psql/t/010_tab_completion.pl27
-rw-r--r--src/bin/psql/t/020_cancel.pl29
-rw-r--r--src/bin/psql/tab-complete.c3
6 files changed, 101 insertions, 84 deletions
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index feb1d547d4d..9b140badeb9 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -32,8 +32,8 @@
static bool DescribeQuery(const char *query, double *elapsed_msec);
static bool ExecQueryUsingCursor(const char *query, double *elapsed_msec);
-static int ExecQueryAndProcessResults(const char *query, double *elapsed_msec, bool *svpt_gone_p,
- bool is_watch, const printQueryOpt *opt, FILE *printQueryFout);
+static int ExecQueryAndProcessResults(const char *query, double *elapsed_msec, bool *svpt_gone_p,
+ bool is_watch, const printQueryOpt *opt, FILE *printQueryFout);
static bool command_no_begin(const char *query);
static bool is_select_command(const char *query);
@@ -482,7 +482,7 @@ ClearOrSaveResult(PGresult *result)
static void
ClearOrSaveAllResults(void)
{
- PGresult *result;
+ PGresult *result;
while ((result = PQgetResult(pset.db)) != NULL)
ClearOrSaveResult(result);
@@ -697,7 +697,8 @@ PrintQueryTuples(const PGresult *result, const printQueryOpt *opt, FILE *printQu
}
else
{
- FILE *fout = printQueryFout ? printQueryFout : pset.queryFout;
+ FILE *fout = printQueryFout ? printQueryFout : pset.queryFout;
+
printQuery(result, opt ? opt : &pset.popt, fout, false, pset.logfile);
if (ferror(fout))
{
@@ -907,9 +908,9 @@ HandleCopyResult(PGresult **resultp)
&& (copystream != NULL);
/*
- * Suppress status printing if the report would go to the same
- * place as the COPY data just went. Note this doesn't
- * prevent error reporting, since handleCopyOut did that.
+ * Suppress status printing if the report would go to the same place
+ * as the COPY data just went. Note this doesn't prevent error
+ * reporting, since handleCopyOut did that.
*/
if (copystream == pset.queryFout)
{
@@ -943,8 +944,8 @@ HandleCopyResult(PGresult **resultp)
ResetCancelConn();
/*
- * Replace the PGRES_COPY_OUT/IN result with COPY command's exit
- * status, or with NULL if we want to suppress printing anything.
+ * Replace the PGRES_COPY_OUT/IN result with COPY command's exit status,
+ * or with NULL if we want to suppress printing anything.
*/
PQclear(*resultp);
*resultp = copy_result;
@@ -1069,7 +1070,7 @@ PrintQueryResult(PGresult *result, bool last, bool is_watch, const printQueryOpt
*/
struct t_notice_messages
{
- PQExpBufferData messages[2];
+ PQExpBufferData messages[2];
int current;
};
@@ -1080,6 +1081,7 @@ static void
AppendNoticeMessage(void *arg, const char *msg)
{
struct t_notice_messages *notices = arg;
+
appendPQExpBufferStr(&notices->messages[notices->current], msg);
}
@@ -1089,7 +1091,8 @@ AppendNoticeMessage(void *arg, const char *msg)
static void
ShowNoticeMessage(struct t_notice_messages *notices)
{
- PQExpBufferData *current = &notices->messages[notices->current];
+ PQExpBufferData *current = &notices->messages[notices->current];
+
if (*current->data != '\0')
pg_log_info("%s", current->data);
resetPQExpBuffer(current);
@@ -1234,6 +1237,7 @@ SendQuery(const char *query)
break;
case PQTRANS_INTRANS:
+
/*
* Release our savepoint, but do nothing if they are messing
* with savepoints themselves
@@ -1472,7 +1476,7 @@ DescribeQuery(const char *query, double *elapsed_msec)
*/
static int
ExecQueryAndProcessResults(const char *query, double *elapsed_msec, bool *svpt_gone_p,
- bool is_watch, const printQueryOpt *opt, FILE *printQueryFout)
+ bool is_watch, const printQueryOpt *opt, FILE *printQueryFout)
{
bool timing = pset.timing;
bool success;
@@ -1527,8 +1531,8 @@ ExecQueryAndProcessResults(const char *query, double *elapsed_msec, bool *svpt_g
if (!AcceptResult(result, false))
{
/*
- * Some error occured, either a server-side failure or
- * a failure to submit the command string. Record that.
+ * Some error occured, either a server-side failure or a failure
+ * to submit the command string. Record that.
*/
const char *error = PQresultErrorMessage(result);
@@ -1551,10 +1555,12 @@ ExecQueryAndProcessResults(const char *query, double *elapsed_msec, bool *svpt_g
if (result_status == PGRES_COPY_BOTH ||
result_status == PGRES_COPY_OUT ||
result_status == PGRES_COPY_IN)
+
/*
- * For some obscure reason PQgetResult does *not* return a NULL in copy
- * cases despite the result having been cleared, but keeps returning an
- * "empty" result that we have to ignore manually.
+ * For some obscure reason PQgetResult does *not* return a
+ * NULL in copy cases despite the result having been cleared,
+ * but keeps returning an "empty" result that we have to
+ * ignore manually.
*/
result = NULL;
else
@@ -1565,12 +1571,13 @@ ExecQueryAndProcessResults(const char *query, double *elapsed_msec, bool *svpt_g
else if (svpt_gone_p && !*svpt_gone_p)
{
/*
- * Check if the user ran any command that would destroy our internal
- * savepoint: If the user did COMMIT AND CHAIN, RELEASE or ROLLBACK, our
- * savepoint is gone. If they issued a SAVEPOINT, releasing ours would
- * remove theirs.
+ * Check if the user ran any command that would destroy our
+ * internal savepoint: If the user did COMMIT AND CHAIN, RELEASE
+ * or ROLLBACK, our savepoint is gone. If they issued a SAVEPOINT,
+ * releasing ours would remove theirs.
*/
const char *cmd = PQcmdStatus(result);
+
*svpt_gone_p = (strcmp(cmd, "COMMIT") == 0 ||
strcmp(cmd, "SAVEPOINT") == 0 ||
strcmp(cmd, "RELEASE") == 0 ||
@@ -1614,11 +1621,11 @@ ExecQueryAndProcessResults(const char *query, double *elapsed_msec, bool *svpt_g
/*
* Get timing measure before printing the last result.
*
- * It will include the display of previous results, if any.
- * This cannot be helped because the server goes on processing
- * further queries anyway while the previous ones are being displayed.
- * The parallel execution of the client display hides the server time
- * when it is shorter.
+ * It will include the display of previous results, if any. This
+ * cannot be helped because the server goes on processing further
+ * queries anyway while the previous ones are being displayed. The
+ * parallel execution of the client display hides the server time when
+ * it is shorter.
*
* With combined queries, timing must be understood as an upper bound
* of the time spent processing them.
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 31df8b759cd..1a5d924a23f 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -109,9 +109,9 @@ describeAggregates(const char *pattern, bool verbose, bool showSystem)
" AND n.nspname <> 'information_schema'\n");
if (!validateSQLNamePattern(&buf, pattern, true, false,
- "n.nspname", "p.proname", NULL,
- "pg_catalog.pg_function_is_visible(p.oid)",
- NULL, 3))
+ "n.nspname", "p.proname", NULL,
+ "pg_catalog.pg_function_is_visible(p.oid)",
+ NULL, 3))
return false;
appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
@@ -6002,7 +6002,7 @@ validateSQLNamePattern(PQExpBuffer buf, const char *pattern, bool have_where,
const char *visibilityrule, bool *added_clause,
int maxparts)
{
- PQExpBufferData dbbuf;
+ PQExpBufferData dbbuf;
int dotcnt;
bool added;
@@ -6021,7 +6021,7 @@ validateSQLNamePattern(PQExpBuffer buf, const char *pattern, bool have_where,
return false;
}
- if (maxparts > 1 && dotcnt == maxparts-1)
+ if (maxparts > 1 && dotcnt == maxparts - 1)
{
if (PQdb(pset.db) == NULL)
{
diff --git a/src/bin/psql/t/001_basic.pl b/src/bin/psql/t/001_basic.pl
index 98996d9a379..90e69d7cdba 100644
--- a/src/bin/psql/t/001_basic.pl
+++ b/src/bin/psql/t/001_basic.pl
@@ -36,9 +36,8 @@ sub psql_fails_like
my ($node, $sql, $expected_stderr, $test_name) = @_;
# Use the context of a WAL sender, some of the tests rely on that.
- my ($ret, $stdout, $stderr) = $node->psql(
- 'postgres', $sql,
- replication => 'database');
+ my ($ret, $stdout, $stderr) =
+ $node->psql('postgres', $sql, replication => 'database');
isnt($ret, 0, "$test_name: exit code not 0");
like($stderr, $expected_stderr, "$test_name: matches");
@@ -69,9 +68,9 @@ max_wal_senders = 4
});
$node->start;
-psql_like($node, '\copyright', qr/Copyright/, '\copyright');
-psql_like($node, '\help', qr/ALTER/, '\help without arguments');
-psql_like($node, '\help SELECT', qr/SELECT/, '\help with argument');
+psql_like($node, '\copyright', qr/Copyright/, '\copyright');
+psql_like($node, '\help', qr/ALTER/, '\help without arguments');
+psql_like($node, '\help SELECT', qr/SELECT/, '\help with argument');
# Test clean handling of unsupported replication command responses
psql_fails_like(
@@ -116,16 +115,16 @@ NOTIFY foo, 'bar';",
'notification with payload');
# test behavior and output on server crash
-my ($ret, $out, $err) = $node->psql(
- 'postgres',
- "SELECT 'before' AS running;\n" .
- "SELECT pg_terminate_backend(pg_backend_pid());\n" .
- "SELECT 'AFTER' AS not_running;\n");
+my ($ret, $out, $err) = $node->psql('postgres',
+ "SELECT 'before' AS running;\n"
+ . "SELECT pg_terminate_backend(pg_backend_pid());\n"
+ . "SELECT 'AFTER' AS not_running;\n");
is($ret, 2, 'server crash: psql exit code');
like($out, qr/before/, 'server crash: output before crash');
ok($out !~ qr/AFTER/, 'server crash: no output after crash');
-is($err, 'psql:<stdin>:2: FATAL: terminating connection due to administrator command
+is( $err,
+ 'psql:<stdin>:2: FATAL: terminating connection due to administrator command
psql:<stdin>:2: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
@@ -149,34 +148,46 @@ psql_like(
# \errverbose: The normal way, using a cursor by setting FETCH_COUNT,
# and using \gdesc. Test them all.
-like(($node->psql('postgres', "SELECT error;\n\\errverbose", on_error_stop => 0))[2],
- qr/\A^psql:<stdin>:1: ERROR: .*$
+like(
+ ( $node->psql(
+ 'postgres',
+ "SELECT error;\n\\errverbose",
+ on_error_stop => 0))[2],
+ qr/\A^psql:<stdin>:1: ERROR: .*$
^LINE 1: SELECT error;$
^ *^.*$
^psql:<stdin>:2: error: ERROR: [0-9A-Z]{5}: .*$
^LINE 1: SELECT error;$
^ *^.*$
^LOCATION: .*$/m,
- '\errverbose after normal query with error');
-
-like(($node->psql('postgres', "\\set FETCH_COUNT 1\nSELECT error;\n\\errverbose", on_error_stop => 0))[2],
- qr/\A^psql:<stdin>:2: ERROR: .*$
+ '\errverbose after normal query with error');
+
+like(
+ ( $node->psql(
+ 'postgres',
+ "\\set FETCH_COUNT 1\nSELECT error;\n\\errverbose",
+ on_error_stop => 0))[2],
+ qr/\A^psql:<stdin>:2: ERROR: .*$
^LINE 2: SELECT error;$
^ *^.*$
^psql:<stdin>:3: error: ERROR: [0-9A-Z]{5}: .*$
^LINE 2: SELECT error;$
^ *^.*$
^LOCATION: .*$/m,
- '\errverbose after FETCH_COUNT query with error');
-
-like(($node->psql('postgres', "SELECT error\\gdesc\n\\errverbose", on_error_stop => 0))[2],
- qr/\A^psql:<stdin>:1: ERROR: .*$
+ '\errverbose after FETCH_COUNT query with error');
+
+like(
+ ( $node->psql(
+ 'postgres',
+ "SELECT error\\gdesc\n\\errverbose",
+ on_error_stop => 0))[2],
+ qr/\A^psql:<stdin>:1: ERROR: .*$
^LINE 1: SELECT error$
^ *^.*$
^psql:<stdin>:2: error: ERROR: [0-9A-Z]{5}: .*$
^LINE 1: SELECT error$
^ *^.*$
^LOCATION: .*$/m,
- '\errverbose after \gdesc with error');
+ '\errverbose after \gdesc with error');
done_testing();
diff --git a/src/bin/psql/t/010_tab_completion.pl b/src/bin/psql/t/010_tab_completion.pl
index 2711935a2cc..2eea515e871 100644
--- a/src/bin/psql/t/010_tab_completion.pl
+++ b/src/bin/psql/t/010_tab_completion.pl
@@ -212,10 +212,7 @@ check_completion(
clear_line();
# check case folding
-check_completion(
- "select * from TAB\t",
- qr/tab1 /,
- "automatically fold case");
+check_completion("select * from TAB\t", qr/tab1 /, "automatically fold case");
clear_query();
@@ -228,15 +225,10 @@ check_completion("\\DRD\t", qr/drds /, "complete \\DRD<tab> to \\drds");
clear_line();
# check completion of a schema-qualified name
-check_completion(
- "select * from pub\t",
- qr/public\./,
- "complete schema when relevant");
+check_completion("select * from pub\t",
+ qr/public\./, "complete schema when relevant");
-check_completion(
- "tab\t",
- qr/tab1 /,
- "complete schema-qualified name");
+check_completion("tab\t", qr/tab1 /, "complete schema-qualified name");
clear_query();
@@ -339,15 +331,10 @@ check_completion(
clear_line();
# check timezone name completion
-check_completion(
- "SET timezone TO am\t",
- qr|'America/|,
- "offer partial timezone name");
+check_completion("SET timezone TO am\t",
+ qr|'America/|, "offer partial timezone name");
-check_completion(
- "new_\t",
- qr|New_York|,
- "complete partial timezone name");
+check_completion("new_\t", qr|New_York|, "complete partial timezone name");
clear_line();
diff --git a/src/bin/psql/t/020_cancel.pl b/src/bin/psql/t/020_cancel.pl
index d57d3429521..f4dbd36c391 100644
--- a/src/bin/psql/t/020_cancel.pl
+++ b/src/bin/psql/t/020_cancel.pl
@@ -21,7 +21,8 @@ $node->start;
# the process from IPC::Run. As a workaround, we have psql print its
# own PID (which is the parent of the shell launched by psql) to a
# file.
-SKIP: {
+SKIP:
+{
skip "cancel test requires a Unix shell", 2 if $windows_os;
local %ENV = $node->_get_env();
@@ -31,31 +32,38 @@ SKIP: {
# Test whether shell supports $PPID. It's part of POSIX, but some
# pre-/non-POSIX shells don't support it (e.g., NetBSD).
$stdin = "\\! echo \$PPID";
- IPC::Run::run(['psql', '-X', '-v', 'ON_ERROR_STOP=1'], '<', \$stdin, '>', \$stdout, '2>', \$stderr);
+ IPC::Run::run([ 'psql', '-X', '-v', 'ON_ERROR_STOP=1' ],
+ '<', \$stdin, '>', \$stdout, '2>', \$stderr);
$stdout =~ /^\d+$/ or skip "shell apparently does not support \$PPID", 2;
# Now start the real test
- my $h = IPC::Run::start(['psql', '-X', '-v', 'ON_ERROR_STOP=1'], \$stdin, \$stdout, \$stderr);
+ my $h = IPC::Run::start([ 'psql', '-X', '-v', 'ON_ERROR_STOP=1' ],
+ \$stdin, \$stdout, \$stderr);
# Get the PID
$stdout = '';
$stderr = '';
- $stdin = "\\! echo \$PPID >$tempdir/psql.pid\n";
+ $stdin = "\\! echo \$PPID >$tempdir/psql.pid\n";
pump $h while length $stdin;
my $count;
my $psql_pid;
- until (-s "$tempdir/psql.pid" and ($psql_pid = PostgreSQL::Test::Utils::slurp_file("$tempdir/psql.pid")) =~ /^\d+\n/s)
+ until (
+ -s "$tempdir/psql.pid"
+ and ($psql_pid =
+ PostgreSQL::Test::Utils::slurp_file("$tempdir/psql.pid")) =~
+ /^\d+\n/s)
{
($count++ < 100 * $PostgreSQL::Test::Utils::timeout_default)
or die "pid file did not appear";
- usleep(10_000)
+ usleep(10_000);
}
# Send sleep command and wait until the server has registered it
$stdin = "select pg_sleep($PostgreSQL::Test::Utils::timeout_default);\n";
pump $h while length $stdin;
- $node->poll_query_until('postgres', q{SELECT (SELECT count(*) FROM pg_stat_activity WHERE query ~ '^select pg_sleep') > 0;})
- or die "timed out";
+ $node->poll_query_until('postgres',
+ q{SELECT (SELECT count(*) FROM pg_stat_activity WHERE query ~ '^select pg_sleep') > 0;}
+ ) or die "timed out";
# Send cancel request
kill 'INT', $psql_pid;
@@ -63,7 +71,10 @@ SKIP: {
my $result = finish $h;
ok(!$result, 'query failed as expected');
- like($stderr, qr/canceling statement due to user request/, 'query was canceled');
+ like(
+ $stderr,
+ qr/canceling statement due to user request/,
+ 'query was canceled');
}
done_testing();
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 588c0841fee..55af9eb04e4 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -826,7 +826,7 @@ static const SchemaQuery Query_for_list_of_mergetargets = {
.selcondition =
"c.relkind IN (" CppAsString2(RELKIND_RELATION) ", "
CppAsString2(RELKIND_PARTITIONED_TABLE) ") ",
- .viscondition = "pg_catalog.pg_table_is_visible(c.oid)",
+ .viscondition = "pg_catalog.pg_table_is_visible(c.oid)",
.namespace = "c.relnamespace",
.result = "c.relname",
};
@@ -1827,6 +1827,7 @@ psql_completion(const char *text, int start, int end)
(HeadMatches("ALTER", "PUBLICATION", MatchAny, "ADD|SET", "TABLE") &&
ends_with(prev_wd, ',')))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
+
/*
* "ALTER PUBLICATION <name> SET TABLE <name> WHERE (" - complete with
* table attributes