Commit 2a6ef344 authored by Robert Haas's avatar Robert Haas

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.
parent 641459f2
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.168 2010/07/06 19:18:55 momjian Exp $ * $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.169 2010/08/05 14:44:58 rhaas Exp $
* *
* NOTES * NOTES
* See acl.h. * See acl.h.
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
#include "catalog/pg_ts_config.h" #include "catalog/pg_ts_config.h"
#include "catalog/pg_ts_dict.h" #include "catalog/pg_ts_dict.h"
#include "commands/dbcommands.h" #include "commands/dbcommands.h"
#include "commands/proclang.h"
#include "commands/tablespace.h"
#include "foreign/foreign.h" #include "foreign/foreign.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "parser/parse_func.h" #include "parser/parse_func.h"
...@@ -419,7 +421,7 @@ ExecuteGrantStmt(GrantStmt *stmt) ...@@ -419,7 +421,7 @@ ExecuteGrantStmt(GrantStmt *stmt)
else else
istmt.grantees = istmt.grantees =
lappend_oid(istmt.grantees, lappend_oid(istmt.grantees,
get_roleid_checked(grantee->rolname)); get_role_oid(grantee->rolname, false));
} }
/* /*
...@@ -607,12 +609,7 @@ objectNamesToOids(GrantObjectType objtype, List *objnames) ...@@ -607,12 +609,7 @@ objectNamesToOids(GrantObjectType objtype, List *objnames)
char *dbname = strVal(lfirst(cell)); char *dbname = strVal(lfirst(cell));
Oid dbid; Oid dbid;
dbid = get_database_oid(dbname); dbid = get_database_oid(dbname, false);
if (!OidIsValid(dbid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_DATABASE),
errmsg("database \"%s\" does not exist",
dbname)));
objects = lappend_oid(objects, dbid); objects = lappend_oid(objects, dbid);
} }
break; break;
...@@ -631,18 +628,10 @@ objectNamesToOids(GrantObjectType objtype, List *objnames) ...@@ -631,18 +628,10 @@ objectNamesToOids(GrantObjectType objtype, List *objnames)
foreach(cell, objnames) foreach(cell, objnames)
{ {
char *langname = strVal(lfirst(cell)); char *langname = strVal(lfirst(cell));
HeapTuple tuple; Oid oid;
tuple = SearchSysCache1(LANGNAME, PointerGetDatum(langname));
if (!HeapTupleIsValid(tuple))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("language \"%s\" does not exist",
langname)));
objects = lappend_oid(objects, HeapTupleGetOid(tuple)); oid = get_language_oid(langname, false);
objects = lappend_oid(objects, oid);
ReleaseSysCache(tuple);
} }
break; break;
case ACL_OBJECT_LARGEOBJECT: case ACL_OBJECT_LARGEOBJECT:
...@@ -663,49 +652,20 @@ objectNamesToOids(GrantObjectType objtype, List *objnames) ...@@ -663,49 +652,20 @@ objectNamesToOids(GrantObjectType objtype, List *objnames)
foreach(cell, objnames) foreach(cell, objnames)
{ {
char *nspname = strVal(lfirst(cell)); char *nspname = strVal(lfirst(cell));
HeapTuple tuple; Oid oid;
tuple = SearchSysCache1(NAMESPACENAME,
CStringGetDatum(nspname));
if (!HeapTupleIsValid(tuple))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist",
nspname)));
objects = lappend_oid(objects, HeapTupleGetOid(tuple));
ReleaseSysCache(tuple); oid = get_namespace_oid(nspname, false);
objects = lappend_oid(objects, oid);
} }
break; break;
case ACL_OBJECT_TABLESPACE: case ACL_OBJECT_TABLESPACE:
foreach(cell, objnames) foreach(cell, objnames)
{ {
char *spcname = strVal(lfirst(cell)); char *spcname = strVal(lfirst(cell));
ScanKeyData entry[1]; Oid spcoid;
HeapScanDesc scan;
HeapTuple tuple;
Relation relation;
relation = heap_open(TableSpaceRelationId, AccessShareLock); spcoid = get_tablespace_oid(spcname, false);
objects = lappend_oid(objects, spcoid);
ScanKeyInit(&entry[0],
Anum_pg_tablespace_spcname,
BTEqualStrategyNumber, F_NAMEEQ,
CStringGetDatum(spcname));
scan = heap_beginscan(relation, SnapshotNow, 1, entry);
tuple = heap_getnext(scan, ForwardScanDirection);
if (!HeapTupleIsValid(tuple))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("tablespace \"%s\" does not exist", spcname)));
objects = lappend_oid(objects, HeapTupleGetOid(tuple));
heap_endscan(scan);
heap_close(relation, AccessShareLock);
} }
break; break;
case ACL_OBJECT_FDW: case ACL_OBJECT_FDW:
...@@ -913,7 +873,7 @@ ExecAlterDefaultPrivilegesStmt(AlterDefaultPrivilegesStmt *stmt) ...@@ -913,7 +873,7 @@ ExecAlterDefaultPrivilegesStmt(AlterDefaultPrivilegesStmt *stmt)
else else
iacls.grantees = iacls.grantees =
lappend_oid(iacls.grantees, lappend_oid(iacls.grantees,
get_roleid_checked(grantee->rolname)); get_role_oid(grantee->rolname, false));
} }
/* /*
...@@ -996,7 +956,7 @@ ExecAlterDefaultPrivilegesStmt(AlterDefaultPrivilegesStmt *stmt) ...@@ -996,7 +956,7 @@ ExecAlterDefaultPrivilegesStmt(AlterDefaultPrivilegesStmt *stmt)
{ {
char *rolename = strVal(lfirst(rolecell)); char *rolename = strVal(lfirst(rolecell));
iacls.roleid = get_roleid_checked(rolename); iacls.roleid = get_role_oid(rolename, false);
/* /*
* We insist that calling user be a member of each target role. If * We insist that calling user be a member of each target role. If
...@@ -1037,18 +997,12 @@ SetDefaultACLsInSchemas(InternalDefaultACL *iacls, List *nspnames) ...@@ -1037,18 +997,12 @@ SetDefaultACLsInSchemas(InternalDefaultACL *iacls, List *nspnames)
AclResult aclresult; AclResult aclresult;
/* /*
* Normally we'd use LookupCreationNamespace here, but it's * Note that we must do the permissions check against the target
* important to do the permissions check against the target role * role not the calling user. We require CREATE privileges,
* not the calling user, so write it out in full. We require * since without CREATE you won't be able to do anything using the
* CREATE privileges, since without CREATE you won't be able to do * default privs anyway.
* anything using the default privs anyway.
*/ */
iacls->nspid = GetSysCacheOid1(NAMESPACENAME, iacls->nspid = get_namespace_oid(nspname, false);
CStringGetDatum(nspname));
if (!OidIsValid(iacls->nspid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist", nspname)));
aclresult = pg_namespace_aclcheck(iacls->nspid, iacls->roleid, aclresult = pg_namespace_aclcheck(iacls->nspid, iacls->roleid,
ACL_CREATE); ACL_CREATE);
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.125 2010/02/26 02:00:36 momjian Exp $ * $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.126 2010/08/05 14:44:58 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -332,13 +332,7 @@ RangeVarGetCreationNamespace(const RangeVar *newRelation) ...@@ -332,13 +332,7 @@ RangeVarGetCreationNamespace(const RangeVar *newRelation)
return myTempNamespace; return myTempNamespace;
} }
/* use exact schema given */ /* use exact schema given */
namespaceId = GetSysCacheOid1(NAMESPACENAME, namespaceId = get_namespace_oid(newRelation->schemaname, false);
CStringGetDatum(newRelation->schemaname));
if (!OidIsValid(namespaceId))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist",
newRelation->schemaname)));
/* we do not check for USAGE rights here! */ /* we do not check for USAGE rights here! */
} }
else else
...@@ -2270,7 +2264,7 @@ LookupNamespaceNoError(const char *nspname) ...@@ -2270,7 +2264,7 @@ LookupNamespaceNoError(const char *nspname)
return InvalidOid; return InvalidOid;
} }
return GetSysCacheOid1(NAMESPACENAME, CStringGetDatum(nspname)); return get_namespace_oid(nspname, true);
} }
/* /*
...@@ -2300,11 +2294,7 @@ LookupExplicitNamespace(const char *nspname) ...@@ -2300,11 +2294,7 @@ LookupExplicitNamespace(const char *nspname)
*/ */
} }
namespaceId = GetSysCacheOid1(NAMESPACENAME, CStringGetDatum(nspname)); namespaceId = get_namespace_oid(nspname, false);
if (!OidIsValid(namespaceId))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist", nspname)));
aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_USAGE); aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_USAGE);
if (aclresult != ACLCHECK_OK) if (aclresult != ACLCHECK_OK)
...@@ -2339,11 +2329,7 @@ LookupCreationNamespace(const char *nspname) ...@@ -2339,11 +2329,7 @@ LookupCreationNamespace(const char *nspname)
return myTempNamespace; return myTempNamespace;
} }
namespaceId = GetSysCacheOid1(NAMESPACENAME, CStringGetDatum(nspname)); namespaceId = get_namespace_oid(nspname, false);
if (!OidIsValid(namespaceId))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist", nspname)));
aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_CREATE); aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_CREATE);
if (aclresult != ACLCHECK_OK) if (aclresult != ACLCHECK_OK)
...@@ -2385,12 +2371,7 @@ QualifiedNameGetCreationNamespace(List *names, char **objname_p) ...@@ -2385,12 +2371,7 @@ QualifiedNameGetCreationNamespace(List *names, char **objname_p)
return myTempNamespace; return myTempNamespace;
} }
/* use exact schema given */ /* use exact schema given */
namespaceId = GetSysCacheOid1(NAMESPACENAME, namespaceId = get_namespace_oid(schemaname, false);
CStringGetDatum(schemaname));
if (!OidIsValid(namespaceId))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist", schemaname)));
/* we do not check for USAGE rights here! */ /* we do not check for USAGE rights here! */
} }
else else
...@@ -2413,6 +2394,26 @@ QualifiedNameGetCreationNamespace(List *names, char **objname_p) ...@@ -2413,6 +2394,26 @@ QualifiedNameGetCreationNamespace(List *names, char **objname_p)
return namespaceId; return namespaceId;
} }
/*
* get_namespace_oid - given a namespace name, look up the OID
*
* If missing_ok is false, throw an error if namespace name not found. If
* true, just return InvalidOid.
*/
Oid
get_namespace_oid(const char *nspname, bool missing_ok)
{
Oid oid;
oid = GetSysCacheOid1(NAMESPACENAME, CStringGetDatum(nspname));
if (!OidIsValid(oid) && !missing_ok)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist", nspname)));
return oid;
}
/* /*
* makeRangeVarFromNameList * makeRangeVarFromNameList
* Utility routine to convert a qualified-name list into RangeVar form. * Utility routine to convert a qualified-name list into RangeVar form.
...@@ -2897,8 +2898,7 @@ recomputeNamespacePath(void) ...@@ -2897,8 +2898,7 @@ recomputeNamespacePath(void)
char *rname; char *rname;
rname = NameStr(((Form_pg_authid) GETSTRUCT(tuple))->rolname); rname = NameStr(((Form_pg_authid) GETSTRUCT(tuple))->rolname);
namespaceId = GetSysCacheOid1(NAMESPACENAME, namespaceId = get_namespace_oid(rname, true);
CStringGetDatum(rname));
ReleaseSysCache(tuple); ReleaseSysCache(tuple);
if (OidIsValid(namespaceId) && if (OidIsValid(namespaceId) &&
!list_member_oid(oidlist, namespaceId) && !list_member_oid(oidlist, namespaceId) &&
...@@ -2925,8 +2925,7 @@ recomputeNamespacePath(void) ...@@ -2925,8 +2925,7 @@ recomputeNamespacePath(void)
else else
{ {
/* normal namespace reference */ /* normal namespace reference */
namespaceId = GetSysCacheOid1(NAMESPACENAME, namespaceId = get_namespace_oid(curname, true);
CStringGetDatum(curname));
if (OidIsValid(namespaceId) && if (OidIsValid(namespaceId) &&
!list_member_oid(oidlist, namespaceId) && !list_member_oid(oidlist, namespaceId) &&
pg_namespace_aclcheck(namespaceId, roleid, pg_namespace_aclcheck(namespaceId, roleid,
...@@ -3033,8 +3032,7 @@ InitTempTableNamespace(void) ...@@ -3033,8 +3032,7 @@ InitTempTableNamespace(void)
snprintf(namespaceName, sizeof(namespaceName), "pg_temp_%d", MyBackendId); snprintf(namespaceName, sizeof(namespaceName), "pg_temp_%d", MyBackendId);
namespaceId = GetSysCacheOid1(NAMESPACENAME, namespaceId = get_namespace_oid(namespaceName, true);
CStringGetDatum(namespaceName));
if (!OidIsValid(namespaceId)) if (!OidIsValid(namespaceId))
{ {
/* /*
...@@ -3066,8 +3064,7 @@ InitTempTableNamespace(void) ...@@ -3066,8 +3064,7 @@ InitTempTableNamespace(void)
snprintf(namespaceName, sizeof(namespaceName), "pg_toast_temp_%d", snprintf(namespaceName, sizeof(namespaceName), "pg_toast_temp_%d",
MyBackendId); MyBackendId);
toastspaceId = GetSysCacheOid1(NAMESPACENAME, toastspaceId = get_namespace_oid(namespaceName, true);
CStringGetDatum(namespaceName));
if (!OidIsValid(toastspaceId)) if (!OidIsValid(toastspaceId))
{ {
toastspaceId = NamespaceCreate(namespaceName, BOOTSTRAP_SUPERUSERID); toastspaceId = NamespaceCreate(namespaceName, BOOTSTRAP_SUPERUSERID);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/alter.c,v 1.37 2010/07/28 05:22:24 sriggs Exp $ * $PostgreSQL: pgsql/src/backend/commands/alter.c,v 1.38 2010/08/05 14:44:58 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -211,7 +211,7 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt) ...@@ -211,7 +211,7 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt)
void void
ExecAlterOwnerStmt(AlterOwnerStmt *stmt) ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
{ {
Oid newowner = get_roleid_checked(stmt->newowner); Oid newowner = get_role_oid(stmt->newowner, false);
switch (stmt->objectType) switch (stmt->objectType)
{ {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Copyright (c) 1996-2010, PostgreSQL Global Development Group * Copyright (c) 1996-2010, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/comment.c,v 1.115 2010/06/13 17:43:12 rhaas Exp $ * $PostgreSQL: pgsql/src/backend/commands/comment.c,v 1.116 2010/08/05 14:44:58 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -42,6 +42,8 @@ ...@@ -42,6 +42,8 @@
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "commands/comment.h" #include "commands/comment.h"
#include "commands/dbcommands.h" #include "commands/dbcommands.h"
#include "commands/defrem.h"
#include "commands/proclang.h"
#include "commands/tablespace.h" #include "commands/tablespace.h"
#include "libpq/be-fsstubs.h" #include "libpq/be-fsstubs.h"
#include "miscadmin.h" #include "miscadmin.h"
...@@ -686,11 +688,10 @@ CommentDatabase(List *qualname, char *comment) ...@@ -686,11 +688,10 @@ CommentDatabase(List *qualname, char *comment)
* of the database. Erroring out would prevent pg_restore from completing * of the database. Erroring out would prevent pg_restore from completing
* (which is really pg_restore's fault, but for now we will work around * (which is really pg_restore's fault, but for now we will work around
* the problem here). Consensus is that the best fix is to treat wrong * the problem here). Consensus is that the best fix is to treat wrong
* database name as a WARNING not an ERROR. * database name as a WARNING not an ERROR (thus, we tell get_database_oid
* to ignore the error so that we can handle it differently here).
*/ */
oid = get_database_oid(database, true);
/* First get the database OID */
oid = get_database_oid(database);
if (!OidIsValid(oid)) if (!OidIsValid(oid))
{ {
ereport(WARNING, ereport(WARNING,
...@@ -729,14 +730,7 @@ CommentTablespace(List *qualname, char *comment) ...@@ -729,14 +730,7 @@ CommentTablespace(List *qualname, char *comment)
errmsg("tablespace name cannot be qualified"))); errmsg("tablespace name cannot be qualified")));
tablespace = strVal(linitial(qualname)); tablespace = strVal(linitial(qualname));
oid = get_tablespace_oid(tablespace); oid = get_tablespace_oid(tablespace, false);
if (!OidIsValid(oid))
{
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("tablespace \"%s\" does not exist", tablespace)));
return;
}
/* Check object security */ /* Check object security */
if (!pg_tablespace_ownercheck(oid, GetUserId())) if (!pg_tablespace_ownercheck(oid, GetUserId()))
...@@ -766,7 +760,7 @@ CommentRole(List *qualname, char *comment) ...@@ -766,7 +760,7 @@ CommentRole(List *qualname, char *comment)
errmsg("role name cannot be qualified"))); errmsg("role name cannot be qualified")));
role = strVal(linitial(qualname)); role = strVal(linitial(qualname));
oid = get_roleid_checked(role); oid = get_role_oid(role, false);
/* Check object security */ /* Check object security */
if (!has_privs_of_role(GetUserId(), oid)) if (!has_privs_of_role(GetUserId(), oid))
...@@ -799,11 +793,7 @@ CommentNamespace(List *qualname, char *comment) ...@@ -799,11 +793,7 @@ CommentNamespace(List *qualname, char *comment)
errmsg("schema name cannot be qualified"))); errmsg("schema name cannot be qualified")));
namespace = strVal(linitial(qualname)); namespace = strVal(linitial(qualname));
oid = GetSysCacheOid1(NAMESPACENAME, CStringGetDatum(namespace)); oid = get_namespace_oid(namespace, false);
if (!OidIsValid(oid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist", namespace)));
/* Check object security */ /* Check object security */
if (!pg_namespace_ownercheck(oid, GetUserId())) if (!pg_namespace_ownercheck(oid, GetUserId()))
...@@ -1213,11 +1203,7 @@ CommentLanguage(List *qualname, char *comment) ...@@ -1213,11 +1203,7 @@ CommentLanguage(List *qualname, char *comment)
errmsg("language name cannot be qualified"))); errmsg("language name cannot be qualified")));
language = strVal(linitial(qualname)); language = strVal(linitial(qualname));
oid = GetSysCacheOid1(LANGNAME, CStringGetDatum(language)); oid = get_language_oid(language, false);
if (!OidIsValid(oid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("language \"%s\" does not exist", language)));
/* Check object security */ /* Check object security */
if (!superuser()) if (!superuser())
...@@ -1254,12 +1240,7 @@ CommentOpClass(List *qualname, List *arguments, char *comment) ...@@ -1254,12 +1240,7 @@ CommentOpClass(List *qualname, List *arguments, char *comment)
/* /*
* Get the access method's OID. * Get the access method's OID.
*/ */
amID = GetSysCacheOid1(AMNAME, CStringGetDatum(amname)); amID = get_am_oid(amname, false);
if (!OidIsValid(amID))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("access method \"%s\" does not exist",
amname)));
/* /*
* Look up the opclass. * Look up the opclass.
...@@ -1335,12 +1316,7 @@ CommentOpFamily(List *qualname, List *arguments, char *comment) ...@@ -1335,12 +1316,7 @@ CommentOpFamily(List *qualname, List *arguments, char *comment)
/* /*
* Get the access method's OID. * Get the access method's OID.
*/ */
amID = GetSysCacheOid1(AMNAME, CStringGetDatum(amname)); amID = get_am_oid(amname, false);
if (!OidIsValid(amID))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("access method \"%s\" does not exist",
amname)));
/* /*
* Look up the opfamily. * Look up the opfamily.
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.236 2010/07/20 18:14:16 momjian Exp $ * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.237 2010/08/05 14:45:00 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -255,7 +255,7 @@ createdb(const CreatedbStmt *stmt) ...@@ -255,7 +255,7 @@ createdb(const CreatedbStmt *stmt)
/* obtain OID of proposed owner */ /* obtain OID of proposed owner */
if (dbowner) if (dbowner)
datdba = get_roleid_checked(dbowner); datdba = get_role_oid(dbowner, false);
else else
datdba = GetUserId(); datdba = GetUserId();
...@@ -429,12 +429,7 @@ createdb(const CreatedbStmt *stmt) ...@@ -429,12 +429,7 @@ createdb(const CreatedbStmt *stmt)
AclResult aclresult; AclResult aclresult;
tablespacename = strVal(dtablespacename->arg); tablespacename = strVal(dtablespacename->arg);
dst_deftablespace = get_tablespace_oid(tablespacename); dst_deftablespace = get_tablespace_oid(tablespacename, false);
if (!OidIsValid(dst_deftablespace))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("tablespace \"%s\" does not exist",
tablespacename)));
/* check permissions */ /* check permissions */
aclresult = pg_tablespace_aclcheck(dst_deftablespace, GetUserId(), aclresult = pg_tablespace_aclcheck(dst_deftablespace, GetUserId(),
ACL_CREATE); ACL_CREATE);
...@@ -491,7 +486,7 @@ createdb(const CreatedbStmt *stmt) ...@@ -491,7 +486,7 @@ createdb(const CreatedbStmt *stmt)
* message than "unique index violation". There's a race condition but * message than "unique index violation". There's a race condition but
* we're willing to accept the less friendly message in that case. * we're willing to accept the less friendly message in that case.
*/ */
if (OidIsValid(get_database_oid(dbname))) if (OidIsValid(get_database_oid(dbname, true)))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_DATABASE), (errcode(ERRCODE_DUPLICATE_DATABASE),
errmsg("database \"%s\" already exists", dbname))); errmsg("database \"%s\" already exists", dbname)));
...@@ -919,7 +914,7 @@ RenameDatabase(const char *oldname, const char *newname) ...@@ -919,7 +914,7 @@ RenameDatabase(const char *oldname, const char *newname)
* Make sure the new name doesn't exist. See notes for same error in * Make sure the new name doesn't exist. See notes for same error in
* CREATE DATABASE. * CREATE DATABASE.
*/ */
if (OidIsValid(get_database_oid(newname))) if (OidIsValid(get_database_oid(newname, true)))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_DATABASE), (errcode(ERRCODE_DUPLICATE_DATABASE),
errmsg("database \"%s\" already exists", newname))); errmsg("database \"%s\" already exists", newname)));
...@@ -1030,11 +1025,7 @@ movedb(const char *dbname, const char *tblspcname) ...@@ -1030,11 +1025,7 @@ movedb(const char *dbname, const char *tblspcname)
/* /*
* Get tablespace's oid * Get tablespace's oid
*/ */
dst_tblspcoid = get_tablespace_oid(tblspcname); dst_tblspcoid = get_tablespace_oid(tblspcname, false);
if (dst_tblspcoid == InvalidOid)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_DATABASE),
errmsg("tablespace \"%s\" does not exist", tblspcname)));
/* /*
* Permission checks * Permission checks
...@@ -1402,12 +1393,7 @@ AlterDatabase(AlterDatabaseStmt *stmt, bool isTopLevel) ...@@ -1402,12 +1393,7 @@ AlterDatabase(AlterDatabaseStmt *stmt, bool isTopLevel)
void void
AlterDatabaseSet(AlterDatabaseSetStmt *stmt) AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
{ {
Oid datid = get_database_oid(stmt->dbname); Oid datid = get_database_oid(stmt->dbname, false);
if (!OidIsValid(datid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_DATABASE),
errmsg("database \"%s\" does not exist", stmt->dbname)));
/* /*
* Obtain a lock on the database and make sure it didn't go away in the * Obtain a lock on the database and make sure it didn't go away in the
...@@ -1818,10 +1804,11 @@ errdetail_busy_db(int notherbackends, int npreparedxacts) ...@@ -1818,10 +1804,11 @@ errdetail_busy_db(int notherbackends, int npreparedxacts)
/* /*
* get_database_oid - given a database name, look up the OID * get_database_oid - given a database name, look up the OID
* *
* Returns InvalidOid if database name not found. * If missing_ok is false, throw an error if database name not found. If
* true, just return InvalidOid.
*/ */
Oid Oid
get_database_oid(const char *dbname) get_database_oid(const char *dbname, bool missing_ok)
{ {
Relation pg_database; Relation pg_database;
ScanKeyData entry[1]; ScanKeyData entry[1];
...@@ -1852,6 +1839,12 @@ get_database_oid(const char *dbname) ...@@ -1852,6 +1839,12 @@ get_database_oid(const char *dbname)
systable_endscan(scan); systable_endscan(scan);
heap_close(pg_database, AccessShareLock); heap_close(pg_database, AccessShareLock);
if (!OidIsValid(oid) && !missing_ok)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_DATABASE),
errmsg("database \"%s\" does not exist",
dbname)));
return oid; return oid;
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/foreigncmds.c,v 1.11 2010/02/14 18:42:14 rhaas Exp $ * $PostgreSQL: pgsql/src/backend/commands/foreigncmds.c,v 1.12 2010/08/05 14:45:00 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -184,7 +184,7 @@ GetUserOidFromMapping(const char *username, bool missing_ok) ...@@ -184,7 +184,7 @@ GetUserOidFromMapping(const char *username, bool missing_ok)
return GetUserId(); return GetUserId();
/* map to provided user */ /* map to provided user */
return missing_ok ? get_roleid(username) : get_roleid_checked(username); return get_role_oid(username, missing_ok);
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.198 2010/07/06 19:18:56 momjian Exp $ * $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.199 2010/08/05 14:45:00 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -218,12 +218,7 @@ DefineIndex(RangeVar *heapRelation, ...@@ -218,12 +218,7 @@ DefineIndex(RangeVar *heapRelation,
*/ */
if (tableSpaceName) if (tableSpaceName)
{ {
tablespaceId = get_tablespace_oid(tableSpaceName); tablespaceId = get_tablespace_oid(tableSpaceName, false);
if (!OidIsValid(tablespaceId))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("tablespace \"%s\" does not exist",
tableSpaceName)));
} }
else else
{ {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -641,7 +641,6 @@ DefineOpFamily(CreateOpFamilyStmt *stmt)
char *opfname; /* name of opfamily we're creating */ char *opfname; /* name of opfamily we're creating */
Oid amoid, /* our AM's oid */ Oid amoid, /* our AM's oid */
namespaceoid; /* namespace to create opfamily in */ namespaceoid; /* namespace to create opfamily in */
HeapTuple tup;
AclResult aclresult; AclResult aclresult;
/* Convert list of names to a name and namespace */ /* Convert list of names to a name and namespace */
...@@ -654,20 +653,11 @@ DefineOpFamily(CreateOpFamilyStmt *stmt) ...@@ -654,20 +653,11 @@ DefineOpFamily(CreateOpFamilyStmt *stmt)
aclcheck_error(aclresult, ACL_KIND_NAMESPACE, aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
get_namespace_name(namespaceoid)); get_namespace_name(namespaceoid));
/* Get necessary info about access method */ /* Get access method OID, throwing an error if it doesn't exist. */
tup = SearchSysCache1(AMNAME, CStringGetDatum(stmt->amname)); amoid = get_am_oid(stmt->amname, false);
if (!HeapTupleIsValid(tup))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("access method \"%s\" does not exist",
stmt->amname)));
amoid = HeapTupleGetOid(tup);
/* XXX Should we make any privilege check against the AM? */ /* XXX Should we make any privilege check against the AM? */
ReleaseSysCache(tup);
/* /*
* Currently, we require superuser privileges to create an opfamily. See * Currently, we require superuser privileges to create an opfamily. See
* comments in DefineOpClass. * comments in DefineOpClass.
...@@ -1427,12 +1417,7 @@ RemoveOpClass(RemoveOpClassStmt *stmt) ...@@ -1427,12 +1417,7 @@ RemoveOpClass(RemoveOpClassStmt *stmt)
/* /*
* Get the access method's OID. * Get the access method's OID.
*/ */
amID = GetSysCacheOid1(AMNAME, CStringGetDatum(stmt->amname)); amID = get_am_oid(stmt->amname, false);
if (!OidIsValid(amID))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("access method \"%s\" does not exist",
stmt->amname)));
/* /*
* Look up the opclass. * Look up the opclass.
...@@ -1488,12 +1473,7 @@ RemoveOpFamily(RemoveOpFamilyStmt *stmt) ...@@ -1488,12 +1473,7 @@ RemoveOpFamily(RemoveOpFamilyStmt *stmt)
/* /*
* Get the access method's OID. * Get the access method's OID.
*/ */
amID = GetSysCacheOid1(AMNAME, CStringGetDatum(stmt->amname)); amID = get_am_oid(stmt->amname, false);
if (!OidIsValid(amID))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("access method \"%s\" does not exist",
stmt->amname)));
/* /*
* Look up the opfamily. * Look up the opfamily.
...@@ -1650,12 +1630,7 @@ RenameOpClass(List *name, const char *access_method, const char *newname) ...@@ -1650,12 +1630,7 @@ RenameOpClass(List *name, const char *access_method, const char *newname)
Relation rel; Relation rel;
AclResult aclresult; AclResult aclresult;
amOid = GetSysCacheOid1(AMNAME, CStringGetDatum(access_method)); amOid = get_am_oid(access_method, false);
if (!OidIsValid(amOid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("access method \"%s\" does not exist",
access_method)));
rel = heap_open(OperatorClassRelationId, RowExclusiveLock); rel = heap_open(OperatorClassRelationId, RowExclusiveLock);
...@@ -1744,12 +1719,7 @@ RenameOpFamily(List *name, const char *access_method, const char *newname) ...@@ -1744,12 +1719,7 @@ RenameOpFamily(List *name, const char *access_method, const char *newname)
Relation rel; Relation rel;
AclResult aclresult; AclResult aclresult;
amOid = GetSysCacheOid1(AMNAME, CStringGetDatum(access_method)); amOid = get_am_oid(access_method, false);
if (!OidIsValid(amOid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("access method \"%s\" does not exist",
access_method)));
rel = heap_open(OperatorFamilyRelationId, RowExclusiveLock); rel = heap_open(OperatorFamilyRelationId, RowExclusiveLock);
...@@ -1835,12 +1805,7 @@ AlterOpClassOwner(List *name, const char *access_method, Oid newOwnerId) ...@@ -1835,12 +1805,7 @@ AlterOpClassOwner(List *name, const char *access_method, Oid newOwnerId)
char *opcname; char *opcname;
char *schemaname; char *schemaname;
amOid = GetSysCacheOid1(AMNAME, CStringGetDatum(access_method)); amOid = get_am_oid(access_method, false);
if (!OidIsValid(amOid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("access method \"%s\" does not exist",
access_method)));
rel = heap_open(OperatorClassRelationId, RowExclusiveLock); rel = heap_open(OperatorClassRelationId, RowExclusiveLock);
...@@ -1978,12 +1943,7 @@ AlterOpFamilyOwner(List *name, const char *access_method, Oid newOwnerId) ...@@ -1978,12 +1943,7 @@ AlterOpFamilyOwner(List *name, const char *access_method, Oid newOwnerId)
char *opfname; char *opfname;
char *schemaname; char *schemaname;
amOid = GetSysCacheOid1(AMNAME, CStringGetDatum(access_method)); amOid = get_am_oid(access_method, false);
if (!OidIsValid(amOid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("access method \"%s\" does not exist",
access_method)));
rel = heap_open(OperatorFamilyRelationId, RowExclusiveLock); rel = heap_open(OperatorFamilyRelationId, RowExclusiveLock);
...@@ -2108,3 +2068,22 @@ AlterOpFamilyOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId) ...@@ -2108,3 +2068,22 @@ AlterOpFamilyOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
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;
}
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * 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 ...@@ -514,7 +514,7 @@ void
DropProceduralLanguage(DropPLangStmt *stmt) DropProceduralLanguage(DropPLangStmt *stmt)
{ {
char *languageName; char *languageName;
HeapTuple langTup; Oid oid;
ObjectAddress object; ObjectAddress object;
/* /*
...@@ -522,34 +522,26 @@ DropProceduralLanguage(DropPLangStmt *stmt) ...@@ -522,34 +522,26 @@ DropProceduralLanguage(DropPLangStmt *stmt)
*/ */
languageName = case_translate_language_name(stmt->plname); languageName = case_translate_language_name(stmt->plname);
langTup = SearchSysCache1(LANGNAME, CStringGetDatum(languageName)); oid = get_language_oid(languageName, stmt->missing_ok);
if (!HeapTupleIsValid(langTup)) if (!OidIsValid(oid))
{ {
if (!stmt->missing_ok) ereport(NOTICE,
ereport(ERROR, (errmsg("language \"%s\" does not exist, skipping",
(errcode(ERRCODE_UNDEFINED_OBJECT), languageName)));
errmsg("language \"%s\" does not exist", languageName)));
else
ereport(NOTICE,
(errmsg("language \"%s\" does not exist, skipping",
languageName)));
return; return;
} }
/* /*
* Check permission * Check permission
*/ */
if (!pg_language_ownercheck(HeapTupleGetOid(langTup), GetUserId())) if (!pg_language_ownercheck(oid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_LANGUAGE, aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_LANGUAGE,
languageName); languageName);
object.classId = LanguageRelationId; object.classId = LanguageRelationId;
object.objectId = HeapTupleGetOid(langTup); object.objectId = oid;
object.objectSubId = 0; object.objectSubId = 0;
ReleaseSysCache(langTup);
/* /*
* Do the deletion * Do the deletion
*/ */
...@@ -735,3 +727,22 @@ AlterLanguageOwner_internal(HeapTuple tup, Relation rel, Oid newOwnerId) ...@@ -735,3 +727,22 @@ AlterLanguageOwner_internal(HeapTuple tup, Relation rel, Oid newOwnerId)
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;
}
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -57,7 +57,7 @@ CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString)
* Who is supposed to own the new schema? * Who is supposed to own the new schema?
*/ */
if (authId) if (authId)
owner_uid = get_roleid_checked(authId); owner_uid = get_role_oid(authId, false);
else else
owner_uid = saved_uid; owner_uid = saved_uid;
...@@ -178,24 +178,13 @@ RemoveSchemas(DropStmt *drop) ...@@ -178,24 +178,13 @@ RemoveSchemas(DropStmt *drop)
errmsg("schema name cannot be qualified"))); errmsg("schema name cannot be qualified")));
namespaceName = strVal(linitial(names)); namespaceName = strVal(linitial(names));
namespaceId = GetSysCacheOid1(NAMESPACENAME, namespaceId = get_namespace_oid(namespaceName, drop->missing_ok);
CStringGetDatum(namespaceName));
if (!OidIsValid(namespaceId)) if (!OidIsValid(namespaceId))
{ {
if (!drop->missing_ok) ereport(NOTICE,
{ (errmsg("schema \"%s\" does not exist, skipping",
ereport(ERROR, namespaceName)));
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("schema \"%s\" does not exist",
namespaceName)));
}
else
{
ereport(NOTICE,
(errmsg("schema \"%s\" does not exist, skipping",
namespaceName)));
}
continue; continue;
} }
...@@ -264,9 +253,7 @@ RenameSchema(const char *oldname, const char *newname) ...@@ -264,9 +253,7 @@ RenameSchema(const char *oldname, const char *newname)
errmsg("schema \"%s\" does not exist", oldname))); errmsg("schema \"%s\" does not exist", oldname)));
/* make sure the new name doesn't exist */ /* make sure the new name doesn't exist */
if (HeapTupleIsValid( if (OidIsValid(get_namespace_oid(newname, true)))
SearchSysCache1(NAMESPACENAME,
CStringGetDatum(newname))))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_SCHEMA), (errcode(ERRCODE_DUPLICATE_SCHEMA),
errmsg("schema \"%s\" already exists", newname))); errmsg("schema \"%s\" already exists", newname)));
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.338 2010/08/03 15:47:02 rhaas Exp $ * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.339 2010/08/05 14:45:01 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -414,12 +414,7 @@ DefineRelation(CreateStmt *stmt, char relkind) ...@@ -414,12 +414,7 @@ DefineRelation(CreateStmt *stmt, char relkind)
*/ */
if (stmt->tablespacename) if (stmt->tablespacename)
{ {
tablespaceId = get_tablespace_oid(stmt->tablespacename); tablespaceId = get_tablespace_oid(stmt->tablespacename, false);
if (!OidIsValid(tablespaceId))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("tablespace \"%s\" does not exist",
stmt->tablespacename)));
} }
else else
{ {
...@@ -2941,7 +2936,7 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab, Relation rel, ...@@ -2941,7 +2936,7 @@ ATExecCmd(List **wqueue, AlteredTableInfo *tab, Relation rel,
break; break;
case AT_ChangeOwner: /* ALTER OWNER */ case AT_ChangeOwner: /* ALTER OWNER */
ATExecChangeOwner(RelationGetRelid(rel), ATExecChangeOwner(RelationGetRelid(rel),
get_roleid_checked(cmd->name), get_role_oid(cmd->name, false),
false, lockmode); false, lockmode);
break; break;
case AT_ClusterOn: /* CLUSTER ON */ case AT_ClusterOn: /* CLUSTER ON */
...@@ -6945,11 +6940,7 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, char *tablespacename, L ...@@ -6945,11 +6940,7 @@ ATPrepSetTableSpace(AlteredTableInfo *tab, Relation rel, char *tablespacename, L
AclResult aclresult; AclResult aclresult;
/* Check that the tablespace exists */ /* Check that the tablespace exists */
tablespaceId = get_tablespace_oid(tablespacename); tablespaceId = get_tablespace_oid(tablespacename, false);
if (!OidIsValid(tablespaceId))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("tablespace \"%s\" does not exist", tablespacename)));
/* Check its permissions */ /* Check its permissions */
aclresult = pg_tablespace_aclcheck(tablespaceId, GetUserId(), ACL_CREATE); aclresult = pg_tablespace_aclcheck(tablespaceId, GetUserId(), ACL_CREATE);
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.78 2010/07/20 18:14:16 momjian Exp $ * $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.79 2010/08/05 14:45:01 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -246,7 +246,7 @@ CreateTableSpace(CreateTableSpaceStmt *stmt) ...@@ -246,7 +246,7 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
/* However, the eventual owner of the tablespace need not be */ /* However, the eventual owner of the tablespace need not be */
if (stmt->owner) if (stmt->owner)
ownerId = get_roleid_checked(stmt->owner); ownerId = get_role_oid(stmt->owner, false);
else else
ownerId = GetUserId(); ownerId = GetUserId();
...@@ -298,7 +298,7 @@ CreateTableSpace(CreateTableSpaceStmt *stmt) ...@@ -298,7 +298,7 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
* index would catch this anyway, but might as well give a friendlier * index would catch this anyway, but might as well give a friendlier
* message.) * message.)
*/ */
if (OidIsValid(get_tablespace_oid(stmt->tablespacename))) if (OidIsValid(get_tablespace_oid(stmt->tablespacename, true)))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT), (errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("tablespace \"%s\" already exists", errmsg("tablespace \"%s\" already exists",
...@@ -1029,7 +1029,7 @@ assign_default_tablespace(const char *newval, bool doit, GucSource source) ...@@ -1029,7 +1029,7 @@ assign_default_tablespace(const char *newval, bool doit, GucSource source)
if (IsTransactionState()) if (IsTransactionState())
{ {
if (newval[0] != '\0' && if (newval[0] != '\0' &&
!OidIsValid(get_tablespace_oid(newval))) !OidIsValid(get_tablespace_oid(newval, true)))
{ {
ereport(GUC_complaint_elevel(source), ereport(GUC_complaint_elevel(source),
(errcode(ERRCODE_UNDEFINED_OBJECT), (errcode(ERRCODE_UNDEFINED_OBJECT),
...@@ -1079,7 +1079,7 @@ GetDefaultTablespace(bool forTemp) ...@@ -1079,7 +1079,7 @@ GetDefaultTablespace(bool forTemp)
* to refer to an existing tablespace; we just silently return InvalidOid, * to refer to an existing tablespace; we just silently return InvalidOid,
* causing the new object to be created in the database's tablespace. * causing the new object to be created in the database's tablespace.
*/ */
result = get_tablespace_oid(default_tablespace); result = get_tablespace_oid(default_tablespace, true);
/* /*
* Allow explicit specification of database's default tablespace in * Allow explicit specification of database's default tablespace in
...@@ -1146,21 +1146,13 @@ assign_temp_tablespaces(const char *newval, bool doit, GucSource source) ...@@ -1146,21 +1146,13 @@ assign_temp_tablespaces(const char *newval, bool doit, GucSource source)
continue; continue;
} }
/* Else verify that name is a valid tablespace name */ /*
curoid = get_tablespace_oid(curname); * In an interactive SET command, we ereport for bad info.
* Otherwise, silently ignore any bad list elements.
*/
curoid = get_tablespace_oid(curname, source < PGC_S_INTERACTIVE);
if (curoid == InvalidOid) if (curoid == InvalidOid)
{
/*
* In an interactive SET command, we ereport for bad info.
* Otherwise, silently ignore any bad list elements.
*/
if (source >= PGC_S_INTERACTIVE)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("tablespace \"%s\" does not exist",
curname)));
continue; continue;
}
/* /*
* Allow explicit specification of database's default tablespace * Allow explicit specification of database's default tablespace
...@@ -1259,10 +1251,10 @@ PrepareTempTablespaces(void) ...@@ -1259,10 +1251,10 @@ PrepareTempTablespaces(void)
} }
/* Else verify that name is a valid tablespace name */ /* Else verify that name is a valid tablespace name */
curoid = get_tablespace_oid(curname); curoid = get_tablespace_oid(curname, true);
if (curoid == InvalidOid) if (curoid == InvalidOid)
{ {
/* Silently ignore any bad list elements */ /* Skip any bad list elements */
continue; continue;
} }
...@@ -1295,10 +1287,11 @@ PrepareTempTablespaces(void) ...@@ -1295,10 +1287,11 @@ PrepareTempTablespaces(void)
/* /*
* get_tablespace_oid - given a tablespace name, look up the OID * get_tablespace_oid - given a tablespace name, look up the OID
* *
* Returns InvalidOid if tablespace name not found. * If missing_ok is false, throw an error if tablespace name not found. If
* true, just return InvalidOid.
*/ */
Oid Oid
get_tablespace_oid(const char *tablespacename) get_tablespace_oid(const char *tablespacename, bool missing_ok)
{ {
Oid result; Oid result;
Relation rel; Relation rel;
...@@ -1329,6 +1322,12 @@ get_tablespace_oid(const char *tablespacename) ...@@ -1329,6 +1322,12 @@ get_tablespace_oid(const char *tablespacename)
heap_endscan(scandesc); heap_endscan(scandesc);
heap_close(rel, AccessShareLock); heap_close(rel, AccessShareLock);
if (!OidIsValid(result) && !missing_ok)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("tablespace \"%s\" does not exist",
tablespacename)));
return result; return result;
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.193 2010/02/26 02:00:40 momjian Exp $ * $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.194 2010/08/05 14:45:01 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -293,8 +293,7 @@ CreateRole(CreateRoleStmt *stmt) ...@@ -293,8 +293,7 @@ CreateRole(CreateRoleStmt *stmt)
pg_authid_rel = heap_open(AuthIdRelationId, RowExclusiveLock); pg_authid_rel = heap_open(AuthIdRelationId, RowExclusiveLock);
pg_authid_dsc = RelationGetDescr(pg_authid_rel); pg_authid_dsc = RelationGetDescr(pg_authid_rel);
tuple = SearchSysCache1(AUTHNAME, PointerGetDatum(stmt->role)); if (OidIsValid(get_role_oid(stmt->role, true)))
if (HeapTupleIsValid(tuple))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT), (errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("role \"%s\" already exists", errmsg("role \"%s\" already exists",
...@@ -384,7 +383,7 @@ CreateRole(CreateRoleStmt *stmt) ...@@ -384,7 +383,7 @@ CreateRole(CreateRoleStmt *stmt)
foreach(item, addroleto) foreach(item, addroleto)
{ {
char *oldrolename = strVal(lfirst(item)); char *oldrolename = strVal(lfirst(item));
Oid oldroleid = get_roleid_checked(oldrolename); Oid oldroleid = get_role_oid(oldrolename, false);
AddRoleMems(oldrolename, oldroleid, AddRoleMems(oldrolename, oldroleid,
list_make1(makeString(stmt->role)), list_make1(makeString(stmt->role)),
...@@ -795,11 +794,7 @@ AlterRoleSet(AlterRoleSetStmt *stmt) ...@@ -795,11 +794,7 @@ AlterRoleSet(AlterRoleSetStmt *stmt)
/* look up and lock the database, if specified */ /* look up and lock the database, if specified */
if (stmt->database != NULL) if (stmt->database != NULL)
{ {
databaseid = get_database_oid(stmt->database); databaseid = get_database_oid(stmt->database, false);
if (!OidIsValid(databaseid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("database \"%s\" not found", stmt->database)));
shdepLockAndCheckObject(DatabaseRelationId, databaseid); shdepLockAndCheckObject(DatabaseRelationId, databaseid);
} }
...@@ -1099,7 +1094,7 @@ GrantRole(GrantRoleStmt *stmt) ...@@ -1099,7 +1094,7 @@ GrantRole(GrantRoleStmt *stmt)
ListCell *item; ListCell *item;
if (stmt->grantor) if (stmt->grantor)
grantor = get_roleid_checked(stmt->grantor); grantor = get_role_oid(stmt->grantor, false);
else else
grantor = GetUserId(); grantor = GetUserId();
...@@ -1127,7 +1122,7 @@ GrantRole(GrantRoleStmt *stmt) ...@@ -1127,7 +1122,7 @@ GrantRole(GrantRoleStmt *stmt)
(errcode(ERRCODE_INVALID_GRANT_OPERATION), (errcode(ERRCODE_INVALID_GRANT_OPERATION),
errmsg("column names cannot be included in GRANT/REVOKE ROLE"))); errmsg("column names cannot be included in GRANT/REVOKE ROLE")));
roleid = get_roleid_checked(rolename); roleid = get_role_oid(rolename, false);
if (stmt->is_grant) if (stmt->is_grant)
AddRoleMems(rolename, roleid, AddRoleMems(rolename, roleid,
stmt->grantee_roles, grantee_ids, stmt->grantee_roles, grantee_ids,
...@@ -1194,7 +1189,7 @@ ReassignOwnedObjects(ReassignOwnedStmt *stmt) ...@@ -1194,7 +1189,7 @@ ReassignOwnedObjects(ReassignOwnedStmt *stmt)
} }
/* Must have privileges on the receiving side too */ /* Must have privileges on the receiving side too */
newrole = get_roleid_checked(stmt->newrole); newrole = get_role_oid(stmt->newrole, false);
if (!has_privs_of_role(GetUserId(), newrole)) if (!has_privs_of_role(GetUserId(), newrole))
ereport(ERROR, ereport(ERROR,
...@@ -1220,7 +1215,7 @@ roleNamesToIds(List *memberNames) ...@@ -1220,7 +1215,7 @@ roleNamesToIds(List *memberNames)
foreach(l, memberNames) foreach(l, memberNames)
{ {
char *rolename = strVal(lfirst(l)); char *rolename = strVal(lfirst(l));
Oid roleid = get_roleid_checked(rolename); Oid roleid = get_role_oid(rolename, false);
result = lappend_oid(result, roleid); result = lappend_oid(result, roleid);
} }
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.353 2010/07/25 23:21:21 rhaas Exp $ * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.354 2010/08/05 14:45:02 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2134,12 +2134,7 @@ OpenIntoRel(QueryDesc *queryDesc) ...@@ -2134,12 +2134,7 @@ OpenIntoRel(QueryDesc *queryDesc)
*/ */
if (into->tableSpaceName) if (into->tableSpaceName)
{ {
tablespaceId = get_tablespace_oid(into->tableSpaceName); tablespaceId = get_tablespace_oid(into->tableSpaceName, false);
if (!OidIsValid(tablespaceId))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("tablespace \"%s\" does not exist",
into->tableSpaceName)));
} }
else else
{ {
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.209 2010/07/06 19:18:56 momjian Exp $ * $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.210 2010/08/05 14:45:03 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -459,7 +459,7 @@ is_member(Oid userid, const char *role) ...@@ -459,7 +459,7 @@ is_member(Oid userid, const char *role)
if (!OidIsValid(userid)) if (!OidIsValid(userid))
return false; /* if user not exist, say "no" */ return false; /* if user not exist, say "no" */
roleid = get_roleid(role); roleid = get_role_oid(role, true);
if (!OidIsValid(roleid)) if (!OidIsValid(roleid))
return false; /* if target role not exist, say "no" */ return false; /* if target role not exist, say "no" */
...@@ -1328,7 +1328,7 @@ check_hba(hbaPort *port) ...@@ -1328,7 +1328,7 @@ check_hba(hbaPort *port)
HbaLine *hba; HbaLine *hba;
/* Get the target role's OID. Note we do not error out for bad role. */ /* Get the target role's OID. Note we do not error out for bad role. */
roleid = get_roleid(port->user_name); roleid = get_role_oid(port->user_name, true);
foreach(line, parsed_hba_lines) foreach(line, parsed_hba_lines)
{ {
......
This diff is collapsed.
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Copyright (c) 2002-2010, PostgreSQL Global Development Group * Copyright (c) 2002-2010, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/dbsize.c,v 1.31 2010/02/26 02:01:07 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/dbsize.c,v 1.32 2010/08/05 14:45:04 rhaas Exp $
* *
*/ */
...@@ -141,13 +141,7 @@ Datum ...@@ -141,13 +141,7 @@ Datum
pg_database_size_name(PG_FUNCTION_ARGS) pg_database_size_name(PG_FUNCTION_ARGS)
{ {
Name dbName = PG_GETARG_NAME(0); Name dbName = PG_GETARG_NAME(0);
Oid dbOid = get_database_oid(NameStr(*dbName)); Oid dbOid = get_database_oid(NameStr(*dbName), false);
if (!OidIsValid(dbOid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_DATABASE),
errmsg("database \"%s\" does not exist",
NameStr(*dbName))));
PG_RETURN_INT64(calculate_database_size(dbOid)); PG_RETURN_INT64(calculate_database_size(dbOid));
} }
...@@ -240,13 +234,7 @@ Datum ...@@ -240,13 +234,7 @@ Datum
pg_tablespace_size_name(PG_FUNCTION_ARGS) pg_tablespace_size_name(PG_FUNCTION_ARGS)
{ {
Name tblspcName = PG_GETARG_NAME(0); Name tblspcName = PG_GETARG_NAME(0);
Oid tblspcOid = get_tablespace_oid(NameStr(*tblspcName)); Oid tblspcOid = get_tablespace_oid(NameStr(*tblspcName), false);
if (!OidIsValid(tblspcOid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("tablespace \"%s\" does not exist",
NameStr(*tblspcName))));
PG_RETURN_INT64(calculate_tablespace_size(tblspcOid)); PG_RETURN_INT64(calculate_tablespace_size(tblspcOid));
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/cache/lsyscache.c,v 1.171 2010/07/09 22:57:39 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/cache/lsyscache.c,v 1.172 2010/08/05 14:45:05 rhaas Exp $
* *
* NOTES * NOTES
* Eventually, the index information should go through here, too. * Eventually, the index information should go through here, too.
...@@ -2638,34 +2638,3 @@ get_namespace_name(Oid nspid) ...@@ -2638,34 +2638,3 @@ get_namespace_name(Oid nspid)
else else
return NULL; return NULL;
} }
/* ---------- PG_AUTHID CACHE ---------- */
/*
* get_roleid
* Given a role name, look up the role's OID.
* Returns InvalidOid if no such role.
*/
Oid
get_roleid(const char *rolname)
{
return GetSysCacheOid1(AUTHNAME, PointerGetDatum(rolname));
}
/*
* get_roleid_checked
* Given a role name, look up the role's OID.
* ereports if no such role.
*/
Oid
get_roleid_checked(const char *rolname)
{
Oid roleid;
roleid = get_roleid(rolname);
if (!OidIsValid(roleid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("role \"%s\" does not exist", rolname)));
return roleid;
}
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/catalog/namespace.h,v 1.62 2010/01/02 16:58:01 momjian Exp $ * $PostgreSQL: pgsql/src/include/catalog/namespace.h,v 1.63 2010/08/05 14:45:06 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -91,6 +91,7 @@ extern void DeconstructQualifiedName(List *names, ...@@ -91,6 +91,7 @@ extern void DeconstructQualifiedName(List *names,
char **objname_p); char **objname_p);
extern Oid LookupNamespaceNoError(const char *nspname); extern Oid LookupNamespaceNoError(const char *nspname);
extern Oid LookupExplicitNamespace(const char *nspname); extern Oid LookupExplicitNamespace(const char *nspname);
extern Oid get_namespace_oid(const char *nspname, bool missing_ok);
extern Oid LookupCreationNamespace(const char *nspname); extern Oid LookupCreationNamespace(const char *nspname);
extern Oid QualifiedNameGetCreationNamespace(List *names, char **objname_p); extern Oid QualifiedNameGetCreationNamespace(List *names, char **objname_p);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/commands/dbcommands.h,v 1.50 2010/01/02 16:58:03 momjian Exp $ * $PostgreSQL: pgsql/src/include/commands/dbcommands.h,v 1.51 2010/08/05 14:45:07 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -59,7 +59,7 @@ extern void AlterDatabase(AlterDatabaseStmt *stmt, bool isTopLevel); ...@@ -59,7 +59,7 @@ extern void AlterDatabase(AlterDatabaseStmt *stmt, bool isTopLevel);
extern void AlterDatabaseSet(AlterDatabaseSetStmt *stmt); extern void AlterDatabaseSet(AlterDatabaseSetStmt *stmt);
extern void AlterDatabaseOwner(const char *dbname, Oid newOwnerId); extern void AlterDatabaseOwner(const char *dbname, Oid newOwnerId);
extern Oid get_database_oid(const char *dbname); extern Oid get_database_oid(const char *dbname, bool missingok);
extern char *get_database_name(Oid dbid); extern char *get_database_name(Oid dbid);
extern void dbase_redo(XLogRecPtr lsn, XLogRecord *rptr); extern void dbase_redo(XLogRecPtr lsn, XLogRecord *rptr);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/commands/defrem.h,v 1.102 2010/07/03 13:53:13 rhaas Exp $ * $PostgreSQL: pgsql/src/include/commands/defrem.h,v 1.103 2010/08/05 14:45:07 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -99,6 +99,7 @@ extern void AlterOpClassOwner(List *name, const char *access_method, Oid newOwne ...@@ -99,6 +99,7 @@ extern void AlterOpClassOwner(List *name, const char *access_method, Oid newOwne
extern void AlterOpClassOwner_oid(Oid opclassOid, Oid newOwnerId); extern void AlterOpClassOwner_oid(Oid opclassOid, Oid newOwnerId);
extern void AlterOpFamilyOwner(List *name, const char *access_method, Oid newOwnerId); extern void AlterOpFamilyOwner(List *name, const char *access_method, Oid newOwnerId);
extern void AlterOpFamilyOwner_oid(Oid opfamilyOid, Oid newOwnerId); extern void AlterOpFamilyOwner_oid(Oid opfamilyOid, Oid newOwnerId);
extern Oid get_am_oid(const char *amname, bool missing_ok);
/* commands/tsearchcmds.c */ /* commands/tsearchcmds.c */
extern void DefineTSParser(List *names, List *parameters); extern void DefineTSParser(List *names, List *parameters);
......
/* /*
* $PostgreSQL: pgsql/src/include/commands/proclang.h,v 1.15 2009/06/11 14:49:11 momjian Exp $ * $PostgreSQL: pgsql/src/include/commands/proclang.h,v 1.16 2010/08/05 14:45:08 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
* *
...@@ -21,5 +21,6 @@ extern void RenameLanguage(const char *oldname, const char *newname); ...@@ -21,5 +21,6 @@ extern void RenameLanguage(const char *oldname, const char *newname);
extern void AlterLanguageOwner(const char *name, Oid newOwnerId); extern void AlterLanguageOwner(const char *name, Oid newOwnerId);
extern void AlterLanguageOwner_oid(Oid oid, Oid newOwnerId); extern void AlterLanguageOwner_oid(Oid oid, Oid newOwnerId);
extern bool PLTemplateExists(const char *languageName); extern bool PLTemplateExists(const char *languageName);
extern Oid get_language_oid(const char *langname, bool missing_ok);
#endif /* PROCLANG_H */ #endif /* PROCLANG_H */
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/commands/tablespace.h,v 1.23 2010/01/07 03:53:08 rhaas Exp $ * $PostgreSQL: pgsql/src/include/commands/tablespace.h,v 1.24 2010/08/05 14:45:08 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -51,7 +51,7 @@ extern Oid GetDefaultTablespace(bool forTemp); ...@@ -51,7 +51,7 @@ extern Oid GetDefaultTablespace(bool forTemp);
extern void PrepareTempTablespaces(void); extern void PrepareTempTablespaces(void);
extern Oid get_tablespace_oid(const char *tablespacename); extern Oid get_tablespace_oid(const char *tablespacename, bool missing_ok);
extern char *get_tablespace_name(Oid spc_oid); extern char *get_tablespace_name(Oid spc_oid);
extern bool directory_is_empty(const char *path); extern bool directory_is_empty(const char *path);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/utils/acl.h,v 1.113 2010/02/26 02:01:28 momjian Exp $ * $PostgreSQL: pgsql/src/include/utils/acl.h,v 1.114 2010/08/05 14:45:09 rhaas Exp $
* *
* NOTES * NOTES
* An ACL array is simply an array of AclItems, representing the union * An ACL array is simply an array of AclItems, representing the union
...@@ -223,6 +223,7 @@ extern bool is_member_of_role(Oid member, Oid role); ...@@ -223,6 +223,7 @@ extern bool is_member_of_role(Oid member, Oid role);
extern bool is_member_of_role_nosuper(Oid member, Oid role); extern bool is_member_of_role_nosuper(Oid member, Oid role);
extern bool is_admin_of_role(Oid member, Oid role); extern bool is_admin_of_role(Oid member, Oid role);
extern void check_is_member_of_role(Oid member, Oid role); extern void check_is_member_of_role(Oid member, Oid role);
extern Oid get_role_oid(const char *rolname, bool missing_ok);
extern void select_best_grantor(Oid roleId, AclMode privileges, extern void select_best_grantor(Oid roleId, AclMode privileges,
const Acl *acl, Oid ownerId, const Acl *acl, Oid ownerId,
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/utils/lsyscache.h,v 1.133 2010/04/24 16:20:32 sriggs Exp $ * $PostgreSQL: pgsql/src/include/utils/lsyscache.h,v 1.134 2010/08/05 14:45:09 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -136,8 +136,6 @@ extern void free_attstatsslot(Oid atttype, ...@@ -136,8 +136,6 @@ extern void free_attstatsslot(Oid atttype,
Datum *values, int nvalues, Datum *values, int nvalues,
float4 *numbers, int nnumbers); float4 *numbers, int nnumbers);
extern char *get_namespace_name(Oid nspid); extern char *get_namespace_name(Oid nspid);
extern Oid get_roleid(const char *rolname);
extern Oid get_roleid_checked(const char *rolname);
#define type_is_array(typid) (get_element_type(typid) != InvalidOid) #define type_is_array(typid) (get_element_type(typid) != InvalidOid)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment