"-- # <whatever> QUERY\n%s\n\n"
Attached an attempt along those lines. I found another duplicate of the ascii-art printing in another function.
Completion queries seems to be out of the echo/echo hidden feature.Incredible, there is a (small) impact on regression tests for the \gexec case. All other changes have no impact, because they are not tested:-(
-- Fabien.
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 543401c6d6..8ec00881db 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -2061,7 +2061,7 @@ exec_command_password(PsqlScanState scan_state, bool active_branch) printfPQExpBuffer(&buf, "ALTER USER %s PASSWORD ", fmtId(user)); appendStringLiteralConn(&buf, encrypted_password, pset.db); - res = PSQLexec(buf.data); + res = PSQLexec("PASSWORD", buf.data); termPQExpBuffer(&buf); if (!res) success = false; @@ -4993,22 +4993,13 @@ do_watch(PQExpBuffer query_buf, double sleep) * returns true unless we have ECHO_HIDDEN_NOEXEC. */ static bool -echo_hidden_command(const char *query) +echo_hidden_command(const char *origin, const char *query) { if (pset.echo_hidden != PSQL_ECHO_HIDDEN_OFF) { - printf(_("********* QUERY **********\n" - "%s\n" - "**************************\n\n"), query); - fflush(stdout); + echoQuery(stdout, origin, query); if (pset.logfile) - { - fprintf(pset.logfile, - _("********* QUERY **********\n" - "%s\n" - "**************************\n\n"), query); - fflush(pset.logfile); - } + echoQuery(pset.logfile, origin, query); if (pset.echo_hidden == PSQL_ECHO_HIDDEN_NOEXEC) return false; @@ -5060,7 +5051,7 @@ lookup_object_oid(EditableObjectType obj_type, const char *desc, break; } - if (!echo_hidden_command(query->data)) + if (!echo_hidden_command("INTERNAL", query->data)) { destroyPQExpBuffer(query); return false; @@ -5155,7 +5146,7 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid, break; } - if (!echo_hidden_command(query->data)) + if (!echo_hidden_command("INTERNAL", query->data)) { destroyPQExpBuffer(query); return false; diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index 9a00499510..69d4e33093 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -523,6 +523,17 @@ PrintTiming(double elapsed_msec) elapsed_msec, days, (int) hours, (int) minutes, seconds); } +/* + * Echo user query + */ +void +echoQuery(FILE *out, const char *origin, const char *query) +{ + fprintf(out, + /* FIXME should this really be translatable? */ + _("-- # %s QUERY\n%s\n\n"), origin, query); + fflush(out); +} /* * PSQLexec @@ -537,7 +548,7 @@ PrintTiming(double elapsed_msec) * caller uses this path to issue "SET CLIENT_ENCODING". */ PGresult * -PSQLexec(const char *query) +PSQLexec(const char *origin, const char *query) { PGresult *res; @@ -549,18 +560,9 @@ PSQLexec(const char *query) if (pset.echo_hidden != PSQL_ECHO_HIDDEN_OFF) { - printf(_("********* QUERY **********\n" - "%s\n" - "**************************\n\n"), query); - fflush(stdout); + echoQuery(stdout, origin, query); if (pset.logfile) - { - fprintf(pset.logfile, - _("********* QUERY **********\n" - "%s\n" - "**************************\n\n"), query); - fflush(pset.logfile); - } + echoQuery(pset.logfile, origin, query); if (pset.echo_hidden == PSQL_ECHO_HIDDEN_NOEXEC) return NULL; @@ -856,10 +858,7 @@ ExecQueryTuples(const PGresult *result) * assumes that MainLoop did that, so we have to do it here. */ if (pset.echo == PSQL_ECHO_ALL && !pset.singlestep) - { - puts(query); - fflush(stdout); - } + echoQuery(stdout, "GEXEC", query); if (!SendQuery(query)) { @@ -1226,13 +1225,7 @@ SendQuery(const char *query) } if (pset.logfile) - { - fprintf(pset.logfile, - _("********* QUERY **********\n" - "%s\n" - "**************************\n\n"), query); - fflush(pset.logfile); - } + echoQuery(pset.logfile, "USER", query); SetCancelConn(pset.db); diff --git a/src/bin/psql/common.h b/src/bin/psql/common.h index 041b2ac068..cdad55414a 100644 --- a/src/bin/psql/common.h +++ b/src/bin/psql/common.h @@ -28,9 +28,10 @@ extern sigjmp_buf sigint_interrupt_jmp; extern void psql_setup_cancel_handler(void); -extern PGresult *PSQLexec(const char *query); +extern PGresult *PSQLexec(const char *origin, const char *query); extern int PSQLexecWatch(const char *query, const printQueryOpt *opt); +extern void echoQuery(FILE *out, const char *origin, const char *query); extern bool SendQuery(const char *query); extern bool is_superuser(void); diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 2abf255798..b7f701a68a 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -127,7 +127,7 @@ describeAggregates(const char *pattern, bool verbose, bool showSystem) appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -195,7 +195,7 @@ describeAccessMethods(const char *pattern, bool verbose) appendPQExpBufferStr(&buf, "ORDER BY 1;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -282,7 +282,7 @@ describeTablespaces(const char *pattern, bool verbose) appendPQExpBufferStr(&buf, "ORDER BY 1;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -682,7 +682,7 @@ describeFunctions(const char *functypes, const char *func_pattern, appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -813,7 +813,7 @@ describeTypes(const char *pattern, bool verbose, bool showSystem) appendPQExpBufferStr(&buf, "ORDER BY 1, 2;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -1001,7 +1001,7 @@ describeOperators(const char *oper_pattern, appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3, 4;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -1072,7 +1072,7 @@ listAllDbs(const char *pattern, bool verbose) NULL, "d.datname", NULL, NULL); appendPQExpBufferStr(&buf, "ORDER BY 1;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -1225,7 +1225,7 @@ permissionsList(const char *pattern) appendPQExpBufferStr(&buf, "ORDER BY 1, 2;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); if (!res) { termPQExpBuffer(&buf); @@ -1304,7 +1304,7 @@ listDefaultACLs(const char *pattern) appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); if (!res) { termPQExpBuffer(&buf); @@ -1503,7 +1503,7 @@ objectDescription(const char *pattern, bool showSystem) appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -1555,7 +1555,7 @@ describeTableDetails(const char *pattern, bool verbose, bool showSystem) appendPQExpBufferStr(&buf, "ORDER BY 2, 3;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -1816,7 +1816,7 @@ describeOneTableDetails(const char *schemaname, oid); } - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); if (!res) goto error_return; @@ -1913,7 +1913,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBuffer(&buf, ".%s;", fmtId(relationname)); } - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); if (!res) goto error_return; @@ -1936,7 +1936,7 @@ describeOneTableDetails(const char *schemaname, "\n AND d.deptype IN ('a', 'i')", oid); - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); /* * If we get no rows back, don't show anything (obviously). We should @@ -2098,7 +2098,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBuffer(&buf, "\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid); appendPQExpBufferStr(&buf, "\nORDER BY a.attnum;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); if (!res) goto error_return; numrows = PQntuples(res); @@ -2321,7 +2321,7 @@ describeOneTableDetails(const char *schemaname, " JOIN pg_catalog.pg_inherits i" " ON c.oid = inhrelid" "\nWHERE c.oid = '%s';", oid); - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); if (!result) goto error_return; @@ -2362,7 +2362,7 @@ describeOneTableDetails(const char *schemaname, printfPQExpBuffer(&buf, "SELECT pg_catalog.pg_get_partkeydef('%s'::pg_catalog.oid);", oid); - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); if (!result) goto error_return; @@ -2387,7 +2387,7 @@ describeOneTableDetails(const char *schemaname, " JOIN pg_catalog.pg_namespace n" " ON n.oid = c.relnamespace\n" "WHERE reltoastrelid = '%s';", oid); - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); if (!result) goto error_return; @@ -2445,7 +2445,7 @@ describeOneTableDetails(const char *schemaname, "AND i.indrelid = c2.oid;", oid); - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); if (!result) goto error_return; else if (PQntuples(result) != 1) @@ -2553,7 +2553,7 @@ describeOneTableDetails(const char *schemaname, "WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n" "ORDER BY i.indisprimary DESC, c2.relname;", oid); - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); if (!result) goto error_return; else @@ -2637,7 +2637,7 @@ describeOneTableDetails(const char *schemaname, "WHERE r.conrelid = '%s' AND r.contype = 'c'\n" "ORDER BY 1;", oid); - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); if (!result) goto error_return; else @@ -2700,7 +2700,7 @@ describeOneTableDetails(const char *schemaname, appendPQExpBufferStr(&buf, "ORDER BY conname"); } - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); if (!result) goto error_return; else @@ -2764,7 +2764,7 @@ describeOneTableDetails(const char *schemaname, oid); } - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); if (!result) goto error_return; else @@ -2814,7 +2814,7 @@ describeOneTableDetails(const char *schemaname, "WHERE pol.polrelid = '%s' ORDER BY 1;", oid); - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); if (!result) goto error_return; else @@ -2891,7 +2891,7 @@ describeOneTableDetails(const char *schemaname, "ORDER BY 1;", oid); - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); if (!result) goto error_return; else @@ -2995,7 +2995,7 @@ describeOneTableDetails(const char *schemaname, "ORDER BY 1;", oid); - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); if (!result) goto error_return; else @@ -3070,7 +3070,7 @@ describeOneTableDetails(const char *schemaname, "WHERE r.ev_class = '%s' ORDER BY 1;", oid); } - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); if (!result) goto error_return; else @@ -3159,7 +3159,7 @@ describeOneTableDetails(const char *schemaname, "ORDER BY 1;", oid, oid); - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); if (!result) goto error_return; else @@ -3189,7 +3189,7 @@ describeOneTableDetails(const char *schemaname, printfPQExpBuffer(&buf, "SELECT pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid, true);", oid); - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); if (!result) goto error_return; @@ -3215,7 +3215,7 @@ describeOneTableDetails(const char *schemaname, "FROM pg_catalog.pg_rewrite r\n" "WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1;", oid); - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); if (!result) goto error_return; @@ -3284,7 +3284,7 @@ describeOneTableDetails(const char *schemaname, " WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))"); appendPQExpBufferStr(&buf, "\nORDER BY 1;"); - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); if (!result) goto error_return; else @@ -3428,7 +3428,7 @@ describeOneTableDetails(const char *schemaname, " pg_catalog.pg_foreign_server s\n" "WHERE f.ftrelid = '%s' AND s.oid = f.ftserver;", oid); - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); if (!result) goto error_return; else if (PQntuples(result) != 1) @@ -3462,7 +3462,7 @@ describeOneTableDetails(const char *schemaname, "\nORDER BY inhseqno;", oid); - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); if (!result) goto error_return; else @@ -3527,7 +3527,7 @@ describeOneTableDetails(const char *schemaname, "ORDER BY c.relname;", oid); - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); if (!result) goto error_return; tuples = PQntuples(result); @@ -3695,7 +3695,7 @@ add_tablespace_footer(printTableContent *const cont, char relkind, printfPQExpBuffer(&buf, "SELECT spcname FROM pg_catalog.pg_tablespace\n" "WHERE oid = '%u';", tablespace); - result = PSQLexec(buf.data); + result = PSQLexec("DESCRIBE", buf.data); if (!result) { termPQExpBuffer(&buf); @@ -3805,7 +3805,7 @@ describeRoles(const char *pattern, bool verbose, bool showSystem) appendPQExpBufferStr(&buf, "ORDER BY 1;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); if (!res) return false; @@ -3941,7 +3941,7 @@ listDbRoleSettings(const char *pattern, const char *pattern2) NULL, "d.datname", NULL, NULL); appendPQExpBufferStr(&buf, "ORDER BY 1, 2;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -4159,7 +4159,7 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys appendPQExpBufferStr(&buf, "ORDER BY 1,2;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -4376,7 +4376,7 @@ listPartitionedTables(const char *reltypes, const char *pattern, bool verbose) mixed_output ? "\"Type\" DESC, " : "", showNested || pattern ? "\"Parent name\" NULLS FIRST, " : ""); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -4457,7 +4457,7 @@ listLanguages(const char *pattern, bool verbose, bool showSystem) appendPQExpBufferStr(&buf, "ORDER BY 1;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -4544,7 +4544,7 @@ listDomains(const char *pattern, bool verbose, bool showSystem) appendPQExpBufferStr(&buf, "ORDER BY 1, 2;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -4618,7 +4618,7 @@ listConversions(const char *pattern, bool verbose, bool showSystem) appendPQExpBufferStr(&buf, "ORDER BY 1, 2;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -4684,7 +4684,7 @@ listEventTriggers(const char *pattern, bool verbose) appendPQExpBufferStr(&buf, "ORDER BY 1"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -4778,7 +4778,7 @@ listExtendedStats(const char *pattern) appendPQExpBufferStr(&buf, "ORDER BY 1, 2;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -4894,7 +4894,7 @@ listCasts(const char *pattern, bool verbose) appendPQExpBufferStr(&buf, ") )\nORDER BY 1, 2;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -4993,7 +4993,7 @@ listCollations(const char *pattern, bool verbose, bool showSystem) appendPQExpBufferStr(&buf, "ORDER BY 1, 2;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -5052,7 +5052,7 @@ listSchemas(const char *pattern, bool verbose, bool showSystem) appendPQExpBufferStr(&buf, "ORDER BY 1;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -5112,7 +5112,7 @@ listTSParsers(const char *pattern, bool verbose) appendPQExpBufferStr(&buf, "ORDER BY 1, 2;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -5153,7 +5153,7 @@ listTSParsersVerbose(const char *pattern) appendPQExpBufferStr(&buf, "ORDER BY 1, 2;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -5255,7 +5255,7 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname) gettext_noop("Get token types"), oid); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -5289,7 +5289,7 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname) gettext_noop("Description"), oid); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -5370,7 +5370,7 @@ listTSDictionaries(const char *pattern, bool verbose) appendPQExpBufferStr(&buf, "ORDER BY 1, 2;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -5441,7 +5441,7 @@ listTSTemplates(const char *pattern, bool verbose) appendPQExpBufferStr(&buf, "ORDER BY 1, 2;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -5501,7 +5501,7 @@ listTSConfigs(const char *pattern, bool verbose) appendPQExpBufferStr(&buf, "ORDER BY 1, 2;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -5543,7 +5543,7 @@ listTSConfigsVerbose(const char *pattern) appendPQExpBufferStr(&buf, "ORDER BY 3, 2;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -5626,7 +5626,7 @@ describeOneTSConfig(const char *oid, const char *nspname, const char *cfgname, gettext_noop("Dictionaries"), oid); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -5730,7 +5730,7 @@ listForeignDataWrappers(const char *pattern, bool verbose) appendPQExpBufferStr(&buf, "ORDER BY 1;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -5812,7 +5812,7 @@ listForeignServers(const char *pattern, bool verbose) appendPQExpBufferStr(&buf, "ORDER BY 1;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -5873,7 +5873,7 @@ listUserMappings(const char *pattern, bool verbose) appendPQExpBufferStr(&buf, "ORDER BY 1, 2;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -5951,7 +5951,7 @@ listForeignTables(const char *pattern, bool verbose) appendPQExpBufferStr(&buf, "ORDER BY 1, 2;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -6008,7 +6008,7 @@ listExtensions(const char *pattern) appendPQExpBufferStr(&buf, "ORDER BY 1;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -6057,7 +6057,7 @@ listExtensionContents(const char *pattern) appendPQExpBufferStr(&buf, "ORDER BY 1;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -6117,7 +6117,7 @@ listOneExtensionContents(const char *extname, const char *oid) gettext_noop("Object description"), oid); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -6192,7 +6192,7 @@ listPublications(const char *pattern) appendPQExpBufferStr(&buf, "ORDER BY 1;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -6259,7 +6259,7 @@ describePublications(const char *pattern) appendPQExpBufferStr(&buf, "ORDER BY 2;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); if (!res) { termPQExpBuffer(&buf); @@ -6338,7 +6338,7 @@ describePublications(const char *pattern) " AND pr.prpubid = '%s'\n" "ORDER BY 1,2", pubid); - tabres = PSQLexec(buf.data); + tabres = PSQLexec("DESCRIBE", buf.data); if (!tabres) { printTableCleanup(&cont); @@ -6443,7 +6443,7 @@ describeSubscriptions(const char *pattern, bool verbose) appendPQExpBufferStr(&buf, "ORDER BY 1;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -6557,7 +6557,7 @@ listOperatorClasses(const char *access_method_pattern, } appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -6638,7 +6638,7 @@ listOperatorFamilies(const char *access_method_pattern, } appendPQExpBufferStr(&buf, "ORDER BY 1, 2;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -6725,7 +6725,7 @@ listOpFamilyOperators(const char *access_method_pattern, " pg_catalog.format_type(o.amoprighttype, NULL),\n" " o.amopstrategy;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; @@ -6806,7 +6806,7 @@ listOpFamilyFunctions(const char *access_method_pattern, " ap.amproclefttype = ap.amprocrighttype DESC,\n" " 3, 4, 5;"); - res = PSQLexec(buf.data); + res = PSQLexec("DESCRIBE", buf.data); termPQExpBuffer(&buf); if (!res) return false; diff --git a/src/bin/psql/large_obj.c b/src/bin/psql/large_obj.c index c15fcc0885..4d7a24e4e1 100644 --- a/src/bin/psql/large_obj.c +++ b/src/bin/psql/large_obj.c @@ -72,7 +72,7 @@ start_lo_xact(const char *operation, bool *own_transaction) { case PQTRANS_IDLE: /* need to start our own xact */ - if (!(res = PSQLexec("BEGIN"))) + if (!(res = PSQLexec("LO", "BEGIN"))) return false; PQclear(res); *own_transaction = true; @@ -102,9 +102,9 @@ finish_lo_xact(const char *operation, bool own_transaction) if (own_transaction && pset.autocommit) { /* close out our own xact */ - if (!(res = PSQLexec("COMMIT"))) + if (!(res = PSQLexec("LO", "COMMIT"))) { - res = PSQLexec("ROLLBACK"); + res = PSQLexec("LO", "ROLLBACK"); PQclear(res); return false; } @@ -125,7 +125,7 @@ fail_lo_xact(const char *operation, bool own_transaction) if (own_transaction && pset.autocommit) { /* close out our own xact */ - res = PSQLexec("ROLLBACK"); + res = PSQLexec("LO", "ROLLBACK"); PQclear(res); } @@ -208,7 +208,7 @@ do_lo_import(const char *filename_arg, const char *comment_arg) bufptr += PQescapeStringConn(pset.db, bufptr, comment_arg, slen, NULL); strcpy(bufptr, "'"); - if (!(res = PSQLexec(cmdbuf))) + if (!(res = PSQLexec("LO", cmdbuf))) { free(cmdbuf); return fail_lo_xact("\\lo_import", own_transaction); @@ -300,7 +300,7 @@ do_lo_list(void) gettext_noop("Description")); } - res = PSQLexec(buf); + res = PSQLexec("LO", buf); if (!res) return false; diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index 110906a4e9..773d35d010 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -345,7 +345,7 @@ main(int argc, char *argv[]) if (options.single_txn) { - if ((res = PSQLexec("BEGIN")) == NULL) + if ((res = PSQLexec("STARTUP", "BEGIN")) == NULL) { if (pset.on_error_stop) { @@ -411,7 +411,7 @@ main(int argc, char *argv[]) if (options.single_txn) { - if ((res = PSQLexec("COMMIT")) == NULL) + if ((res = PSQLexec("STARTUP", "COMMIT")) == NULL) { if (pset.on_error_stop) { diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out index 1b2f6bc418..0bc890ab72 100644 --- a/src/test/regress/expected/psql.out +++ b/src/test/regress/expected/psql.out @@ -244,10 +244,18 @@ from pg_attribute where attrelid = 'gexec_test'::regclass and attnum > 0 order by attnum \gexec +-- # GEXEC QUERY create index on gexec_test(a) + +-- # GEXEC QUERY create index on gexec_test(b) + +-- # GEXEC QUERY create index on gexec_test(c) + +-- # GEXEC QUERY create index on gexec_test(d) + -- \gexec should work in FETCH_COUNT mode too -- (though the fetch limit applies to the executed queries not the meta query) \set FETCH_COUNT 1 @@ -257,13 +265,17 @@ select 'drop table gexec_test', NULL union all select 'drop table gexec_test', 'select ''2000-01-01''::date as party_over' \gexec +-- # GEXEC QUERY select 1 as ones + ones ------ 1 (1 row) +-- # GEXEC QUERY select x.y, x.y*2 as double from generate_series(1,4) as x(y) + y | double ---+-------- 1 | 2 @@ -272,10 +284,16 @@ select x.y, x.y*2 as double from generate_series(1,4) as x(y) 4 | 8 (4 rows) +-- # GEXEC QUERY drop table gexec_test + +-- # GEXEC QUERY drop table gexec_test + ERROR: table "gexec_test" does not exist +-- # GEXEC QUERY select '2000-01-01'::date as party_over + party_over ------------ 01-01-2000