aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/comment.c27
-rw-r--r--src/backend/commands/indexcmds.c39
-rw-r--r--src/backend/commands/opclasscmds.c41
3 files changed, 19 insertions, 88 deletions
diff --git a/src/backend/commands/comment.c b/src/backend/commands/comment.c
index 83b8af7e6bf..c5dee8f8af9 100644
--- a/src/backend/commands/comment.c
+++ b/src/backend/commands/comment.c
@@ -7,7 +7,7 @@
* 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 $
*
*-------------------------------------------------------------------------
*/
@@ -22,7 +22,6 @@
#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"
@@ -468,36 +467,28 @@ CommentNamespace(List *qualname, char *comment)
{
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);
}
/*
@@ -607,8 +598,7 @@ CommentRule(List *qualname, char *comment)
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 */
@@ -740,8 +730,7 @@ CommentOperator(List *opername, List *arguments, char *comment)
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);
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index f36bad8ada1..4049e7435c5 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -8,7 +8,7 @@
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
@@ -410,9 +410,8 @@ static Oid
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;
@@ -434,42 +433,14 @@ GetAttrOpClass(IndexElem *attribute, Oid attrType,
*/
/* 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),
diff --git a/src/backend/commands/opclasscmds.c b/src/backend/commands/opclasscmds.c
index fb86c980b98..c56b0e1fa84 100644
--- a/src/backend/commands/opclasscmds.c
+++ b/src/backend/commands/opclasscmds.c
@@ -9,7 +9,7 @@
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
@@ -467,10 +467,9 @@ storeProcedures(Oid opclassoid, int numProcs, Oid *procedures)
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;
@@ -489,42 +488,14 @@ RemoveOpClass(RemoveOpClassStmt *stmt)
*/
/* 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),