Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4e766f2

Browse files
committed
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
1 parent b683908 commit 4e766f2

File tree

4 files changed

+34
-21
lines changed

4 files changed

+34
-21
lines changed

doc/src/sgml/ref/create_foreign_data_wrapper.sgml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_foreign_data_wrapper.sgml,v 1.5 2009/06/19 15:28:25 petere Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_foreign_data_wrapper.sgml,v 1.6 2009/12/23 12:23:58 heikki Exp $
33
PostgreSQL documentation
44
-->
55

@@ -74,10 +74,9 @@ CREATE FOREIGN DATA WRAPPER <replaceable class="parameter">name</replaceable>
7474
take two arguments: one of type <type>text[]</type>, which will
7575
contain the array of options as stored in the system catalogs,
7676
and one of type <type>oid</type>, which will be the OID of the
77-
system catalog containing the options, or zero if the context is
78-
not known. The return type is ignored; the function should
79-
indicate invalid options using
80-
the <function>ereport()</function> function.
77+
system catalog containing the options. The return type is ignored;
78+
the function should indicate invalid options using the
79+
<function>ereport()</function> function.
8180
</para>
8281
</listitem>
8382
</varlistentry>

src/backend/commands/foreigncmds.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/commands/foreigncmds.c,v 1.8 2009/06/11 14:48:55 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/commands/foreigncmds.c,v 1.9 2009/12/23 12:23:58 heikki Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -88,7 +88,8 @@ optionListToArray(List *options)
8888
* This is used by CREATE/ALTER of FOREIGN DATA WRAPPER/SERVER/USER MAPPING.
8989
*/
9090
static Datum
91-
transformGenericOptions(Datum oldOptions,
91+
transformGenericOptions(Oid catalogId,
92+
Datum oldOptions,
9293
List *options,
9394
Oid fdwvalidator)
9495
{
@@ -162,7 +163,7 @@ transformGenericOptions(Datum oldOptions,
162163
result = optionListToArray(resultOptions);
163164

164165
if (fdwvalidator)
165-
OidFunctionCall2(fdwvalidator, result, (Datum) 0);
166+
OidFunctionCall2(fdwvalidator, result, ObjectIdGetDatum(catalogId));
166167

167168
return result;
168169
}
@@ -384,7 +385,9 @@ CreateForeignDataWrapper(CreateFdwStmt *stmt)
384385

385386
nulls[Anum_pg_foreign_data_wrapper_fdwacl - 1] = true;
386387

387-
fdwoptions = transformGenericOptions(PointerGetDatum(NULL), stmt->options,
388+
fdwoptions = transformGenericOptions(ForeignDataWrapperRelationId,
389+
PointerGetDatum(NULL),
390+
stmt->options,
388391
fdwvalidator);
389392

390393
if (PointerIsValid(DatumGetPointer(fdwoptions)))
@@ -501,7 +504,10 @@ AlterForeignDataWrapper(AlterFdwStmt *stmt)
501504
datum = PointerGetDatum(NULL);
502505

503506
/* Transform the options */
504-
datum = transformGenericOptions(datum, stmt->options, fdwvalidator);
507+
datum = transformGenericOptions(ForeignDataWrapperRelationId,
508+
datum,
509+
stmt->options,
510+
fdwvalidator);
505511

506512
if (PointerIsValid(DatumGetPointer(datum)))
507513
repl_val[Anum_pg_foreign_data_wrapper_fdwoptions - 1] = datum;
@@ -667,7 +673,9 @@ CreateForeignServer(CreateForeignServerStmt *stmt)
667673
nulls[Anum_pg_foreign_server_srvacl - 1] = true;
668674

669675
/* Add server options */
670-
srvoptions = transformGenericOptions(PointerGetDatum(NULL), stmt->options,
676+
srvoptions = transformGenericOptions(ForeignServerRelationId,
677+
PointerGetDatum(NULL),
678+
stmt->options,
671679
fdw->fdwvalidator);
672680

673681
if (PointerIsValid(DatumGetPointer(srvoptions)))
@@ -765,7 +773,9 @@ AlterForeignServer(AlterForeignServerStmt *stmt)
765773
datum = PointerGetDatum(NULL);
766774

767775
/* Prepare the options array */
768-
datum = transformGenericOptions(datum, stmt->options,
776+
datum = transformGenericOptions(ForeignServerRelationId,
777+
datum,
778+
stmt->options,
769779
fdw->fdwvalidator);
770780

771781
if (PointerIsValid(DatumGetPointer(datum)))
@@ -936,7 +946,9 @@ CreateUserMapping(CreateUserMappingStmt *stmt)
936946
values[Anum_pg_user_mapping_umserver - 1] = ObjectIdGetDatum(srv->serverid);
937947

938948
/* Add user options */
939-
useoptions = transformGenericOptions(PointerGetDatum(NULL), stmt->options,
949+
useoptions = transformGenericOptions(UserMappingRelationId,
950+
PointerGetDatum(NULL),
951+
stmt->options,
940952
fdw->fdwvalidator);
941953

942954
if (PointerIsValid(DatumGetPointer(useoptions)))
@@ -1031,7 +1043,9 @@ AlterUserMapping(AlterUserMappingStmt *stmt)
10311043
datum = PointerGetDatum(NULL);
10321044

10331045
/* Prepare the options array */
1034-
datum = transformGenericOptions(datum, stmt->options,
1046+
datum = transformGenericOptions(UserMappingRelationId,
1047+
datum,
1048+
stmt->options,
10351049
fdw->fdwvalidator);
10361050

10371051
if (PointerIsValid(DatumGetPointer(datum)))

src/backend/foreign/foreign.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $PostgreSQL: pgsql/src/backend/foreign/foreign.c,v 1.5 2009/06/11 16:14:18 tgl Exp $
9+
* $PostgreSQL: pgsql/src/backend/foreign/foreign.c,v 1.6 2009/12/23 12:23:59 heikki Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -372,7 +372,7 @@ is_conninfo_option(const char *option, Oid context)
372372
struct ConnectionOption *opt;
373373

374374
for (opt = libpq_conninfo_options; opt->optname; opt++)
375-
if ((context == opt->optcontext || context == InvalidOid) && strcmp(opt->optname, option) == 0)
375+
if (context == opt->optcontext && strcmp(opt->optname, option) == 0)
376376
return true;
377377
return false;
378378
}
@@ -409,7 +409,7 @@ postgresql_fdw_validator(PG_FUNCTION_ARGS)
409409
*/
410410
initStringInfo(&buf);
411411
for (opt = libpq_conninfo_options; opt->optname; opt++)
412-
if (catalog == InvalidOid || catalog == opt->optcontext)
412+
if (catalog == opt->optcontext)
413413
appendStringInfo(&buf, "%s%s", (buf.len > 0) ? ", " : "",
414414
opt->optname);
415415

src/test/regress/expected/foreign_data.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ CREATE SERVER s6 VERSION '16.0' FOREIGN DATA WRAPPER foo OPTIONS (host 'a', dbna
284284
CREATE SERVER s7 TYPE 'oracle' VERSION '17.0' FOREIGN DATA WRAPPER foo OPTIONS (host 'a', dbname 'b');
285285
CREATE SERVER s8 FOREIGN DATA WRAPPER postgresql OPTIONS (foo '1'); -- ERROR
286286
ERROR: invalid option "foo"
287-
HINT: Valid options in this context are: authtype, service, user, password, connect_timeout, dbname, host, hostaddr, port, tty, options, requiressl, sslmode, gsslib
287+
HINT: Valid options in this context are: authtype, service, connect_timeout, dbname, host, hostaddr, port, tty, options, requiressl, sslmode, gsslib
288288
CREATE SERVER s8 FOREIGN DATA WRAPPER postgresql OPTIONS (host 'localhost', dbname 's8db');
289289
\des+
290290
List of foreign servers
@@ -395,7 +395,7 @@ ERROR: permission denied for foreign-data wrapper foo
395395
RESET ROLE;
396396
ALTER SERVER s8 OPTIONS (foo '1'); -- ERROR option validation
397397
ERROR: invalid option "foo"
398-
HINT: Valid options in this context are: authtype, service, user, password, connect_timeout, dbname, host, hostaddr, port, tty, options, requiressl, sslmode, gsslib
398+
HINT: Valid options in this context are: authtype, service, connect_timeout, dbname, host, hostaddr, port, tty, options, requiressl, sslmode, gsslib
399399
ALTER SERVER s8 OPTIONS (connect_timeout '30', SET dbname 'db1', DROP host);
400400
SET ROLE regress_test_role;
401401
ALTER SERVER s1 OWNER TO regress_test_indirect; -- ERROR
@@ -534,7 +534,7 @@ ERROR: user mapping "foreign_data_user" already exists for server s4
534534
CREATE USER MAPPING FOR public SERVER s4 OPTIONS (mapping 'is public');
535535
CREATE USER MAPPING FOR user SERVER s8 OPTIONS (username 'test', password 'secret'); -- ERROR
536536
ERROR: invalid option "username"
537-
HINT: Valid options in this context are: authtype, service, user, password, connect_timeout, dbname, host, hostaddr, port, tty, options, requiressl, sslmode, gsslib
537+
HINT: Valid options in this context are: user, password
538538
CREATE USER MAPPING FOR user SERVER s8 OPTIONS (user 'test', password 'secret');
539539
ALTER SERVER s5 OWNER TO regress_test_role;
540540
ALTER SERVER s6 OWNER TO regress_test_indirect;
@@ -573,7 +573,7 @@ ALTER USER MAPPING FOR public SERVER s5 OPTIONS (gotcha 'true'); -- E
573573
ERROR: user mapping "public" does not exist for the server
574574
ALTER USER MAPPING FOR current_user SERVER s8 OPTIONS (username 'test'); -- ERROR
575575
ERROR: invalid option "username"
576-
HINT: Valid options in this context are: authtype, service, user, password, connect_timeout, dbname, host, hostaddr, port, tty, options, requiressl, sslmode, gsslib
576+
HINT: Valid options in this context are: user, password
577577
ALTER USER MAPPING FOR current_user SERVER s8 OPTIONS (DROP user, SET password 'public');
578578
SET ROLE regress_test_role;
579579
ALTER USER MAPPING FOR current_user SERVER s5 OPTIONS (ADD modified '1');

0 commit comments

Comments
 (0)