* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.26 2002/07/20 05:16:56 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.27 2002/07/29 23:46:35 tgl Exp $
*
*-------------------------------------------------------------------------
*/
if (relation->schemaname)
{
/* use exact schema given */
- AclResult aclresult;
-
- namespaceId = GetSysCacheOid(NAMESPACENAME,
- CStringGetDatum(relation->schemaname),
- 0, 0, 0);
- if (!OidIsValid(namespaceId))
- elog(ERROR, "Namespace \"%s\" does not exist",
- relation->schemaname);
- aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_USAGE);
- if (aclresult != ACLCHECK_OK)
- aclcheck_error(aclresult, relation->schemaname);
-
+ namespaceId = LookupExplicitNamespace(relation->schemaname);
relId = get_relname_relid(relation->relname, namespaceId);
}
else
if (!OidIsValid(namespaceId))
elog(ERROR, "Namespace \"%s\" does not exist",
newRelation->schemaname);
+ /* we do not check for USAGE rights here! */
}
else
{
FuncnameGetCandidates(List *names, int nargs)
{
FuncCandidateList resultList = NULL;
- char *catalogname;
- char *schemaname = NULL;
- char *funcname = NULL;
+ char *schemaname;
+ char *funcname;
Oid namespaceId;
CatCList *catlist;
int i;
/* deconstruct the name list */
- switch (length(names))
- {
- case 1:
- funcname = strVal(lfirst(names));
- break;
- case 2:
- schemaname = strVal(lfirst(names));
- funcname = strVal(lsecond(names));
- break;
- case 3:
- catalogname = strVal(lfirst(names));
- schemaname = strVal(lsecond(names));
- funcname = strVal(lfirst(lnext(lnext(names))));
- /*
- * We check the catalog name and then ignore it.
- */
- if (strcmp(catalogname, DatabaseName) != 0)
- elog(ERROR, "Cross-database references are not implemented");
- break;
- default:
- elog(ERROR, "Improper qualified name (too many dotted names): %s",
- NameListToString(names));
- break;
- }
+ DeconstructQualifiedName(names, &schemaname, &funcname);
if (schemaname)
{
/* use exact schema given */
- AclResult aclresult;
-
- namespaceId = GetSysCacheOid(NAMESPACENAME,
- CStringGetDatum(schemaname),
- 0, 0, 0);
- if (!OidIsValid(namespaceId))
- elog(ERROR, "Namespace \"%s\" does not exist",
- schemaname);
- aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_USAGE);
- if (aclresult != ACLCHECK_OK)
- aclcheck_error(aclresult, schemaname);
+ namespaceId = LookupExplicitNamespace(schemaname);
}
else
{
OpernameGetCandidates(List *names, char oprkind)
{
FuncCandidateList resultList = NULL;
- char *catalogname;
- char *schemaname = NULL;
- char *opername = NULL;
+ char *schemaname;
+ char *opername;
Oid namespaceId;
CatCList *catlist;
int i;
/* deconstruct the name list */
- switch (length(names))
- {
- case 1:
- opername = strVal(lfirst(names));
- break;
- case 2:
- schemaname = strVal(lfirst(names));
- opername = strVal(lsecond(names));
- break;
- case 3:
- catalogname = strVal(lfirst(names));
- schemaname = strVal(lsecond(names));
- opername = strVal(lfirst(lnext(lnext(names))));
- /*
- * We check the catalog name and then ignore it.
- */
- if (strcmp(catalogname, DatabaseName) != 0)
- elog(ERROR, "Cross-database references are not implemented");
- break;
- default:
- elog(ERROR, "Improper qualified name (too many dotted names): %s",
- NameListToString(names));
- break;
- }
+ DeconstructQualifiedName(names, &schemaname, &opername);
if (schemaname)
{
/* use exact schema given */
- AclResult aclresult;
-
- namespaceId = GetSysCacheOid(NAMESPACENAME,
- CStringGetDatum(schemaname),
- 0, 0, 0);
- if (!OidIsValid(namespaceId))
- elog(ERROR, "Namespace \"%s\" does not exist",
- schemaname);
- aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_USAGE);
- if (aclresult != ACLCHECK_OK)
- aclcheck_error(aclresult, schemaname);
+ namespaceId = LookupExplicitNamespace(schemaname);
}
else
{
return visible;
}
-
/*
- * QualifiedNameGetCreationNamespace
- * Given a possibly-qualified name for an object (in List-of-Values
- * format), determine what namespace the object should be created in.
- * Also extract and return the object name (last component of list).
+ * DeconstructQualifiedName
+ * Given a possibly-qualified name expressed as a list of String nodes,
+ * extract the schema name and object name.
*
- * This is *not* used for tables. Hence, the TEMP table namespace is
- * never selected as the creation target.
+ * *nspname_p is set to NULL if there is no explicit schema name.
*/
-Oid
-QualifiedNameGetCreationNamespace(List *names, char **objname_p)
+void
+DeconstructQualifiedName(List *names,
+ char **nspname_p,
+ char **objname_p)
{
char *catalogname;
char *schemaname = NULL;
char *objname = NULL;
- Oid namespaceId;
- /* deconstruct the name list */
switch (length(names))
{
case 1:
break;
}
+ *nspname_p = schemaname;
+ *objname_p = objname;
+}
+
+/*
+ * LookupExplicitNamespace
+ * Process an explicitly-specified schema name: look up the schema
+ * and verify we have USAGE (lookup) rights in it.
+ *
+ * Returns the namespace OID. Raises elog if any problem.
+ */
+Oid
+LookupExplicitNamespace(char *nspname)
+{
+ Oid namespaceId;
+ AclResult aclresult;
+
+ namespaceId = GetSysCacheOid(NAMESPACENAME,
+ CStringGetDatum(nspname),
+ 0, 0, 0);
+ if (!OidIsValid(namespaceId))
+ elog(ERROR, "Namespace \"%s\" does not exist", nspname);
+
+ aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(), ACL_USAGE);
+ if (aclresult != ACLCHECK_OK)
+ aclcheck_error(aclresult, nspname);
+
+ return namespaceId;
+}
+
+/*
+ * QualifiedNameGetCreationNamespace
+ * Given a possibly-qualified name for an object (in List-of-Values
+ * format), determine what namespace the object should be created in.
+ * Also extract and return the object name (last component of list).
+ *
+ * This is *not* used for tables. Hence, the TEMP table namespace is
+ * never selected as the creation target.
+ */
+Oid
+QualifiedNameGetCreationNamespace(List *names, char **objname_p)
+{
+ char *schemaname;
+ char *objname;
+ Oid namespaceId;
+
+ /* deconstruct the name list */
+ DeconstructQualifiedName(names, &schemaname, &objname);
+
if (schemaname)
{
/* use exact schema given */
if (!OidIsValid(namespaceId))
elog(ERROR, "Namespace \"%s\" does not exist",
schemaname);
+ /* we do not check for USAGE rights here! */
}
else
{
* Copyright (c) 1996-2001, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.52 2002/07/20 05:16:57 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.53 2002/07/29 23:46:35 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "catalog/pg_constraint.h"
#include "catalog/pg_database.h"
#include "catalog/pg_description.h"
-#include "catalog/pg_namespace.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_rewrite.h"
#include "catalog/pg_trigger.h"
{
Oid oid;
Oid classoid;
- HeapTuple tp;
char *namespace;
if (length(qualname) != 1)
elog(ERROR, "CommentSchema: schema name may not be qualified");
namespace = strVal(lfirst(qualname));
- tp = SearchSysCache(NAMESPACENAME,
- CStringGetDatum(namespace),
- 0, 0, 0);
- if (!HeapTupleIsValid(tp))
+ oid = GetSysCacheOid(NAMESPACENAME,
+ CStringGetDatum(namespace),
+ 0, 0, 0);
+ if (!OidIsValid(oid))
elog(ERROR, "CommentSchema: Schema \"%s\" could not be found",
namespace);
- /* no TupleDesc here to Assert(...->tdhasoid); */
- oid = HeapTupleGetOid(tp);
-
/* Check object security */
if (!pg_namespace_ownercheck(oid, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, namespace);
/* pg_namespace doesn't have a hard-coded OID, so must look it up */
- classoid = get_relname_relid(NamespaceRelationName, PG_CATALOG_NAMESPACE);
- Assert(OidIsValid(classoid));
+ classoid = get_system_catalog_relid(NamespaceRelationName);
/* Call CreateComments() to create/drop the comments */
CreateComments(oid, classoid, 0, comment);
-
- /* Cleanup */
- ReleaseSysCache(tp);
}
/*
aclcheck_error(aclcheck, rulename);
/* pg_rewrite doesn't have a hard-coded OID, so must look it up */
- classoid = get_relname_relid(RewriteRelationName, PG_CATALOG_NAMESPACE);
- Assert(OidIsValid(classoid));
+ classoid = get_system_catalog_relid(RewriteRelationName);
/* Call CreateComments() to create/drop the comments */
aclcheck_error(ACLCHECK_NOT_OWNER, NameListToString(opername));
/* pg_operator doesn't have a hard-coded OID, so must look it up */
- classoid = get_relname_relid(OperatorRelationName, PG_CATALOG_NAMESPACE);
- Assert(OidIsValid(classoid));
+ classoid = get_system_catalog_relid(OperatorRelationName);
/* Call CreateComments() to create/drop the comments */
CreateComments(oid, classoid, 0, comment);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.78 2002/07/20 05:16:57 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.79 2002/07/29 23:46:35 tgl Exp $
*
*-------------------------------------------------------------------------
*/
GetAttrOpClass(IndexElem *attribute, Oid attrType,
char *accessMethodName, Oid accessMethodId)
{
- char *catalogname;
- char *schemaname = NULL;
- char *opcname = NULL;
+ char *schemaname;
+ char *opcname;
HeapTuple tuple;
Oid opClassId,
opInputType;
*/
/* deconstruct the name list */
- switch (length(attribute->opclass))
- {
- case 1:
- opcname = strVal(lfirst(attribute->opclass));
- break;
- case 2:
- schemaname = strVal(lfirst(attribute->opclass));
- opcname = strVal(lsecond(attribute->opclass));
- break;
- case 3:
- catalogname = strVal(lfirst(attribute->opclass));
- schemaname = strVal(lsecond(attribute->opclass));
- opcname = strVal(lfirst(lnext(lnext(attribute->opclass))));
- /*
- * We check the catalog name and then ignore it.
- */
- if (strcmp(catalogname, DatabaseName) != 0)
- elog(ERROR, "Cross-database references are not implemented");
- break;
- default:
- elog(ERROR, "Improper opclass name (too many dotted names): %s",
- NameListToString(attribute->opclass));
- break;
- }
+ DeconstructQualifiedName(attribute->opclass, &schemaname, &opcname);
if (schemaname)
{
/* Look in specific schema only */
Oid namespaceId;
- namespaceId = GetSysCacheOid(NAMESPACENAME,
- CStringGetDatum(schemaname),
- 0, 0, 0);
- if (!OidIsValid(namespaceId))
- elog(ERROR, "Namespace \"%s\" does not exist",
- schemaname);
+ namespaceId = LookupExplicitNamespace(schemaname);
tuple = SearchSysCache(CLAAMNAMENSP,
ObjectIdGetDatum(accessMethodId),
PointerGetDatum(opcname),
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/opclasscmds.c,v 1.1 2002/07/29 22:14:10 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/opclasscmds.c,v 1.2 2002/07/29 23:46:35 tgl Exp $
*
*-------------------------------------------------------------------------
*/
void
RemoveOpClass(RemoveOpClassStmt *stmt)
{
- Oid amID, opcID;
- char *catalogname;
- char *schemaname = NULL;
- char *opcname = NULL;
+ Oid amID, opcID;
+ char *schemaname;
+ char *opcname;
HeapTuple tuple;
ObjectAddress object;
*/
/* deconstruct the name list */
- switch (length(stmt->opclassname))
- {
- case 1:
- opcname = strVal(lfirst(stmt->opclassname));
- break;
- case 2:
- schemaname = strVal(lfirst(stmt->opclassname));
- opcname = strVal(lsecond(stmt->opclassname));
- break;
- case 3:
- catalogname = strVal(lfirst(stmt->opclassname));
- schemaname = strVal(lsecond(stmt->opclassname));
- opcname = strVal(lfirst(lnext(lnext(stmt->opclassname))));
- /*
- * We check the catalog name and then ignore it.
- */
- if (strcmp(catalogname, DatabaseName) != 0)
- elog(ERROR, "Cross-database references are not implemented");
- break;
- default:
- elog(ERROR, "Improper opclass name (too many dotted names): %s",
- NameListToString(stmt->opclassname));
- break;
- }
+ DeconstructQualifiedName(stmt->opclassname, &schemaname, &opcname);
if (schemaname)
{
/* Look in specific schema only */
Oid namespaceId;
- namespaceId = GetSysCacheOid(NAMESPACENAME,
- CStringGetDatum(schemaname),
- 0, 0, 0);
- if (!OidIsValid(namespaceId))
- elog(ERROR, "Namespace \"%s\" does not exist",
- schemaname);
+ namespaceId = LookupExplicitNamespace(schemaname);
tuple = SearchSysCache(CLAAMNAMENSP,
ObjectIdGetDatum(amID),
PointerGetDatum(opcname),
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.45 2002/07/20 05:16:58 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.46 2002/07/29 23:46:35 tgl Exp $
*
*-------------------------------------------------------------------------
*/
else
{
/* Normal reference to a type name */
- char *catalogname;
- char *schemaname = NULL;
- char *typname = NULL;
+ char *schemaname;
+ char *typname;
/* deconstruct the name list */
- switch (length(typename->names))
- {
- case 1:
- typname = strVal(lfirst(typename->names));
- break;
- case 2:
- schemaname = strVal(lfirst(typename->names));
- typname = strVal(lsecond(typename->names));
- break;
- case 3:
- catalogname = strVal(lfirst(typename->names));
- schemaname = strVal(lsecond(typename->names));
- typname = strVal(lfirst(lnext(lnext(typename->names))));
- /*
- * We check the catalog name and then ignore it.
- */
- if (strcmp(catalogname, DatabaseName) != 0)
- elog(ERROR, "Cross-database references are not implemented");
- break;
- default:
- elog(ERROR, "Improper type name (too many dotted names): %s",
- NameListToString(typename->names));
- break;
- }
+ DeconstructQualifiedName(typename->names, &schemaname, &typname);
/* If an array reference, look up the array type instead */
if (typename->arrayBounds != NIL)
/* Look in specific schema only */
Oid namespaceId;
- namespaceId = GetSysCacheOid(NAMESPACENAME,
- CStringGetDatum(schemaname),
- 0, 0, 0);
- if (!OidIsValid(namespaceId))
- elog(ERROR, "Namespace \"%s\" does not exist",
- schemaname);
+ namespaceId = LookupExplicitNamespace(schemaname);
restype = GetSysCacheOid(TYPENAMENSP,
PointerGetDatum(typname),
ObjectIdGetDatum(namespaceId),
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: namespace.h,v 1.16 2002/07/16 06:58:13 ishii Exp $
+ * $Id: namespace.h,v 1.17 2002/07/29 23:46:35 tgl Exp $
*
*-------------------------------------------------------------------------
*/
extern Oid OpclassnameGetOpcid(Oid amid, const char *opcname);
extern bool OpclassIsVisible(Oid opcid);
+extern void DeconstructQualifiedName(List *names,
+ char **nspname_p,
+ char **objname_p);
+extern Oid LookupExplicitNamespace(char *nspname);
+
extern Oid QualifiedNameGetCreationNamespace(List *names, char **objname_p);
extern RangeVar *makeRangeVarFromNameList(List *names);
extern char *NameListToString(List *names);