1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-14 18:42:34 +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

@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/proclang.c,v 1.91 2010/02/26 02:00:39 momjian Exp $
* $PostgreSQL: pgsql/src/backend/commands/proclang.c,v 1.92 2010/08/05 14:45:01 rhaas Exp $
*
*-------------------------------------------------------------------------
*/
@ -514,7 +514,7 @@ void
DropProceduralLanguage(DropPLangStmt *stmt)
{
char *languageName;
HeapTuple langTup;
Oid oid;
ObjectAddress object;
/*
@ -522,34 +522,26 @@ DropProceduralLanguage(DropPLangStmt *stmt)
*/
languageName = case_translate_language_name(stmt->plname);
langTup = SearchSysCache1(LANGNAME, CStringGetDatum(languageName));
if (!HeapTupleIsValid(langTup))
oid = get_language_oid(languageName, stmt->missing_ok);
if (!OidIsValid(oid))
{
if (!stmt->missing_ok)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("language \"%s\" does not exist", languageName)));
else
ereport(NOTICE,
(errmsg("language \"%s\" does not exist, skipping",
languageName)));
ereport(NOTICE,
(errmsg("language \"%s\" does not exist, skipping",
languageName)));
return;
}
/*
* Check permission
*/
if (!pg_language_ownercheck(HeapTupleGetOid(langTup), GetUserId()))
if (!pg_language_ownercheck(oid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_LANGUAGE,
languageName);
object.classId = LanguageRelationId;
object.objectId = HeapTupleGetOid(langTup);
object.objectId = oid;
object.objectSubId = 0;
ReleaseSysCache(langTup);
/*
* Do the deletion
*/
@ -735,3 +727,22 @@ AlterLanguageOwner_internal(HeapTuple tup, Relation rel, Oid newOwnerId)
newOwnerId);
}
}
/*
* get_language_oid - given a language name, look up the OID
*
* If missing_ok is false, throw an error if language name not found. If
* true, just return InvalidOid.
*/
Oid
get_language_oid(const char *langname, bool missing_ok)
{
Oid oid;
oid = GetSysCacheOid1(LANGNAME, CStringGetDatum(langname));
if (!OidIsValid(oid) && !missing_ok)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("language \"%s\" does not exist", langname)));
return oid;
}