mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +03:00
Fix hard-coded relkind constants in assorted other files.
Although it's reasonable to expect that most of these constants will never change, that does not make it good programming style to hard-code the value rather than using the RELKIND_FOO macros. I think I've now gotten all the hard-coded references in C code. Unfortunately there's no equally convenient way to parameterize SQL files ... Discussion: https://postgr.es/m/11145.1488931324@sss.pgh.pa.us
This commit is contained in:
@ -9,6 +9,8 @@
|
|||||||
*/
|
*/
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
|
#include "catalog/pg_class.h"
|
||||||
|
|
||||||
#include "libpq-fe.h"
|
#include "libpq-fe.h"
|
||||||
#include "pg_getopt.h"
|
#include "pg_getopt.h"
|
||||||
|
|
||||||
@ -433,11 +435,12 @@ sql_exec_dumpalltables(PGconn *conn, struct options * opts)
|
|||||||
|
|
||||||
snprintf(todo, sizeof(todo),
|
snprintf(todo, sizeof(todo),
|
||||||
"SELECT pg_catalog.pg_relation_filenode(c.oid) as \"Filenode\", relname as \"Table Name\" %s "
|
"SELECT pg_catalog.pg_relation_filenode(c.oid) as \"Filenode\", relname as \"Table Name\" %s "
|
||||||
"FROM pg_class c "
|
"FROM pg_catalog.pg_class c "
|
||||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace "
|
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace "
|
||||||
" LEFT JOIN pg_catalog.pg_database d ON d.datname = pg_catalog.current_database(),"
|
" LEFT JOIN pg_catalog.pg_database d ON d.datname = pg_catalog.current_database(),"
|
||||||
" pg_catalog.pg_tablespace t "
|
" pg_catalog.pg_tablespace t "
|
||||||
"WHERE relkind IN ('r', 'm'%s%s) AND "
|
"WHERE relkind IN (" CppAsString2(RELKIND_RELATION) ","
|
||||||
|
CppAsString2(RELKIND_MATVIEW) "%s%s) AND "
|
||||||
" %s"
|
" %s"
|
||||||
" t.oid = CASE"
|
" t.oid = CASE"
|
||||||
" WHEN reltablespace <> 0 THEN reltablespace"
|
" WHEN reltablespace <> 0 THEN reltablespace"
|
||||||
@ -445,8 +448,8 @@ sql_exec_dumpalltables(PGconn *conn, struct options * opts)
|
|||||||
" END "
|
" END "
|
||||||
"ORDER BY relname",
|
"ORDER BY relname",
|
||||||
opts->extended ? addfields : "",
|
opts->extended ? addfields : "",
|
||||||
opts->indexes ? ", 'i', 'S'" : "",
|
opts->indexes ? "," CppAsString2(RELKIND_INDEX) "," CppAsString2(RELKIND_SEQUENCE) : "",
|
||||||
opts->systables ? ", 't'" : "",
|
opts->systables ? "," CppAsString2(RELKIND_TOASTVALUE) : "",
|
||||||
opts->systables ? "" : "n.nspname NOT IN ('pg_catalog', 'information_schema') AND n.nspname !~ '^pg_toast' AND");
|
opts->systables ? "" : "n.nspname NOT IN ('pg_catalog', 'information_schema') AND n.nspname !~ '^pg_toast' AND");
|
||||||
|
|
||||||
sql_exec(conn, todo, opts->quiet);
|
sql_exec(conn, todo, opts->quiet);
|
||||||
@ -507,7 +510,11 @@ sql_exec_searchtables(PGconn *conn, struct options * opts)
|
|||||||
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace \n"
|
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace \n"
|
||||||
" LEFT JOIN pg_catalog.pg_database d ON d.datname = pg_catalog.current_database(),\n"
|
" LEFT JOIN pg_catalog.pg_database d ON d.datname = pg_catalog.current_database(),\n"
|
||||||
" pg_catalog.pg_tablespace t \n"
|
" pg_catalog.pg_tablespace t \n"
|
||||||
"WHERE relkind IN ('r', 'm', 'i', 'S', 't') AND \n"
|
"WHERE relkind IN (" CppAsString2(RELKIND_RELATION) ","
|
||||||
|
CppAsString2(RELKIND_MATVIEW) ","
|
||||||
|
CppAsString2(RELKIND_INDEX) ","
|
||||||
|
CppAsString2(RELKIND_SEQUENCE) ","
|
||||||
|
CppAsString2(RELKIND_TOASTVALUE) ") AND \n"
|
||||||
" t.oid = CASE\n"
|
" t.oid = CASE\n"
|
||||||
" WHEN reltablespace <> 0 THEN reltablespace\n"
|
" WHEN reltablespace <> 0 THEN reltablespace\n"
|
||||||
" ELSE dattablespace\n"
|
" ELSE dattablespace\n"
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "access/htup_details.h"
|
#include "access/htup_details.h"
|
||||||
#include "access/sysattr.h"
|
#include "access/sysattr.h"
|
||||||
|
#include "catalog/pg_class.h"
|
||||||
#include "commands/defrem.h"
|
#include "commands/defrem.h"
|
||||||
#include "commands/explain.h"
|
#include "commands/explain.h"
|
||||||
#include "commands/vacuum.h"
|
#include "commands/vacuum.h"
|
||||||
@ -3885,7 +3886,11 @@ postgresImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
|
|||||||
" adrelid = c.oid AND adnum = attnum ");
|
" adrelid = c.oid AND adnum = attnum ");
|
||||||
|
|
||||||
appendStringInfoString(&buf,
|
appendStringInfoString(&buf,
|
||||||
"WHERE c.relkind IN ('r', 'v', 'f', 'm') "
|
"WHERE c.relkind IN ("
|
||||||
|
CppAsString2(RELKIND_RELATION) ","
|
||||||
|
CppAsString2(RELKIND_VIEW) ","
|
||||||
|
CppAsString2(RELKIND_FOREIGN_TABLE) ","
|
||||||
|
CppAsString2(RELKIND_MATVIEW) ") "
|
||||||
" AND n.nspname = ");
|
" AND n.nspname = ");
|
||||||
deparseStringLiteral(&buf, stmt->remote_schema);
|
deparseStringLiteral(&buf, stmt->remote_schema);
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "catalog/pg_class.h"
|
||||||
|
|
||||||
#include "libpq-fe.h"
|
#include "libpq-fe.h"
|
||||||
#include "pg_getopt.h"
|
#include "pg_getopt.h"
|
||||||
|
|
||||||
@ -209,7 +211,7 @@ vacuumlo(const char *database, const struct _param * param)
|
|||||||
strcat(buf, " AND a.atttypid = t.oid ");
|
strcat(buf, " AND a.atttypid = t.oid ");
|
||||||
strcat(buf, " AND c.relnamespace = s.oid ");
|
strcat(buf, " AND c.relnamespace = s.oid ");
|
||||||
strcat(buf, " AND t.typname in ('oid', 'lo') ");
|
strcat(buf, " AND t.typname in ('oid', 'lo') ");
|
||||||
strcat(buf, " AND c.relkind in ('r', 'm')");
|
strcat(buf, " AND c.relkind in (" CppAsString2(RELKIND_RELATION) ", " CppAsString2(RELKIND_MATVIEW) ")");
|
||||||
strcat(buf, " AND s.nspname !~ '^pg_'");
|
strcat(buf, " AND s.nspname !~ '^pg_'");
|
||||||
res = PQexec(conn, buf);
|
res = PQexec(conn, buf);
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
|
@ -69,6 +69,7 @@
|
|||||||
|
|
||||||
#include "access/htup_details.h"
|
#include "access/htup_details.h"
|
||||||
#include "catalog/namespace.h"
|
#include "catalog/namespace.h"
|
||||||
|
#include "catalog/pg_class.h"
|
||||||
#include "catalog/pg_type.h"
|
#include "catalog/pg_type.h"
|
||||||
#include "commands/dbcommands.h"
|
#include "commands/dbcommands.h"
|
||||||
#include "executor/executor.h"
|
#include "executor/executor.h"
|
||||||
@ -2344,7 +2345,13 @@ schema_get_xml_visible_tables(Oid nspid)
|
|||||||
StringInfoData query;
|
StringInfoData query;
|
||||||
|
|
||||||
initStringInfo(&query);
|
initStringInfo(&query);
|
||||||
appendStringInfo(&query, "SELECT oid FROM pg_catalog.pg_class WHERE relnamespace = %u AND relkind IN ('r', 'm', 'v') AND pg_catalog.has_table_privilege (oid, 'SELECT') ORDER BY relname;", nspid);
|
appendStringInfo(&query, "SELECT oid FROM pg_catalog.pg_class"
|
||||||
|
" WHERE relnamespace = %u AND relkind IN ("
|
||||||
|
CppAsString2(RELKIND_RELATION) ","
|
||||||
|
CppAsString2(RELKIND_MATVIEW) ","
|
||||||
|
CppAsString2(RELKIND_VIEW) ")"
|
||||||
|
" AND pg_catalog.has_table_privilege (oid, 'SELECT')"
|
||||||
|
" ORDER BY relname;", nspid);
|
||||||
|
|
||||||
return query_to_oid_list(query.data);
|
return query_to_oid_list(query.data);
|
||||||
}
|
}
|
||||||
@ -2370,7 +2377,13 @@ static List *
|
|||||||
database_get_xml_visible_tables(void)
|
database_get_xml_visible_tables(void)
|
||||||
{
|
{
|
||||||
/* At the moment there is no order required here. */
|
/* At the moment there is no order required here. */
|
||||||
return query_to_oid_list("SELECT oid FROM pg_catalog.pg_class WHERE relkind IN ('r', 'm', 'v') AND pg_catalog.has_table_privilege (pg_class.oid, 'SELECT') AND relnamespace IN (" XML_VISIBLE_SCHEMAS ");");
|
return query_to_oid_list("SELECT oid FROM pg_catalog.pg_class"
|
||||||
|
" WHERE relkind IN ("
|
||||||
|
CppAsString2(RELKIND_RELATION) ","
|
||||||
|
CppAsString2(RELKIND_MATVIEW) ","
|
||||||
|
CppAsString2(RELKIND_VIEW) ")"
|
||||||
|
" AND pg_catalog.has_table_privilege(pg_class.oid, 'SELECT')"
|
||||||
|
" AND relnamespace IN (" XML_VISIBLE_SCHEMAS ");");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
|
|
||||||
|
#include "catalog/pg_class.h"
|
||||||
|
|
||||||
#include "libpq-fe.h"
|
#include "libpq-fe.h"
|
||||||
#include "pqexpbuffer.h"
|
#include "pqexpbuffer.h"
|
||||||
|
|
||||||
@ -51,8 +53,8 @@ main(int argc, char **argv)
|
|||||||
"SELECT c.relname, (SELECT nspname FROM "
|
"SELECT c.relname, (SELECT nspname FROM "
|
||||||
"pg_catalog.pg_namespace n WHERE n.oid = c.relnamespace) AS nspname "
|
"pg_catalog.pg_namespace n WHERE n.oid = c.relnamespace) AS nspname "
|
||||||
"FROM pg_catalog.pg_class c "
|
"FROM pg_catalog.pg_class c "
|
||||||
"WHERE c.relkind = 'r' "
|
"WHERE c.relkind = " CppAsString2(RELKIND_RELATION)
|
||||||
"AND c.relhasoids "
|
" AND c.relhasoids "
|
||||||
"ORDER BY nspname, c.relname"
|
"ORDER BY nspname, c.relname"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -71,9 +73,10 @@ main(int argc, char **argv)
|
|||||||
"(SELECT nspname FROM pg_catalog.pg_namespace n WHERE n.oid = c.relnamespace) AS nspname, "
|
"(SELECT nspname FROM pg_catalog.pg_namespace n WHERE n.oid = c.relnamespace) AS nspname, "
|
||||||
"a.attname "
|
"a.attname "
|
||||||
"FROM pg_catalog.pg_class c, pg_catalog.pg_attribute a "
|
"FROM pg_catalog.pg_class c, pg_catalog.pg_attribute a "
|
||||||
"WHERE a.attnum > 0 AND c.relkind = 'r' "
|
"WHERE a.attnum > 0"
|
||||||
"AND a.attrelid = c.oid "
|
" AND c.relkind = " CppAsString2(RELKIND_RELATION)
|
||||||
"AND a.atttypid IN ('pg_catalog.oid'::regtype, "
|
" AND a.attrelid = c.oid"
|
||||||
|
" AND a.atttypid IN ('pg_catalog.oid'::regtype, "
|
||||||
" 'pg_catalog.regclass'::regtype, "
|
" 'pg_catalog.regclass'::regtype, "
|
||||||
" 'pg_catalog.regoper'::regtype, "
|
" 'pg_catalog.regoper'::regtype, "
|
||||||
" 'pg_catalog.regoperator'::regtype, "
|
" 'pg_catalog.regoperator'::regtype, "
|
||||||
@ -146,9 +149,10 @@ main(int argc, char **argv)
|
|||||||
"(SELECT nspname FROM pg_catalog.pg_namespace n WHERE n.oid = c.relnamespace) AS nspname, "
|
"(SELECT nspname FROM pg_catalog.pg_namespace n WHERE n.oid = c.relnamespace) AS nspname, "
|
||||||
"a.attname "
|
"a.attname "
|
||||||
"FROM pg_catalog.pg_class c, pg_catalog.pg_attribute a "
|
"FROM pg_catalog.pg_class c, pg_catalog.pg_attribute a "
|
||||||
"WHERE a.attnum > 0 AND c.relkind = 'r' "
|
"WHERE a.attnum > 0"
|
||||||
"AND a.attrelid = c.oid "
|
" AND c.relkind = " CppAsString2(RELKIND_RELATION)
|
||||||
"AND a.atttypid IN ('pg_catalog.oid[]'::regtype, "
|
" AND a.attrelid = c.oid"
|
||||||
|
" AND a.atttypid IN ('pg_catalog.oid[]'::regtype, "
|
||||||
" 'pg_catalog.regclass[]'::regtype, "
|
" 'pg_catalog.regclass[]'::regtype, "
|
||||||
" 'pg_catalog.regoper[]'::regtype, "
|
" 'pg_catalog.regoper[]'::regtype, "
|
||||||
" 'pg_catalog.regoperator[]'::regtype, "
|
" 'pg_catalog.regoperator[]'::regtype, "
|
||||||
|
Reference in New Issue
Block a user