From 5cc6fbd70b889632238049f9477561c61a04e0a3 Mon Sep 17 00:00:00 2001 From: Mark Dilger Date: Wed, 6 Jan 2021 13:51:02 -0800 Subject: [PATCH v3 6/9] Refactoring expand_schema_name_patterns and friends. Refactoring these functions to take a PGconn pointer rather than an Archive pointer in preparation for moving these functions to fe_utils. This is much like what was previously done for ExecuteSqlQuery and friends, and for the same reasons. --- src/bin/pg_dump/pg_dump.c | 47 ++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index e8985a834f..41ce4b7866 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -55,6 +55,7 @@ #include "catalog/pg_type_d.h" #include "common/connect.h" #include "dumputils.h" +#include "fe_utils/query_utils.h" #include "fe_utils/string_utils.h" #include "getopt_long.h" #include "libpq/libpq-fs.h" @@ -147,14 +148,14 @@ static void setup_connection(Archive *AH, const char *dumpencoding, const char *dumpsnapshot, char *use_role); static ArchiveFormat parseArchiveFormat(const char *format, ArchiveMode *mode); -static void expand_schema_name_patterns(Archive *fout, +static void expand_schema_name_patterns(PGconn *conn, SimpleStringList *patterns, SimpleOidList *oids, bool strict_names); -static void expand_foreign_server_name_patterns(Archive *fout, +static void expand_foreign_server_name_patterns(PGconn *conn, SimpleStringList *patterns, SimpleOidList *oids); -static void expand_table_name_patterns(Archive *fout, +static void expand_table_name_patterns(PGconn *conn, SimpleStringList *patterns, SimpleOidList *oids, bool strict_names); @@ -798,13 +799,15 @@ main(int argc, char **argv) /* Expand schema selection patterns into OID lists */ if (schema_include_patterns.head != NULL) { - expand_schema_name_patterns(fout, &schema_include_patterns, + expand_schema_name_patterns(GetConnection(fout), + &schema_include_patterns, &schema_include_oids, strict_names); if (schema_include_oids.head == NULL) fatal("no matching schemas were found"); } - expand_schema_name_patterns(fout, &schema_exclude_patterns, + expand_schema_name_patterns(GetConnection(fout), + &schema_exclude_patterns, &schema_exclude_oids, false); /* non-matching exclusion patterns aren't an error */ @@ -812,21 +815,25 @@ main(int argc, char **argv) /* Expand table selection patterns into OID lists */ if (table_include_patterns.head != NULL) { - expand_table_name_patterns(fout, &table_include_patterns, + expand_table_name_patterns(GetConnection(fout), + &table_include_patterns, &table_include_oids, strict_names); if (table_include_oids.head == NULL) fatal("no matching tables were found"); } - expand_table_name_patterns(fout, &table_exclude_patterns, + expand_table_name_patterns(GetConnection(fout), + &table_exclude_patterns, &table_exclude_oids, false); - expand_table_name_patterns(fout, &tabledata_exclude_patterns, + expand_table_name_patterns(GetConnection(fout), + &tabledata_exclude_patterns, &tabledata_exclude_oids, false); - expand_foreign_server_name_patterns(fout, &foreign_servers_include_patterns, + expand_foreign_server_name_patterns(GetConnection(fout), + &foreign_servers_include_patterns, &foreign_servers_include_oids); /* non-matching exclusion patterns aren't an error */ @@ -1316,7 +1323,7 @@ parseArchiveFormat(const char *format, ArchiveMode *mode) * and append them to the given OID list. */ static void -expand_schema_name_patterns(Archive *fout, +expand_schema_name_patterns(PGconn *conn, SimpleStringList *patterns, SimpleOidList *oids, bool strict_names) @@ -1340,10 +1347,10 @@ expand_schema_name_patterns(Archive *fout, { appendPQExpBufferStr(query, "SELECT oid FROM pg_catalog.pg_namespace n\n"); - processSQLNamePattern(GetConnection(fout), query, cell->val, false, + processSQLNamePattern(conn, query, cell->val, false, false, NULL, "n.nspname", NULL, NULL); - res = ExecuteSqlQueryAH(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(conn, query->data, PGRES_TUPLES_OK); if (strict_names && PQntuples(res) == 0) fatal("no matching schemas were found for pattern \"%s\"", cell->val); @@ -1364,7 +1371,7 @@ expand_schema_name_patterns(Archive *fout, * and append them to the given OID list. */ static void -expand_foreign_server_name_patterns(Archive *fout, +expand_foreign_server_name_patterns(PGconn *conn, SimpleStringList *patterns, SimpleOidList *oids) { @@ -1387,10 +1394,10 @@ expand_foreign_server_name_patterns(Archive *fout, { appendPQExpBufferStr(query, "SELECT oid FROM pg_catalog.pg_foreign_server s\n"); - processSQLNamePattern(GetConnection(fout), query, cell->val, false, + processSQLNamePattern(conn, query, cell->val, false, false, NULL, "s.srvname", NULL, NULL); - res = ExecuteSqlQueryAH(fout, query->data, PGRES_TUPLES_OK); + res = ExecuteSqlQuery(conn, query->data, PGRES_TUPLES_OK); if (PQntuples(res) == 0) fatal("no matching foreign servers were found for pattern \"%s\"", cell->val); @@ -1410,7 +1417,7 @@ expand_foreign_server_name_patterns(Archive *fout, * in pg_dumpall.c */ static void -expand_table_name_patterns(Archive *fout, +expand_table_name_patterns(PGconn *conn, SimpleStringList *patterns, SimpleOidList *oids, bool strict_names) { @@ -1446,13 +1453,13 @@ expand_table_name_patterns(Archive *fout, RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW, RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE, RELKIND_PARTITIONED_TABLE); - processSQLNamePattern(GetConnection(fout), query, cell->val, true, + processSQLNamePattern(conn, query, cell->val, true, false, "n.nspname", "c.relname", NULL, "pg_catalog.pg_table_is_visible(c.oid)"); - ExecuteSqlStatementAH(fout, "RESET search_path"); - res = ExecuteSqlQueryAH(fout, query->data, PGRES_TUPLES_OK); - PQclear(ExecuteSqlQueryForSingleRowAH(fout, + ExecuteSqlStatement(conn, "RESET search_path"); + res = ExecuteSqlQuery(conn, query->data, PGRES_TUPLES_OK); + PQclear(ExecuteSqlQueryForSingleRow(conn, ALWAYS_SECURE_SEARCH_PATH_SQL)); if (strict_names && PQntuples(res) == 0) fatal("no matching tables were found for pattern \"%s\"", cell->val); -- 2.21.1 (Apple Git-122.3)