mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +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:
@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.69 2010/07/16 00:13:23 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.70 2010/08/05 14:45:01 rhaas Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -641,7 +641,6 @@ DefineOpFamily(CreateOpFamilyStmt *stmt)
|
||||
char *opfname; /* name of opfamily we're creating */
|
||||
Oid amoid, /* our AM's oid */
|
||||
namespaceoid; /* namespace to create opfamily in */
|
||||
HeapTuple tup;
|
||||
AclResult aclresult;
|
||||
|
||||
/* Convert list of names to a name and namespace */
|
||||
@ -654,20 +653,11 @@ DefineOpFamily(CreateOpFamilyStmt *stmt)
|
||||
aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
|
||||
get_namespace_name(namespaceoid));
|
||||
|
||||
/* Get necessary info about access method */
|
||||
tup = SearchSysCache1(AMNAME, CStringGetDatum(stmt->amname));
|
||||
if (!HeapTupleIsValid(tup))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("access method \"%s\" does not exist",
|
||||
stmt->amname)));
|
||||
|
||||
amoid = HeapTupleGetOid(tup);
|
||||
/* Get access method OID, throwing an error if it doesn't exist. */
|
||||
amoid = get_am_oid(stmt->amname, false);
|
||||
|
||||
/* XXX Should we make any privilege check against the AM? */
|
||||
|
||||
ReleaseSysCache(tup);
|
||||
|
||||
/*
|
||||
* Currently, we require superuser privileges to create an opfamily. See
|
||||
* comments in DefineOpClass.
|
||||
@ -1427,12 +1417,7 @@ RemoveOpClass(RemoveOpClassStmt *stmt)
|
||||
/*
|
||||
* Get the access method's OID.
|
||||
*/
|
||||
amID = GetSysCacheOid1(AMNAME, CStringGetDatum(stmt->amname));
|
||||
if (!OidIsValid(amID))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("access method \"%s\" does not exist",
|
||||
stmt->amname)));
|
||||
amID = get_am_oid(stmt->amname, false);
|
||||
|
||||
/*
|
||||
* Look up the opclass.
|
||||
@ -1488,12 +1473,7 @@ RemoveOpFamily(RemoveOpFamilyStmt *stmt)
|
||||
/*
|
||||
* Get the access method's OID.
|
||||
*/
|
||||
amID = GetSysCacheOid1(AMNAME, CStringGetDatum(stmt->amname));
|
||||
if (!OidIsValid(amID))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("access method \"%s\" does not exist",
|
||||
stmt->amname)));
|
||||
amID = get_am_oid(stmt->amname, false);
|
||||
|
||||
/*
|
||||
* Look up the opfamily.
|
||||
@ -1650,12 +1630,7 @@ RenameOpClass(List *name, const char *access_method, const char *newname)
|
||||
Relation rel;
|
||||
AclResult aclresult;
|
||||
|
||||
amOid = GetSysCacheOid1(AMNAME, CStringGetDatum(access_method));
|
||||
if (!OidIsValid(amOid))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("access method \"%s\" does not exist",
|
||||
access_method)));
|
||||
amOid = get_am_oid(access_method, false);
|
||||
|
||||
rel = heap_open(OperatorClassRelationId, RowExclusiveLock);
|
||||
|
||||
@ -1744,12 +1719,7 @@ RenameOpFamily(List *name, const char *access_method, const char *newname)
|
||||
Relation rel;
|
||||
AclResult aclresult;
|
||||
|
||||
amOid = GetSysCacheOid1(AMNAME, CStringGetDatum(access_method));
|
||||
if (!OidIsValid(amOid))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("access method \"%s\" does not exist",
|
||||
access_method)));
|
||||
amOid = get_am_oid(access_method, false);
|
||||
|
||||
rel = heap_open(OperatorFamilyRelationId, RowExclusiveLock);
|
||||
|
||||
@ -1835,12 +1805,7 @@ AlterOpClassOwner(List *name, const char *access_method, Oid newOwnerId)
|
||||
char *opcname;
|
||||
char *schemaname;
|
||||
|
||||
amOid = GetSysCacheOid1(AMNAME, CStringGetDatum(access_method));
|
||||
if (!OidIsValid(amOid))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("access method \"%s\" does not exist",
|
||||
access_method)));
|
||||
amOid = get_am_oid(access_method, false);
|
||||
|
||||
rel = heap_open(OperatorClassRelationId, RowExclusiveLock);
|
||||
|
||||
@ -1978,12 +1943,7 @@ AlterOpFamilyOwner(List *name, const char *access_method, Oid newOwnerId)
|
||||
char *opfname;
|
||||
char *schemaname;
|
||||
|
||||
amOid = GetSysCacheOid1(AMNAME, CStringGetDatum(access_method));
|
||||
if (!OidIsValid(amOid))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("access method \"%s\" does not exist",
|
||||
access_method)));
|
||||
amOid = get_am_oid(access_method, false);
|
||||
|
||||
rel = heap_open(OperatorFamilyRelationId, RowExclusiveLock);
|
||||
|
||||
@ -2108,3 +2068,22 @@ AlterOpFamilyOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
|
||||
newOwnerId);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* get_am_oid - given an access method name, look up the OID
|
||||
*
|
||||
* If missing_ok is false, throw an error if access method not found. If
|
||||
* true, just return InvalidOid.
|
||||
*/
|
||||
Oid
|
||||
get_am_oid(const char *amname, bool missing_ok)
|
||||
{
|
||||
Oid oid;
|
||||
|
||||
oid = GetSysCacheOid1(AMNAME, CStringGetDatum(amname));
|
||||
if (!OidIsValid(oid) && !missing_ok)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||
errmsg("access method \"%s\" does not exist", amname)));
|
||||
return oid;
|
||||
}
|
||||
|
Reference in New Issue
Block a user