Make psql's \sf and \ef honor ECHO_HIDDEN.

These commands were calling the database direct rather than  calling
PSQLexec like other slash commands that needed database data.

The code is also changed not to pass the connection as a parameter to
the helper functions. It's available in a global variable, and that's
what PSQLexec uses.
This commit is contained in:
Andrew Dunstan 2014-11-21 12:14:05 -05:00
parent 622983ea69
commit e4d28175a1
1 changed files with 11 additions and 11 deletions

View File

@ -62,8 +62,8 @@ static bool do_edit(const char *filename_arg, PQExpBuffer query_buf,
static bool do_connect(char *dbname, char *user, char *host, char *port);
static bool do_shell(const char *command);
static bool do_watch(PQExpBuffer query_buf, long sleep);
static bool lookup_function_oid(PGconn *conn, const char *desc, Oid *foid);
static bool get_create_function_cmd(PGconn *conn, Oid oid, PQExpBuffer buf);
static bool lookup_function_oid(const char *desc, Oid *foid);
static bool get_create_function_cmd(Oid oid, PQExpBuffer buf);
static int strip_lineno_from_funcdesc(char *func);
static void minimal_error_message(PGresult *res);
@ -611,12 +611,12 @@ exec_command(const char *cmd,
"AS $function$\n"
"\n$function$\n");
}
else if (!lookup_function_oid(pset.db, func, &foid))
else if (!lookup_function_oid(func, &foid))
{
/* error already reported */
status = PSQL_CMD_ERROR;
}
else if (!get_create_function_cmd(pset.db, foid, query_buf))
else if (!get_create_function_cmd(foid, query_buf))
{
/* error already reported */
status = PSQL_CMD_ERROR;
@ -1215,12 +1215,12 @@ exec_command(const char *cmd,
psql_error("function name is required\n");
status = PSQL_CMD_ERROR;
}
else if (!lookup_function_oid(pset.db, func, &foid))
else if (!lookup_function_oid(func, &foid))
{
/* error already reported */
status = PSQL_CMD_ERROR;
}
else if (!get_create_function_cmd(pset.db, foid, func_buf))
else if (!get_create_function_cmd(foid, func_buf))
{
/* error already reported */
status = PSQL_CMD_ERROR;
@ -2934,7 +2934,7 @@ do_watch(PQExpBuffer query_buf, long sleep)
* unfortunately it can be hard to tell the difference.
*/
static bool
lookup_function_oid(PGconn *conn, const char *desc, Oid *foid)
lookup_function_oid(const char *desc, Oid *foid)
{
bool result = true;
PQExpBuffer query;
@ -2942,11 +2942,11 @@ lookup_function_oid(PGconn *conn, const char *desc, Oid *foid)
query = createPQExpBuffer();
appendPQExpBufferStr(query, "SELECT ");
appendStringLiteralConn(query, desc, conn);
appendStringLiteralConn(query, desc, pset.db);
appendPQExpBuffer(query, "::pg_catalog.%s::pg_catalog.oid",
strchr(desc, '(') ? "regprocedure" : "regproc");
res = PQexec(conn, query->data);
res = PSQLexec(query->data);
if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) == 1)
*foid = atooid(PQgetvalue(res, 0, 0));
else
@ -2966,7 +2966,7 @@ lookup_function_oid(PGconn *conn, const char *desc, Oid *foid)
* function with the given OID. If successful, the result is stored in buf.
*/
static bool
get_create_function_cmd(PGconn *conn, Oid oid, PQExpBuffer buf)
get_create_function_cmd(Oid oid, PQExpBuffer buf)
{
bool result = true;
PQExpBuffer query;
@ -2975,7 +2975,7 @@ get_create_function_cmd(PGconn *conn, Oid oid, PQExpBuffer buf)
query = createPQExpBuffer();
printfPQExpBuffer(query, "SELECT pg_catalog.pg_get_functiondef(%u)", oid);
res = PQexec(conn, query->data);
res = PSQLexec(query->data);
if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) == 1)
{
resetPQExpBuffer(buf);