mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Create the catalog infrastructure for foreign-data-wrapper handlers.
Add a fdwhandler column to pg_foreign_data_wrapper, plus HANDLER options in the CREATE FOREIGN DATA WRAPPER and ALTER FOREIGN DATA WRAPPER commands, plus pg_dump support for same. Also invent a new pseudotype fdw_handler with properties similar to language_handler. This is split out of the "FDW API" patch for ease of review; it's all stuff we will certainly need, regardless of any other details of the FDW API. FDW handler functions will not actually get called yet. In passing, fix some omissions and infelicities in foreigncmds.c. Shigeru Hanada, Jan Urbanski, Heikki Linnakangas
This commit is contained in:
@@ -6260,6 +6260,7 @@ getForeignDataWrappers(int *numForeignDataWrappers)
|
||||
int i_oid;
|
||||
int i_fdwname;
|
||||
int i_rolname;
|
||||
int i_fdwhandler;
|
||||
int i_fdwvalidator;
|
||||
int i_fdwacl;
|
||||
int i_fdwoptions;
|
||||
@@ -6274,13 +6275,30 @@ getForeignDataWrappers(int *numForeignDataWrappers)
|
||||
/* Make sure we are in proper schema */
|
||||
selectSourceSchema("pg_catalog");
|
||||
|
||||
appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
|
||||
"(%s fdwowner) AS rolname, fdwvalidator::pg_catalog.regproc, fdwacl,"
|
||||
"array_to_string(ARRAY("
|
||||
" SELECT option_name || ' ' || quote_literal(option_value) "
|
||||
" FROM pg_options_to_table(fdwoptions)), ', ') AS fdwoptions "
|
||||
"FROM pg_foreign_data_wrapper",
|
||||
username_subquery);
|
||||
if (g_fout->remoteVersion >= 90100)
|
||||
{
|
||||
appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
|
||||
"(%s fdwowner) AS rolname, "
|
||||
"fdwhandler::pg_catalog.regproc, "
|
||||
"fdwvalidator::pg_catalog.regproc, fdwacl, "
|
||||
"array_to_string(ARRAY("
|
||||
" SELECT option_name || ' ' || quote_literal(option_value) "
|
||||
" FROM pg_options_to_table(fdwoptions)), ', ') AS fdwoptions "
|
||||
"FROM pg_foreign_data_wrapper",
|
||||
username_subquery);
|
||||
}
|
||||
else
|
||||
{
|
||||
appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
|
||||
"(%s fdwowner) AS rolname, "
|
||||
"'-' AS fdwhandler, "
|
||||
"fdwvalidator::pg_catalog.regproc, fdwacl, "
|
||||
"array_to_string(ARRAY("
|
||||
" SELECT option_name || ' ' || quote_literal(option_value) "
|
||||
" FROM pg_options_to_table(fdwoptions)), ', ') AS fdwoptions "
|
||||
"FROM pg_foreign_data_wrapper",
|
||||
username_subquery);
|
||||
}
|
||||
|
||||
res = PQexec(g_conn, query->data);
|
||||
check_sql_result(res, g_conn, query->data, PGRES_TUPLES_OK);
|
||||
@@ -6294,6 +6312,7 @@ getForeignDataWrappers(int *numForeignDataWrappers)
|
||||
i_oid = PQfnumber(res, "oid");
|
||||
i_fdwname = PQfnumber(res, "fdwname");
|
||||
i_rolname = PQfnumber(res, "rolname");
|
||||
i_fdwhandler = PQfnumber(res, "fdwhandler");
|
||||
i_fdwvalidator = PQfnumber(res, "fdwvalidator");
|
||||
i_fdwacl = PQfnumber(res, "fdwacl");
|
||||
i_fdwoptions = PQfnumber(res, "fdwoptions");
|
||||
@@ -6307,11 +6326,11 @@ getForeignDataWrappers(int *numForeignDataWrappers)
|
||||
fdwinfo[i].dobj.name = strdup(PQgetvalue(res, i, i_fdwname));
|
||||
fdwinfo[i].dobj.namespace = NULL;
|
||||
fdwinfo[i].rolname = strdup(PQgetvalue(res, i, i_rolname));
|
||||
fdwinfo[i].fdwhandler = strdup(PQgetvalue(res, i, i_fdwhandler));
|
||||
fdwinfo[i].fdwvalidator = strdup(PQgetvalue(res, i, i_fdwvalidator));
|
||||
fdwinfo[i].fdwoptions = strdup(PQgetvalue(res, i, i_fdwoptions));
|
||||
fdwinfo[i].fdwacl = strdup(PQgetvalue(res, i, i_fdwacl));
|
||||
|
||||
|
||||
/* Decide whether we want to dump it */
|
||||
selectDumpableObject(&(fdwinfo[i].dobj));
|
||||
}
|
||||
@@ -10929,11 +10948,13 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo)
|
||||
appendPQExpBuffer(q, "CREATE FOREIGN DATA WRAPPER %s",
|
||||
qfdwname);
|
||||
|
||||
if (fdwinfo->fdwvalidator && strcmp(fdwinfo->fdwvalidator, "-") != 0)
|
||||
appendPQExpBuffer(q, " VALIDATOR %s",
|
||||
fdwinfo->fdwvalidator);
|
||||
if (strcmp(fdwinfo->fdwhandler, "-") != 0)
|
||||
appendPQExpBuffer(q, " HANDLER %s", fdwinfo->fdwhandler);
|
||||
|
||||
if (fdwinfo->fdwoptions && strlen(fdwinfo->fdwoptions) > 0)
|
||||
if (strcmp(fdwinfo->fdwvalidator, "-") != 0)
|
||||
appendPQExpBuffer(q, " VALIDATOR %s", fdwinfo->fdwvalidator);
|
||||
|
||||
if (strlen(fdwinfo->fdwoptions) > 0)
|
||||
appendPQExpBuffer(q, " OPTIONS (%s)", fdwinfo->fdwoptions);
|
||||
|
||||
appendPQExpBuffer(q, ";\n");
|
||||
|
Reference in New Issue
Block a user