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.
*
*
* 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
* See acl.h.
#include "catalog/pg_ts_config.h"
#include "catalog/pg_ts_dict.h"
#include "commands/dbcommands.h"
+#include "commands/proclang.h"
+#include "commands/tablespace.h"
#include "foreign/foreign.h"
#include "miscadmin.h"
#include "parser/parse_func.h"
else
istmt.grantees =
lappend_oid(istmt.grantees,
- get_roleid_checked(grantee->rolname));
+ get_role_oid(grantee->rolname, false));
}
/*
char *dbname = strVal(lfirst(cell));
Oid dbid;
- dbid = get_database_oid(dbname);
- if (!OidIsValid(dbid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_DATABASE),
- errmsg("database \"%s\" does not exist",
- dbname)));
+ dbid = get_database_oid(dbname, false);
objects = lappend_oid(objects, dbid);
}
break;
foreach(cell, objnames)
{
char *langname = strVal(lfirst(cell));
- HeapTuple tuple;
-
- tuple = SearchSysCache1(LANGNAME, PointerGetDatum(langname));
- if (!HeapTupleIsValid(tuple))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("language \"%s\" does not exist",
- langname)));
+ Oid oid;
- objects = lappend_oid(objects, HeapTupleGetOid(tuple));
-
- ReleaseSysCache(tuple);
+ oid = get_language_oid(langname, false);
+ objects = lappend_oid(objects, oid);
}
break;
case ACL_OBJECT_LARGEOBJECT:
foreach(cell, objnames)
{
char *nspname = strVal(lfirst(cell));
- HeapTuple tuple;
-
- 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));
+ Oid oid;
- ReleaseSysCache(tuple);
+ oid = get_namespace_oid(nspname, false);
+ objects = lappend_oid(objects, oid);
}
break;
case ACL_OBJECT_TABLESPACE:
foreach(cell, objnames)
{
char *spcname = strVal(lfirst(cell));
- ScanKeyData entry[1];
- HeapScanDesc scan;
- HeapTuple tuple;
- Relation relation;
+ Oid spcoid;
- relation = heap_open(TableSpaceRelationId, AccessShareLock);
-
- 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);
+ spcoid = get_tablespace_oid(spcname, false);
+ objects = lappend_oid(objects, spcoid);
}
break;
case ACL_OBJECT_FDW:
else
iacls.grantees =
lappend_oid(iacls.grantees,
- get_roleid_checked(grantee->rolname));
+ get_role_oid(grantee->rolname, false));
}
/*
{
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
AclResult aclresult;
/*
- * Normally we'd use LookupCreationNamespace here, but it's
- * important to do the permissions check against the target role
- * not the calling user, so write it out in full. We require
- * CREATE privileges, since without CREATE you won't be able to do
- * anything using the default privs anyway.
+ * Note that we must do the permissions check against the target
+ * role not the calling user. We require CREATE privileges,
+ * since without CREATE you won't be able to do anything using the
+ * default privs anyway.
*/
- iacls->nspid = GetSysCacheOid1(NAMESPACENAME,
- CStringGetDatum(nspname));
- if (!OidIsValid(iacls->nspid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_SCHEMA),
- errmsg("schema \"%s\" does not exist", nspname)));
+ iacls->nspid = get_namespace_oid(nspname, false);
aclresult = pg_namespace_aclcheck(iacls->nspid, iacls->roleid,
ACL_CREATE);
* Portions Copyright (c) 1994, Regents of the University of California
*
* 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 $
*
*-------------------------------------------------------------------------
*/
return myTempNamespace;
}
/* use exact schema given */
- namespaceId = GetSysCacheOid1(NAMESPACENAME,
- CStringGetDatum(newRelation->schemaname));
- if (!OidIsValid(namespaceId))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_SCHEMA),
- errmsg("schema \"%s\" does not exist",
- newRelation->schemaname)));
+ namespaceId = get_namespace_oid(newRelation->schemaname, false);
/* we do not check for USAGE rights here! */
}
else
return InvalidOid;
}
- return GetSysCacheOid1(NAMESPACENAME, CStringGetDatum(nspname));
+ return get_namespace_oid(nspname, true);
}
/*
*/
}
- namespaceId = GetSysCacheOid1(NAMESPACENAME, CStringGetDatum(nspname));
- if (!OidIsValid(namespaceId))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_SCHEMA),
- errmsg("schema \"%s\" does not exist", nspname)));
+ namespaceId = get_namespace_oid(nspname, false);
aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_USAGE);
if (aclresult != ACLCHECK_OK)
return myTempNamespace;
}
- namespaceId = GetSysCacheOid1(NAMESPACENAME, CStringGetDatum(nspname));
- if (!OidIsValid(namespaceId))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_SCHEMA),
- errmsg("schema \"%s\" does not exist", nspname)));
+ namespaceId = get_namespace_oid(nspname, false);
aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_CREATE);
if (aclresult != ACLCHECK_OK)
return myTempNamespace;
}
/* use exact schema given */
- namespaceId = GetSysCacheOid1(NAMESPACENAME,
- CStringGetDatum(schemaname));
- if (!OidIsValid(namespaceId))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_SCHEMA),
- errmsg("schema \"%s\" does not exist", schemaname)));
+ namespaceId = get_namespace_oid(schemaname, false);
/* we do not check for USAGE rights here! */
}
else
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
* Utility routine to convert a qualified-name list into RangeVar form.
char *rname;
rname = NameStr(((Form_pg_authid) GETSTRUCT(tuple))->rolname);
- namespaceId = GetSysCacheOid1(NAMESPACENAME,
- CStringGetDatum(rname));
+ namespaceId = get_namespace_oid(rname, true);
ReleaseSysCache(tuple);
if (OidIsValid(namespaceId) &&
!list_member_oid(oidlist, namespaceId) &&
else
{
/* normal namespace reference */
- namespaceId = GetSysCacheOid1(NAMESPACENAME,
- CStringGetDatum(curname));
+ namespaceId = get_namespace_oid(curname, true);
if (OidIsValid(namespaceId) &&
!list_member_oid(oidlist, namespaceId) &&
pg_namespace_aclcheck(namespaceId, roleid,
snprintf(namespaceName, sizeof(namespaceName), "pg_temp_%d", MyBackendId);
- namespaceId = GetSysCacheOid1(NAMESPACENAME,
- CStringGetDatum(namespaceName));
+ namespaceId = get_namespace_oid(namespaceName, true);
if (!OidIsValid(namespaceId))
{
/*
snprintf(namespaceName, sizeof(namespaceName), "pg_toast_temp_%d",
MyBackendId);
- toastspaceId = GetSysCacheOid1(NAMESPACENAME,
- CStringGetDatum(namespaceName));
+ toastspaceId = get_namespace_oid(namespaceName, true);
if (!OidIsValid(toastspaceId))
{
toastspaceId = NamespaceCreate(namespaceName, BOOTSTRAP_SUPERUSERID);
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
void
ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
{
- Oid newowner = get_roleid_checked(stmt->newowner);
+ Oid newowner = get_role_oid(stmt->newowner, false);
switch (stmt->objectType)
{
* Copyright (c) 1996-2010, PostgreSQL Global Development Group
*
* 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 $
*
*-------------------------------------------------------------------------
*/
#include "catalog/pg_type.h"
#include "commands/comment.h"
#include "commands/dbcommands.h"
+#include "commands/defrem.h"
+#include "commands/proclang.h"
#include "commands/tablespace.h"
#include "libpq/be-fsstubs.h"
#include "miscadmin.h"
* 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
* 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).
*/
-
- /* First get the database OID */
- oid = get_database_oid(database);
+ oid = get_database_oid(database, true);
if (!OidIsValid(oid))
{
ereport(WARNING,
errmsg("tablespace name cannot be qualified")));
tablespace = strVal(linitial(qualname));
- oid = get_tablespace_oid(tablespace);
- if (!OidIsValid(oid))
- {
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("tablespace \"%s\" does not exist", tablespace)));
- return;
- }
+ oid = get_tablespace_oid(tablespace, false);
/* Check object security */
if (!pg_tablespace_ownercheck(oid, GetUserId()))
errmsg("role name cannot be qualified")));
role = strVal(linitial(qualname));
- oid = get_roleid_checked(role);
+ oid = get_role_oid(role, false);
/* Check object security */
if (!has_privs_of_role(GetUserId(), oid))
errmsg("schema name cannot be qualified")));
namespace = strVal(linitial(qualname));
- oid = GetSysCacheOid1(NAMESPACENAME, CStringGetDatum(namespace));
- if (!OidIsValid(oid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_SCHEMA),
- errmsg("schema \"%s\" does not exist", namespace)));
+ oid = get_namespace_oid(namespace, false);
/* Check object security */
if (!pg_namespace_ownercheck(oid, GetUserId()))
errmsg("language name cannot be qualified")));
language = strVal(linitial(qualname));
- oid = GetSysCacheOid1(LANGNAME, CStringGetDatum(language));
- if (!OidIsValid(oid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_SCHEMA),
- errmsg("language \"%s\" does not exist", language)));
+ oid = get_language_oid(language, false);
/* Check object security */
if (!superuser())
/*
* Get the access method's OID.
*/
- amID = GetSysCacheOid1(AMNAME, CStringGetDatum(amname));
- if (!OidIsValid(amID))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("access method \"%s\" does not exist",
- amname)));
+ amID = get_am_oid(amname, false);
/*
* Look up the opclass.
/*
* Get the access method's OID.
*/
- amID = GetSysCacheOid1(AMNAME, CStringGetDatum(amname));
- if (!OidIsValid(amID))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("access method \"%s\" does not exist",
- amname)));
+ amID = get_am_oid(amname, false);
/*
* Look up the opfamily.
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
/* obtain OID of proposed owner */
if (dbowner)
- datdba = get_roleid_checked(dbowner);
+ datdba = get_role_oid(dbowner, false);
else
datdba = GetUserId();
AclResult aclresult;
tablespacename = strVal(dtablespacename->arg);
- dst_deftablespace = get_tablespace_oid(tablespacename);
- if (!OidIsValid(dst_deftablespace))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("tablespace \"%s\" does not exist",
- tablespacename)));
+ dst_deftablespace = get_tablespace_oid(tablespacename, false);
/* check permissions */
aclresult = pg_tablespace_aclcheck(dst_deftablespace, GetUserId(),
ACL_CREATE);
* message than "unique index violation". There's a race condition but
* 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,
(errcode(ERRCODE_DUPLICATE_DATABASE),
errmsg("database \"%s\" already exists", dbname)));
* Make sure the new name doesn't exist. See notes for same error in
* CREATE DATABASE.
*/
- if (OidIsValid(get_database_oid(newname)))
+ if (OidIsValid(get_database_oid(newname, true)))
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_DATABASE),
errmsg("database \"%s\" already exists", newname)));
/*
* Get tablespace's oid
*/
- dst_tblspcoid = get_tablespace_oid(tblspcname);
- if (dst_tblspcoid == InvalidOid)
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_DATABASE),
- errmsg("tablespace \"%s\" does not exist", tblspcname)));
+ dst_tblspcoid = get_tablespace_oid(tblspcname, false);
/*
* Permission checks
void
AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
{
- Oid datid = get_database_oid(stmt->dbname);
-
- if (!OidIsValid(datid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_DATABASE),
- errmsg("database \"%s\" does not exist", stmt->dbname)));
+ Oid datid = get_database_oid(stmt->dbname, false);
/*
* Obtain a lock on the database and make sure it didn't go away in the
/*
* 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
-get_database_oid(const char *dbname)
+get_database_oid(const char *dbname, bool missing_ok)
{
Relation pg_database;
ScanKeyData entry[1];
systable_endscan(scan);
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;
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
return GetUserId();
/* map to provided user */
- return missing_ok ? get_roleid(username) : get_roleid_checked(username);
+ return get_role_oid(username, missing_ok);
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
*/
if (tableSpaceName)
{
- tablespaceId = get_tablespace_oid(tableSpaceName);
- if (!OidIsValid(tablespaceId))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("tablespace \"%s\" does not exist",
- tableSpaceName)));
+ tablespaceId = get_tablespace_oid(tableSpaceName, false);
}
else
{
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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 */
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.
/*
* 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.
/*
* 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.
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);
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);
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);
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);
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;
+}
* 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 $
*
*-------------------------------------------------------------------------
*/
DropProceduralLanguage(DropPLangStmt *stmt)
{
char *languageName;
- HeapTuple langTup;
+ Oid oid;
ObjectAddress object;
/*
*/
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
*/
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;
+}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
* 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;
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;
}
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)));
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
*/
if (stmt->tablespacename)
{
- tablespaceId = get_tablespace_oid(stmt->tablespacename);
- if (!OidIsValid(tablespaceId))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("tablespace \"%s\" does not exist",
- stmt->tablespacename)));
+ tablespaceId = get_tablespace_oid(stmt->tablespacename, false);
}
else
{
break;
case AT_ChangeOwner: /* ALTER OWNER */
ATExecChangeOwner(RelationGetRelid(rel),
- get_roleid_checked(cmd->name),
+ get_role_oid(cmd->name, false),
false, lockmode);
break;
case AT_ClusterOn: /* CLUSTER ON */
AclResult aclresult;
/* Check that the tablespace exists */
- tablespaceId = get_tablespace_oid(tablespacename);
- if (!OidIsValid(tablespaceId))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("tablespace \"%s\" does not exist", tablespacename)));
+ tablespaceId = get_tablespace_oid(tablespacename, false);
/* Check its permissions */
aclresult = pg_tablespace_aclcheck(tablespaceId, GetUserId(), ACL_CREATE);
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
/* However, the eventual owner of the tablespace need not be */
if (stmt->owner)
- ownerId = get_roleid_checked(stmt->owner);
+ ownerId = get_role_oid(stmt->owner, false);
else
ownerId = GetUserId();
* index would catch this anyway, but might as well give a friendlier
* message.)
*/
- if (OidIsValid(get_tablespace_oid(stmt->tablespacename)))
+ if (OidIsValid(get_tablespace_oid(stmt->tablespacename, true)))
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("tablespace \"%s\" already exists",
if (IsTransactionState())
{
if (newval[0] != '\0' &&
- !OidIsValid(get_tablespace_oid(newval)))
+ !OidIsValid(get_tablespace_oid(newval, true)))
{
ereport(GUC_complaint_elevel(source),
(errcode(ERRCODE_UNDEFINED_OBJECT),
* to refer to an existing tablespace; we just silently return InvalidOid,
* 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
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)
- {
- /*
- * 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;
- }
/*
* Allow explicit specification of database's default tablespace
}
/* Else verify that name is a valid tablespace name */
- curoid = get_tablespace_oid(curname);
+ curoid = get_tablespace_oid(curname, true);
if (curoid == InvalidOid)
{
- /* Silently ignore any bad list elements */
+ /* Skip any bad list elements */
continue;
}
/*
* 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
-get_tablespace_oid(const char *tablespacename)
+get_tablespace_oid(const char *tablespacename, bool missing_ok)
{
Oid result;
Relation rel;
heap_endscan(scandesc);
heap_close(rel, AccessShareLock);
+ if (!OidIsValid(result) && !missing_ok)
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("tablespace \"%s\" does not exist",
+ tablespacename)));
+
return result;
}
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* 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 $
*
*-------------------------------------------------------------------------
*/
pg_authid_rel = heap_open(AuthIdRelationId, RowExclusiveLock);
pg_authid_dsc = RelationGetDescr(pg_authid_rel);
- tuple = SearchSysCache1(AUTHNAME, PointerGetDatum(stmt->role));
- if (HeapTupleIsValid(tuple))
+ if (OidIsValid(get_role_oid(stmt->role, true)))
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("role \"%s\" already exists",
foreach(item, addroleto)
{
char *oldrolename = strVal(lfirst(item));
- Oid oldroleid = get_roleid_checked(oldrolename);
+ Oid oldroleid = get_role_oid(oldrolename, false);
AddRoleMems(oldrolename, oldroleid,
list_make1(makeString(stmt->role)),
/* look up and lock the database, if specified */
if (stmt->database != NULL)
{
- databaseid = get_database_oid(stmt->database);
- if (!OidIsValid(databaseid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("database \"%s\" not found", stmt->database)));
+ databaseid = get_database_oid(stmt->database, false);
shdepLockAndCheckObject(DatabaseRelationId, databaseid);
}
ListCell *item;
if (stmt->grantor)
- grantor = get_roleid_checked(stmt->grantor);
+ grantor = get_role_oid(stmt->grantor, false);
else
grantor = GetUserId();
(errcode(ERRCODE_INVALID_GRANT_OPERATION),
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)
AddRoleMems(rolename, roleid,
stmt->grantee_roles, grantee_ids,
}
/* 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))
ereport(ERROR,
foreach(l, memberNames)
{
char *rolename = strVal(lfirst(l));
- Oid roleid = get_roleid_checked(rolename);
+ Oid roleid = get_role_oid(rolename, false);
result = lappend_oid(result, roleid);
}
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
*/
if (into->tableSpaceName)
{
- tablespaceId = get_tablespace_oid(into->tableSpaceName);
- if (!OidIsValid(tablespaceId))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("tablespace \"%s\" does not exist",
- into->tableSpaceName)));
+ tablespaceId = get_tablespace_oid(into->tableSpaceName, false);
}
else
{
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
if (!OidIsValid(userid))
return false; /* if user not exist, say "no" */
- roleid = get_roleid(role);
+ roleid = get_role_oid(role, true);
if (!OidIsValid(roleid))
return false; /* if target role not exist, say "no" */
HbaLine *hba;
/* 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)
{
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.157 2010/02/26 02:01:05 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.158 2010/08/05 14:45:04 rhaas Exp $
*
*-------------------------------------------------------------------------
*/
#include "catalog/pg_type.h"
#include "catalog/pg_class.h"
#include "commands/dbcommands.h"
+#include "commands/proclang.h"
#include "commands/tablespace.h"
#include "foreign/foreign.h"
#include "funcapi.h"
if (name[0] == '\0')
aip->ai_grantee = ACL_ID_PUBLIC;
else
- aip->ai_grantee = get_roleid_checked(name);
+ aip->ai_grantee = get_role_oid(name, false);
/*
* XXX Allow a degree of backward compatibility by defaulting the grantor
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("a name must follow the \"/\" sign")));
- aip->ai_grantor = get_roleid_checked(name2);
+ aip->ai_grantor = get_role_oid(name2, false);
}
else
{
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*rolename));
+ roleid = get_role_oid(NameStr(*rolename), false);
tableoid = convert_table_name(tablename);
mode = convert_table_priv_string(priv_type_text);
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*username));
+ roleid = get_role_oid(NameStr(*username), false);
mode = convert_table_priv_string(priv_type_text);
if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(tableoid)))
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*rolename));
+ roleid = get_role_oid(NameStr(*rolename), false);
mode = convert_sequence_priv_string(priv_type_text);
sequenceoid = convert_table_name(sequencename);
if (get_rel_relkind(sequenceoid) != RELKIND_SEQUENCE)
AclResult aclresult;
char relkind;
- roleid = get_roleid_checked(NameStr(*username));
+ roleid = get_role_oid(NameStr(*username), false);
mode = convert_sequence_priv_string(priv_type_text);
relkind = get_rel_relkind(sequenceoid);
if (relkind == '\0')
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*rolename));
+ roleid = get_role_oid(NameStr(*rolename), false);
tableoid = convert_table_name(tablename);
mode = convert_column_priv_string(priv_type_text);
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*username));
+ roleid = get_role_oid(NameStr(*username), false);
mode = convert_column_priv_string(priv_type_text);
if (!SearchSysCacheExists1(RELOID, ObjectIdGetDatum(tableoid)))
AclMode mode;
int privresult;
- roleid = get_roleid_checked(NameStr(*rolename));
+ roleid = get_role_oid(NameStr(*rolename), false);
tableoid = convert_table_name(tablename);
colattnum = convert_column_name(tableoid, column);
mode = convert_column_priv_string(priv_type_text);
AclMode mode;
int privresult;
- roleid = get_roleid_checked(NameStr(*rolename));
+ roleid = get_role_oid(NameStr(*rolename), false);
tableoid = convert_table_name(tablename);
mode = convert_column_priv_string(priv_type_text);
AclMode mode;
int privresult;
- roleid = get_roleid_checked(NameStr(*username));
+ roleid = get_role_oid(NameStr(*username), false);
colattnum = convert_column_name(tableoid, column);
mode = convert_column_priv_string(priv_type_text);
AclMode mode;
int privresult;
- roleid = get_roleid_checked(NameStr(*username));
+ roleid = get_role_oid(NameStr(*username), false);
mode = convert_column_priv_string(priv_type_text);
privresult = column_privilege_check(tableoid, colattnum, roleid, mode);
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*username));
+ roleid = get_role_oid(NameStr(*username), false);
databaseoid = convert_database_name(databasename);
mode = convert_database_priv_string(priv_type_text);
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*username));
+ roleid = get_role_oid(NameStr(*username), false);
mode = convert_database_priv_string(priv_type_text);
if (!SearchSysCacheExists1(DATABASEOID, ObjectIdGetDatum(databaseoid)))
convert_database_name(text *databasename)
{
char *dbname = text_to_cstring(databasename);
- Oid oid;
- oid = get_database_oid(dbname);
- if (!OidIsValid(oid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_DATABASE),
- errmsg("database \"%s\" does not exist", dbname)));
-
- return oid;
+ return get_database_oid(dbname, false);
}
/*
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*username));
+ roleid = get_role_oid(NameStr(*username), false);
fdwid = convert_foreign_data_wrapper_name(fdwname);
mode = convert_foreign_data_wrapper_priv_string(priv_type_text);
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*username));
+ roleid = get_role_oid(NameStr(*username), false);
mode = convert_foreign_data_wrapper_priv_string(priv_type_text);
aclresult = pg_foreign_data_wrapper_aclcheck(fdwid, roleid, mode);
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*username));
+ roleid = get_role_oid(NameStr(*username), false);
functionoid = convert_function_name(functionname);
mode = convert_function_priv_string(priv_type_text);
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*username));
+ roleid = get_role_oid(NameStr(*username), false);
mode = convert_function_priv_string(priv_type_text);
if (!SearchSysCacheExists1(PROCOID, ObjectIdGetDatum(functionoid)))
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*username));
+ roleid = get_role_oid(NameStr(*username), false);
languageoid = convert_language_name(languagename);
mode = convert_language_priv_string(priv_type_text);
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*username));
+ roleid = get_role_oid(NameStr(*username), false);
mode = convert_language_priv_string(priv_type_text);
if (!SearchSysCacheExists1(LANGOID, ObjectIdGetDatum(languageoid)))
convert_language_name(text *languagename)
{
char *langname = text_to_cstring(languagename);
- Oid oid;
- oid = GetSysCacheOid1(LANGNAME, CStringGetDatum(langname));
- if (!OidIsValid(oid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("language \"%s\" does not exist", langname)));
-
- return oid;
+ return get_language_oid(langname, false);
}
/*
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*username));
+ roleid = get_role_oid(NameStr(*username), false);
schemaoid = convert_schema_name(schemaname);
mode = convert_schema_priv_string(priv_type_text);
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*username));
+ roleid = get_role_oid(NameStr(*username), false);
mode = convert_schema_priv_string(priv_type_text);
if (!SearchSysCacheExists1(NAMESPACEOID, ObjectIdGetDatum(schemaoid)))
convert_schema_name(text *schemaname)
{
char *nspname = text_to_cstring(schemaname);
- Oid oid;
-
- oid = GetSysCacheOid1(NAMESPACENAME, CStringGetDatum(nspname));
- if (!OidIsValid(oid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_SCHEMA),
- errmsg("schema \"%s\" does not exist", nspname)));
- return oid;
+ return get_namespace_oid(nspname, false);
}
/*
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*username));
+ roleid = get_role_oid(NameStr(*username), false);
serverid = convert_server_name(servername);
mode = convert_server_priv_string(priv_type_text);
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*username));
+ roleid = get_role_oid(NameStr(*username), false);
mode = convert_server_priv_string(priv_type_text);
aclresult = pg_foreign_server_aclcheck(serverid, roleid, mode);
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*username));
+ roleid = get_role_oid(NameStr(*username), false);
tablespaceoid = convert_tablespace_name(tablespacename);
mode = convert_tablespace_priv_string(priv_type_text);
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*username));
+ roleid = get_role_oid(NameStr(*username), false);
mode = convert_tablespace_priv_string(priv_type_text);
aclresult = pg_tablespace_aclcheck(tablespaceoid, roleid, mode);
convert_tablespace_name(text *tablespacename)
{
char *spcname = text_to_cstring(tablespacename);
- Oid oid;
- oid = get_tablespace_oid(spcname);
-
- if (!OidIsValid(oid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("tablespace \"%s\" does not exist", spcname)));
-
- return oid;
+ return get_tablespace_oid(spcname, false);
}
/*
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*username));
- roleoid = get_roleid_checked(NameStr(*rolename));
+ roleid = get_role_oid(NameStr(*username), false);
+ roleoid = get_role_oid(NameStr(*rolename), false);
mode = convert_role_priv_string(priv_type_text);
aclresult = pg_role_aclcheck(roleoid, roleid, mode);
AclResult aclresult;
roleid = GetUserId();
- roleoid = get_roleid_checked(NameStr(*rolename));
+ roleoid = get_role_oid(NameStr(*rolename), false);
mode = convert_role_priv_string(priv_type_text);
aclresult = pg_role_aclcheck(roleoid, roleid, mode);
AclMode mode;
AclResult aclresult;
- roleid = get_roleid_checked(NameStr(*username));
+ roleid = get_role_oid(NameStr(*username), false);
mode = convert_role_priv_string(priv_type_text);
aclresult = pg_role_aclcheck(roleoid, roleid, mode);
AclMode mode;
AclResult aclresult;
- roleoid = get_roleid_checked(NameStr(*rolename));
+ roleoid = get_role_oid(NameStr(*rolename), false);
mode = convert_role_priv_string(priv_type_text);
aclresult = pg_role_aclcheck(roleoid, roleid, mode);
}
}
}
+
+/*
+ * get_role_oid - Given a role name, look up the role's OID.
+ *
+ * If missing_ok is false, throw an error if tablespace name not found. If
+ * true, just return InvalidOid.
+ */
+Oid
+get_role_oid(const char *rolname, bool missing_ok)
+{
+ Oid oid;
+
+ oid = GetSysCacheOid1(AUTHNAME, CStringGetDatum(rolname));
+ if (!OidIsValid(oid) && !missing_ok)
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("role \"%s\" does not exist", rolname)));
+ return oid;
+}
* Copyright (c) 2002-2010, PostgreSQL Global Development Group
*
* 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 $
*
*/
pg_database_size_name(PG_FUNCTION_ARGS)
{
Name dbName = PG_GETARG_NAME(0);
- Oid dbOid = get_database_oid(NameStr(*dbName));
-
- if (!OidIsValid(dbOid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_DATABASE),
- errmsg("database \"%s\" does not exist",
- NameStr(*dbName))));
+ Oid dbOid = get_database_oid(NameStr(*dbName), false);
PG_RETURN_INT64(calculate_database_size(dbOid));
}
pg_tablespace_size_name(PG_FUNCTION_ARGS)
{
Name tblspcName = PG_GETARG_NAME(0);
- Oid tblspcOid = get_tablespace_oid(NameStr(*tblspcName));
-
- if (!OidIsValid(tblspcOid))
- ereport(ERROR,
- (errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("tablespace \"%s\" does not exist",
- NameStr(*tblspcName))));
+ Oid tblspcOid = get_tablespace_oid(NameStr(*tblspcName), false);
PG_RETURN_INT64(calculate_tablespace_size(tblspcOid));
}
* Portions Copyright (c) 1994, Regents of the University of California
*
* 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
* Eventually, the index information should go through here, too.
else
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;
-}
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* 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 $
*
*-------------------------------------------------------------------------
*/
char **objname_p);
extern Oid LookupNamespaceNoError(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 QualifiedNameGetCreationNamespace(List *names, char **objname_p);
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* 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 $
*
*-------------------------------------------------------------------------
*/
extern void AlterDatabaseSet(AlterDatabaseSetStmt *stmt);
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 void dbase_redo(XLogRecPtr lsn, XLogRecord *rptr);
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* 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 $
*
*-------------------------------------------------------------------------
*/
extern void AlterOpClassOwner_oid(Oid opclassOid, Oid newOwnerId);
extern void AlterOpFamilyOwner(List *name, const char *access_method, Oid newOwnerId);
extern void AlterOpFamilyOwner_oid(Oid opfamilyOid, Oid newOwnerId);
+extern Oid get_am_oid(const char *amname, bool missing_ok);
/* commands/tsearchcmds.c */
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 $
*
*-------------------------------------------------------------------------
*
extern void AlterLanguageOwner(const char *name, Oid newOwnerId);
extern void AlterLanguageOwner_oid(Oid oid, Oid newOwnerId);
extern bool PLTemplateExists(const char *languageName);
+extern Oid get_language_oid(const char *langname, bool missing_ok);
#endif /* PROCLANG_H */
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* 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 $
*
*-------------------------------------------------------------------------
*/
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 bool directory_is_empty(const char *path);
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* 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
* An ACL array is simply an array of AclItems, representing the union
extern bool is_member_of_role_nosuper(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 Oid get_role_oid(const char *rolname, bool missing_ok);
extern void select_best_grantor(Oid roleId, AclMode privileges,
const Acl *acl, Oid ownerId,
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* 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 $
*
*-------------------------------------------------------------------------
*/
Datum *values, int nvalues,
float4 *numbers, int nnumbers);
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)