psql_sf_hidden_queries.patch
application/octet-stream
Filename: psql_sf_hidden_queries.patch
Type: application/octet-stream
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 | + | − |
|---|---|---|
| src/bin/psql/command.c | 27 | 0 |
| src/bin/psql/common.c | 33 | 0 |
| src/bin/psql/common.h | 1 | 0 |
*** a/src/bin/psql/command.c
--- b/src/bin/psql/command.c
***************
*** 2537,2552 **** lookup_function_oid(PGconn *conn, const char *desc, Oid *foid)
appendPQExpBuffer(query, "::pg_catalog.%s::pg_catalog.oid",
strchr(desc, '(') ? "regprocedure" : "regproc");
! res = PQexec(conn, query->data);
! if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) == 1)
! *foid = atooid(PQgetvalue(res, 0, 0));
! else
{
! minimal_error_message(res);
! result = false;
}
- PQclear(res);
destroyPQExpBuffer(query);
return result;
--- 2537,2558 ----
appendPQExpBuffer(query, "::pg_catalog.%s::pg_catalog.oid",
strchr(desc, '(') ? "regprocedure" : "regproc");
! if (TraceQuery(query->data))
{
! res = PQexec(conn, query->data);
! if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) == 1)
! *foid = atooid(PQgetvalue(res, 0, 0));
! else
! {
! minimal_error_message(res);
! result = false;
! }
!
! PQclear(res);
}
+ else
+ result = false;
destroyPQExpBuffer(query);
return result;
***************
*** 2566,2584 **** 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);
! if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) == 1)
{
! resetPQExpBuffer(buf);
! appendPQExpBufferStr(buf, PQgetvalue(res, 0, 0));
}
else
- {
- minimal_error_message(res);
result = false;
- }
- PQclear(res);
destroyPQExpBuffer(query);
return result;
--- 2572,2596 ----
query = createPQExpBuffer();
printfPQExpBuffer(query, "SELECT pg_catalog.pg_get_functiondef(%u)", oid);
! if (TraceQuery(query->data))
{
! res = PQexec(conn, query->data);
! if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) == 1)
! {
! resetPQExpBuffer(buf);
! appendPQExpBufferStr(buf, PQgetvalue(res, 0, 0));
! }
! else
! {
! minimal_error_message(res);
! result = false;
! }
!
! PQclear(res);
}
else
result = false;
destroyPQExpBuffer(query);
return result;
*** a/src/bin/psql/common.c
--- b/src/bin/psql/common.c
***************
*** 471,476 **** AcceptResult(const PGresult *result)
--- 471,507 ----
}
+ /*
+ * TraceQuery
+ *
+ * Show query or push query to log. Returns false, when query should
+ * not be executed.
+ */
+ bool
+ TraceQuery(const 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;
+ }
+
/*
* PSQLexec
***************
*** 499,522 **** PSQLexec(const char *query, bool start_xact)
return NULL;
}
! 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 NULL;
! }
SetCancelConn();
--- 530,537 ----
return NULL;
}
! if (!TraceQuery(query))
! return NULL;
SetCancelConn();
*** a/src/bin/psql/common.h
--- b/src/bin/psql/common.h
***************
*** 46,51 **** extern void SetCancelConn(void);
--- 46,52 ----
extern void ResetCancelConn(void);
extern PGresult *PSQLexec(const char *query, bool start_xact);
+ extern bool TraceQuery(const char *query);
extern bool SendQuery(const char *query);