1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-27 23:21:58 +03:00

Refactor the handling of the various DropStmt variants so that when multiple

objects are specified, we drop them all in a single performMultipleDeletions
call.  This makes the RESTRICT/CASCADE checks more relaxed: it's not counted
as a cascade if one of the later objects has a dependency on an earlier one.
NOTICE messages about such cases go away, too.

In passing, fix the permissions check for DROP CONVERSION, which for some
reason was never made role-aware, and omitted the namespace-owner exemption
too.

Alex Hunsaker, with further fiddling by me.
This commit is contained in:
Tom Lane
2008-06-14 18:04:34 +00:00
parent 95ce4ee943
commit 0cefb50f3c
20 changed files with 666 additions and 682 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/schemacmds.c,v 1.49 2008/01/03 21:23:15 tgl Exp $
* $PostgreSQL: pgsql/src/backend/commands/schemacmds.c,v 1.50 2008/06/14 18:04:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -148,57 +148,76 @@ CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString)
/*
* RemoveSchema
* Removes a schema.
* RemoveSchemas
* Implements DROP SCHEMA.
*/
void
RemoveSchema(List *names, DropBehavior behavior, bool missing_ok)
RemoveSchemas(DropStmt *drop)
{
char *namespaceName;
Oid namespaceId;
ObjectAddress object;
if (list_length(names) != 1)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("schema name cannot be qualified")));
namespaceName = strVal(linitial(names));
namespaceId = GetSysCacheOid(NAMESPACENAME,
CStringGetDatum(namespaceName),
0, 0, 0);
if (!OidIsValid(namespaceId))
{
if (!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)));
}
return;
}
/* Permission check */
if (!pg_namespace_ownercheck(namespaceId, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_NAMESPACE,
namespaceName);
ObjectAddresses *objects;
ListCell *cell;
/*
* Do the deletion. Objects contained in the schema are removed by means
* of their dependency links to the schema.
* First we identify all the schemas, then we delete them in a single
* performMultipleDeletions() call. This is to avoid unwanted
* DROP RESTRICT errors if one of the schemas depends on another.
*/
object.classId = NamespaceRelationId;
object.objectId = namespaceId;
object.objectSubId = 0;
objects = new_object_addresses();
performDeletion(&object, behavior);
foreach(cell, drop->objects)
{
List *names = (List *) lfirst(cell);
char *namespaceName;
Oid namespaceId;
ObjectAddress object;
if (list_length(names) != 1)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("schema name cannot be qualified")));
namespaceName = strVal(linitial(names));
namespaceId = GetSysCacheOid(NAMESPACENAME,
CStringGetDatum(namespaceName),
0, 0, 0);
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)));
}
continue;
}
/* Permission check */
if (!pg_namespace_ownercheck(namespaceId, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_NAMESPACE,
namespaceName);
object.classId = NamespaceRelationId;
object.objectId = namespaceId;
object.objectSubId = 0;
add_exact_object_address(&object, objects);
}
/*
* Do the deletions. Objects contained in the schema(s) are removed by
* means of their dependency links to the schema.
*/
performMultipleDeletions(objects, drop->behavior);
free_object_addresses(objects);
}