1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-27 23:21:58 +03:00

Standardize get_whatever_oid functions for object types with

unqualified names.

- Add a missing_ok parameter to get_tablespace_oid.
- Avoid duplicating get_tablespace_od guts in objectNamesToOids.
- Add a missing_ok parameter to get_database_oid.
- Replace get_roleid and get_role_checked with get_role_oid.
- Add get_namespace_oid, get_language_oid, get_am_oid.
- Refactor existing code to use new interfaces.

Thanks to KaiGai Kohei for the review.
This commit is contained in:
Robert Haas
2010-08-05 14:45:09 +00:00
parent 641459f269
commit 2a6ef3445c
25 changed files with 259 additions and 437 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/schemacmds.c,v 1.57 2010/02/26 02:00:39 momjian Exp $
* $PostgreSQL: pgsql/src/backend/commands/schemacmds.c,v 1.58 2010/08/05 14:45:01 rhaas Exp $
*
*-------------------------------------------------------------------------
*/
@ -57,7 +57,7 @@ CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString)
* Who is supposed to own the new schema?
*/
if (authId)
owner_uid = get_roleid_checked(authId);
owner_uid = get_role_oid(authId, false);
else
owner_uid = saved_uid;
@ -178,24 +178,13 @@ RemoveSchemas(DropStmt *drop)
errmsg("schema name cannot be qualified")));
namespaceName = strVal(linitial(names));
namespaceId = GetSysCacheOid1(NAMESPACENAME,
CStringGetDatum(namespaceName));
namespaceId = get_namespace_oid(namespaceName, drop->missing_ok);
if (!OidIsValid(namespaceId))
{
if (!drop->missing_ok)
{
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist",
namespaceName)));
}
else
{
ereport(NOTICE,
(errmsg("schema \"%s\" does not exist, skipping",
namespaceName)));
}
ereport(NOTICE,
(errmsg("schema \"%s\" does not exist, skipping",
namespaceName)));
continue;
}
@ -264,9 +253,7 @@ RenameSchema(const char *oldname, const char *newname)
errmsg("schema \"%s\" does not exist", oldname)));
/* make sure the new name doesn't exist */
if (HeapTupleIsValid(
SearchSysCache1(NAMESPACENAME,
CStringGetDatum(newname))))
if (OidIsValid(get_namespace_oid(newname, true)))
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_SCHEMA),
errmsg("schema \"%s\" already exists", newname)));