diff options
author | Bruce Momjian <bruce@momjian.us> | 2002-03-19 02:58:20 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2002-03-19 02:58:20 +0000 |
commit | a9819ca253ba13f07a6c4433ef5ecd94c007a716 (patch) | |
tree | 9c4d6695aaedaafe7927b6cfcadd7ac4ef66c87f /src/backend/tcop/utility.c | |
parent | d8e70cd829c517890fd35de74d2654e5bdaf201b (diff) | |
download | postgresql-a9819ca253ba13f07a6c4433ef5ecd94c007a716.tar.gz postgresql-a9819ca253ba13f07a6c4433ef5ecd94c007a716.zip |
The attached patch cleans up the implementation of the TRUNCATE command;
in the current code, the authentication logic (check user, check the
relation we're operating on, etc) is done in tcop/utility.c, whereas the
actual TRUNCATE command in done in TruncateRelation() in
commands/createinh.c (which is really just a wrapper over
heap_truncate() in catalog/heap.c). This patch moves the authentication
logic into TruncateRelation(), as well as making some minor code
cleanups.
Neil Conway
Diffstat (limited to 'src/backend/tcop/utility.c')
-rw-r--r-- | src/backend/tcop/utility.c | 27 |
1 files changed, 3 insertions, 24 deletions
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index a6400eabc35..0c1ead0331c 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.133 2002/03/19 02:18:20 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.134 2002/03/19 02:58:19 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -216,9 +216,7 @@ ProcessUtility(Node *parsetree, break; /* - * ******************************** relation and attribute - * manipulation ******************************** - * + * relation and attribute manipulation */ case T_CreateStmt: DefineRelation((CreateStmt *) parsetree, RELKIND_RELATION); @@ -301,26 +299,7 @@ ProcessUtility(Node *parsetree, case T_TruncateStmt: { - Relation rel; - - relname = ((TruncateStmt *) parsetree)->relName; - if (!allowSystemTableMods && IsSystemRelationName(relname)) - elog(ERROR, "TRUNCATE cannot be used on system tables. '%s' is a system table", - relname); - - /* Grab exclusive lock in preparation for truncate... */ - rel = heap_openr(relname, AccessExclusiveLock); - if (rel->rd_rel->relkind == RELKIND_SEQUENCE) - elog(ERROR, "TRUNCATE cannot be used on sequences. '%s' is a sequence", - relname); - if (rel->rd_rel->relkind == RELKIND_VIEW) - elog(ERROR, "TRUNCATE cannot be used on views. '%s' is a view", - relname); - heap_close(rel, NoLock); - - if (!pg_ownercheck(GetUserId(), relname, RELNAME)) - elog(ERROR, "you do not own class \"%s\"", relname); - TruncateRelation(relname); + TruncateRelation(((TruncateStmt *) parsetree)->relName); } break; |