aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2009-12-23 12:24:16 +0000
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2009-12-23 12:24:16 +0000
commita1ffb012174d3dbd3b8b42bdba593f829d9b678e (patch)
treeab906827f63d65184f207c4163742768cdb87960
parent7826bd450b84bfc2fff7ed76895e7d53ce726766 (diff)
downloadpostgresql-a1ffb012174d3dbd3b8b42bdba593f829d9b678e.tar.gz
postgresql-a1ffb012174d3dbd3b8b42bdba593f829d9b678e.zip
Always pass catalog id to the options validator function specified in
CREATE FOREIGN DATA WRAPPER. Arguably it wasn't a bug because the documentation said that it's passed the catalog ID or zero, but surely we should provide it when it's known. And there isn't currently any scenario where it's not known, and I can't imagine having one in the future either, so better remove the "or zero" escape hatch and always pass a valid catalog ID. Backpatch to 8.4. Martin Pihlak
-rw-r--r--doc/src/sgml/ref/create_foreign_data_wrapper.sgml9
-rw-r--r--src/backend/commands/foreigncmds.c32
-rw-r--r--src/backend/foreign/foreign.c6
-rw-r--r--src/test/regress/expected/foreign_data.out8
4 files changed, 34 insertions, 21 deletions
diff --git a/doc/src/sgml/ref/create_foreign_data_wrapper.sgml b/doc/src/sgml/ref/create_foreign_data_wrapper.sgml
index ee8b619a40e..c3fd2ad5e04 100644
--- a/doc/src/sgml/ref/create_foreign_data_wrapper.sgml
+++ b/doc/src/sgml/ref/create_foreign_data_wrapper.sgml
@@ -1,5 +1,5 @@
<!--
-$PostgreSQL: pgsql/doc/src/sgml/ref/create_foreign_data_wrapper.sgml,v 1.5 2009/06/19 15:28:25 petere Exp $
+$PostgreSQL: pgsql/doc/src/sgml/ref/create_foreign_data_wrapper.sgml,v 1.5.2.1 2009/12/23 12:24:02 heikki Exp $
PostgreSQL documentation
-->
@@ -74,10 +74,9 @@ CREATE FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable>
take two arguments: one of type <type>text[]</type>, which will
contain the array of options as stored in the system catalogs,
and one of type <type>oid</type>, which will be the OID of the
- system catalog containing the options, or zero if the context is
- not known. The return type is ignored; the function should
- indicate invalid options using
- the <function>ereport()</function> function.
+ system catalog containing the options. The return type is ignored;
+ the function should indicate invalid options using the
+ <function>ereport()</function> function.
</para>
</listitem>
</varlistentry>
diff --git a/src/backend/commands/foreigncmds.c b/src/backend/commands/foreigncmds.c
index 79706b0837b..6ae81ebc9a3 100644
--- a/src/backend/commands/foreigncmds.c
+++ b/src/backend/commands/foreigncmds.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/foreigncmds.c,v 1.8 2009/06/11 14:48:55 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/foreigncmds.c,v 1.8.2.1 2009/12/23 12:24:02 heikki Exp $
*
*-------------------------------------------------------------------------
*/
@@ -88,7 +88,8 @@ optionListToArray(List *options)
* This is used by CREATE/ALTER of FOREIGN DATA WRAPPER/SERVER/USER MAPPING.
*/
static Datum
-transformGenericOptions(Datum oldOptions,
+transformGenericOptions(Oid catalogId,
+ Datum oldOptions,
List *options,
Oid fdwvalidator)
{
@@ -162,7 +163,7 @@ transformGenericOptions(Datum oldOptions,
result = optionListToArray(resultOptions);
if (fdwvalidator)
- OidFunctionCall2(fdwvalidator, result, (Datum) 0);
+ OidFunctionCall2(fdwvalidator, result, ObjectIdGetDatum(catalogId));
return result;
}
@@ -384,7 +385,9 @@ CreateForeignDataWrapper(CreateFdwStmt *stmt)
nulls[Anum_pg_foreign_data_wrapper_fdwacl - 1] = true;
- fdwoptions = transformGenericOptions(PointerGetDatum(NULL), stmt->options,
+ fdwoptions = transformGenericOptions(ForeignDataWrapperRelationId,
+ PointerGetDatum(NULL),
+ stmt->options,
fdwvalidator);
if (PointerIsValid(DatumGetPointer(fdwoptions)))
@@ -501,7 +504,10 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt)
datum = PointerGetDatum(NULL);
/* Transform the options */
- datum = transformGenericOptions(datum, stmt->options, fdwvalidator);
+ datum = transformGenericOptions(ForeignDataWrapperRelationId,
+ datum,
+ stmt->options,
+ fdwvalidator);
if (PointerIsValid(DatumGetPointer(datum)))
repl_val[Anum_pg_foreign_data_wrapper_fdwoptions - 1] = datum;
@@ -667,7 +673,9 @@ CreateForeignServer(CreateForeignServerStmt *stmt)
nulls[Anum_pg_foreign_server_srvacl - 1] = true;
/* Add server options */
- srvoptions = transformGenericOptions(PointerGetDatum(NULL), stmt->options,
+ srvoptions = transformGenericOptions(ForeignServerRelationId,
+ PointerGetDatum(NULL),
+ stmt->options,
fdw->fdwvalidator);
if (PointerIsValid(DatumGetPointer(srvoptions)))
@@ -765,7 +773,9 @@ AlterForeignServer(AlterForeignServerStmt *stmt)
datum = PointerGetDatum(NULL);
/* Prepare the options array */
- datum = transformGenericOptions(datum, stmt->options,
+ datum = transformGenericOptions(ForeignServerRelationId,
+ datum,
+ stmt->options,
fdw->fdwvalidator);
if (PointerIsValid(DatumGetPointer(datum)))
@@ -936,7 +946,9 @@ CreateUserMapping(CreateUserMappingStmt *stmt)
values[Anum_pg_user_mapping_umserver - 1] = ObjectIdGetDatum(srv->serverid);
/* Add user options */
- useoptions = transformGenericOptions(PointerGetDatum(NULL), stmt->options,
+ useoptions = transformGenericOptions(UserMappingRelationId,
+ PointerGetDatum(NULL),
+ stmt->options,
fdw->fdwvalidator);
if (PointerIsValid(DatumGetPointer(useoptions)))
@@ -1031,7 +1043,9 @@ AlterUserMapping(AlterUserMappingStmt *stmt)
datum = PointerGetDatum(NULL);
/* Prepare the options array */
- datum = transformGenericOptions(datum, stmt->options,
+ datum = transformGenericOptions(UserMappingRelationId,
+ datum,
+ stmt->options,
fdw->fdwvalidator);
if (PointerIsValid(DatumGetPointer(datum)))
diff --git a/src/backend/foreign/foreign.c b/src/backend/foreign/foreign.c
index 04f0d348fb4..f32a296f5b3 100644
--- a/src/backend/foreign/foreign.c
+++ b/src/backend/foreign/foreign.c
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/foreign/foreign.c,v 1.5 2009/06/11 16:14:18 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/foreign/foreign.c,v 1.5.2.1 2009/12/23 12:24:15 heikki Exp $
*
*-------------------------------------------------------------------------
*/
@@ -372,7 +372,7 @@ is_conninfo_option(const char *option, Oid context)
struct ConnectionOption *opt;
for (opt = libpq_conninfo_options; opt->optname; opt++)
- if ((context == opt->optcontext || context == InvalidOid) && strcmp(opt->optname, option) == 0)
+ if (context == opt->optcontext && strcmp(opt->optname, option) == 0)
return true;
return false;
}
@@ -409,7 +409,7 @@ postgresql_fdw_validator(PG_FUNCTION_ARGS)
*/
initStringInfo(&buf);
for (opt = libpq_conninfo_options; opt->optname; opt++)
- if (catalog == InvalidOid || catalog == opt->optcontext)
+ if (catalog == opt->optcontext)
appendStringInfo(&buf, "%s%s", (buf.len > 0) ? ", " : "",
opt->optname);
diff --git a/src/test/regress/expected/foreign_data.out b/src/test/regress/expected/foreign_data.out
index 1d072cd3a83..5392be0eb36 100644
--- a/src/test/regress/expected/foreign_data.out
+++ b/src/test/regress/expected/foreign_data.out
@@ -284,7 +284,7 @@ CREATE SERVER s6 VERSION '16.0' FOREIGN DATA WRAPPER foo OPTIONS (host 'a', dbna
CREATE SERVER s7 TYPE 'oracle' VERSION '17.0' FOREIGN DATA WRAPPER foo OPTIONS (host 'a', dbname 'b');
CREATE SERVER s8 FOREIGN DATA WRAPPER postgresql OPTIONS (foo '1'); -- ERROR
ERROR: invalid option "foo"
-HINT: Valid options in this context are: authtype, service, user, password, connect_timeout, dbname, host, hostaddr, port, tty, options, requiressl, sslmode, gsslib
+HINT: Valid options in this context are: authtype, service, connect_timeout, dbname, host, hostaddr, port, tty, options, requiressl, sslmode, gsslib
CREATE SERVER s8 FOREIGN DATA WRAPPER postgresql OPTIONS (host 'localhost', dbname 's8db');
\des+
List of foreign servers
@@ -395,7 +395,7 @@ ERROR: permission denied for foreign-data wrapper foo
RESET ROLE;
ALTER SERVER s8 OPTIONS (foo '1'); -- ERROR option validation
ERROR: invalid option "foo"
-HINT: Valid options in this context are: authtype, service, user, password, connect_timeout, dbname, host, hostaddr, port, tty, options, requiressl, sslmode, gsslib
+HINT: Valid options in this context are: authtype, service, connect_timeout, dbname, host, hostaddr, port, tty, options, requiressl, sslmode, gsslib
ALTER SERVER s8 OPTIONS (connect_timeout '30', SET dbname 'db1', DROP host);
SET ROLE regress_test_role;
ALTER SERVER s1 OWNER TO regress_test_indirect; -- ERROR
@@ -534,7 +534,7 @@ ERROR: user mapping "foreign_data_user" already exists for server s4
CREATE USER MAPPING FOR public SERVER s4 OPTIONS (mapping 'is public');
CREATE USER MAPPING FOR user SERVER s8 OPTIONS (username 'test', password 'secret'); -- ERROR
ERROR: invalid option "username"
-HINT: Valid options in this context are: authtype, service, user, password, connect_timeout, dbname, host, hostaddr, port, tty, options, requiressl, sslmode, gsslib
+HINT: Valid options in this context are: user, password
CREATE USER MAPPING FOR user SERVER s8 OPTIONS (user 'test', password 'secret');
ALTER SERVER s5 OWNER TO regress_test_role;
ALTER SERVER s6 OWNER TO regress_test_indirect;
@@ -573,7 +573,7 @@ ALTER USER MAPPING FOR public SERVER s5 OPTIONS (gotcha 'true'); -- E
ERROR: user mapping "public" does not exist for the server
ALTER USER MAPPING FOR current_user SERVER s8 OPTIONS (username 'test'); -- ERROR
ERROR: invalid option "username"
-HINT: Valid options in this context are: authtype, service, user, password, connect_timeout, dbname, host, hostaddr, port, tty, options, requiressl, sslmode, gsslib
+HINT: Valid options in this context are: user, password
ALTER USER MAPPING FOR current_user SERVER s8 OPTIONS (DROP user, SET password 'public');
SET ROLE regress_test_role;
ALTER USER MAPPING FOR current_user SERVER s5 OPTIONS (ADD modified '1');