aboutsummaryrefslogtreecommitdiff
path: root/src/bin/psql/command.c
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2014-11-22 09:39:01 -0500
committerAndrew Dunstan <andrew@dunslane.net>2014-11-22 09:39:01 -0500
commiteca2b9ba3e1e65c2ac880578bfb3cbeed1cb1d26 (patch)
treefeeafd525b46c497d2fc034e45f2ef437dcb298d /src/bin/psql/command.c
parent447770404cce5ce86174fa4809784c4e5d0a0a76 (diff)
downloadpostgresql-eca2b9ba3e1e65c2ac880578bfb3cbeed1cb1d26.tar.gz
postgresql-eca2b9ba3e1e65c2ac880578bfb3cbeed1cb1d26.zip
Rework echo_hidden for \sf and \ef from commit e4d2817.
PSQLexec's error reporting turns out to be too verbose for this case, so revert to using PQexec instead with minimal error reporting. Prior to calling PQexec, we call a function that mimics just the echo_hidden piece of PSQLexec.
Diffstat (limited to 'src/bin/psql/command.c')
-rw-r--r--src/bin/psql/command.c37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 36d5e36977d..162fcf14013 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -2925,6 +2925,34 @@ do_watch(PQExpBuffer query_buf, long sleep)
}
/*
+ * a little code borrowed from PSQLexec() to manage ECHO_HIDDEN output.
+ * returns true unless we have ECHO_HIDDEN_NOEXEC.
+ */
+static bool
+lookup_function_echo_hidden(char * query)
+{
+ if (pset.echo_hidden != PSQL_ECHO_HIDDEN_OFF)
+ {
+ printf(_("********* QUERY **********\n"
+ "%s\n"
+ "**************************\n\n"), query);
+ fflush(stdout);
+ if (pset.logfile)
+ {
+ fprintf(pset.logfile,
+ _("********* QUERY **********\n"
+ "%s\n"
+ "**************************\n\n"), query);
+ fflush(pset.logfile);
+ }
+
+ if (pset.echo_hidden == PSQL_ECHO_HIDDEN_NOEXEC)
+ return false;
+ }
+ return true;
+}
+
+/*
* This function takes a function description, e.g. "x" or "x(int)", and
* issues a query on the given connection to retrieve the function's OID
* using a cast to regproc or regprocedure (as appropriate). The result,
@@ -2945,8 +2973,9 @@ lookup_function_oid(const char *desc, Oid *foid)
appendStringLiteralConn(query, desc, pset.db);
appendPQExpBuffer(query, "::pg_catalog.%s::pg_catalog.oid",
strchr(desc, '(') ? "regprocedure" : "regproc");
-
- res = PSQLexec(query->data);
+ if (!lookup_function_echo_hidden(query->data))
+ return false;
+ res = PQexec(pset.db, query->data);
if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) == 1)
*foid = atooid(PQgetvalue(res, 0, 0));
else
@@ -2975,7 +3004,9 @@ get_create_function_cmd(Oid oid, PQExpBuffer buf)
query = createPQExpBuffer();
printfPQExpBuffer(query, "SELECT pg_catalog.pg_get_functiondef(%u)", oid);
- res = PSQLexec(query->data);
+ if (!lookup_function_echo_hidden(query->data))
+ return false;
+ res = PQexec(pset.db, query->data);
if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) == 1)
{
resetPQExpBuffer(buf);