Index: src/backend/catalog/heap.c =================================================================== RCS file: /var/lib/cvs/pgsql/src/backend/catalog/heap.c,v retrieving revision 1.186 diff -c -r1.186 heap.c *** src/backend/catalog/heap.c 7 Mar 2002 16:35:33 -0000 1.186 --- src/backend/catalog/heap.c 13 Mar 2002 23:27:26 -0000 *************** *** 1051,1057 **** */ void ! heap_truncate(char *relname) { Relation rel; Oid rid; --- 1051,1057 ---- */ void ! heap_truncate(const char *relname) { Relation rel; Oid rid; Index: src/backend/commands/creatinh.c =================================================================== RCS file: /var/lib/cvs/pgsql/src/backend/commands/creatinh.c,v retrieving revision 1.85 diff -c -r1.85 creatinh.c *** src/backend/commands/creatinh.c 7 Mar 2002 16:35:34 -0000 1.85 --- src/backend/commands/creatinh.c 13 Mar 2002 23:27:26 -0000 *************** *** 16,21 **** --- 16,22 ---- #include "postgres.h" #include "access/heapam.h" + #include "catalog/catalog.h" #include "catalog/catname.h" #include "catalog/indexing.h" #include "catalog/heap.h" *************** *** 214,220 **** * themselves will be destroyed, too. */ void ! RemoveRelation(char *name) { AssertArg(name); heap_drop_with_catalog(name, allowSystemTableMods); --- 215,221 ---- * themselves will be destroyed, too. */ void ! RemoveRelation(const char *name) { AssertArg(name); heap_drop_with_catalog(name, allowSystemTableMods); *************** *** 231,240 **** * Rows are removed, indices are truncated and reconstructed. */ void ! TruncateRelation(char *name) { ! AssertArg(name); ! heap_truncate(name); } /*---------- --- 232,265 ---- * Rows are removed, indices are truncated and reconstructed. */ void ! TruncateRelation(const char *relname) { ! Relation rel; ! ! AssertArg(relname); ! ! if (!allowSystemTableMods && IsSystemRelationName(relname)) ! elog(ERROR, "TRUNCATE cannot be used on system tables. '%s' is a system table", ! relname); ! ! if (!pg_ownercheck(GetUserId(), relname, RELNAME)) ! elog(ERROR, "you do not own relation \"%s\"", 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); ! ! /* Keep the lock until transaction commit */ ! heap_close(rel, NoLock); ! ! heap_truncate(relname); } /*---------- Index: src/backend/tcop/utility.c =================================================================== RCS file: /var/lib/cvs/pgsql/src/backend/tcop/utility.c,v retrieving revision 1.132 diff -c -r1.132 utility.c *** src/backend/tcop/utility.c 7 Mar 2002 16:35:36 -0000 1.132 --- src/backend/tcop/utility.c 13 Mar 2002 23:27:26 -0000 *************** *** 216,224 **** break; /* ! * ******************************** relation and attribute ! * manipulation ******************************** ! * */ case T_CreateStmt: DefineRelation((CreateStmt *) parsetree, RELKIND_RELATION); --- 216,222 ---- break; /* ! * relation and attribute manipulation */ case T_CreateStmt: DefineRelation((CreateStmt *) parsetree, RELKIND_RELATION); *************** *** 296,321 **** 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); } break; --- 294,300 ---- case T_TruncateStmt: { ! TruncateRelation(((TruncateStmt *) parsetree)->relName); } break; Index: src/include/catalog/heap.h =================================================================== RCS file: /var/lib/cvs/pgsql/src/include/catalog/heap.h,v retrieving revision 1.43 diff -c -r1.43 heap.h *** src/include/catalog/heap.h 7 Mar 2002 16:35:38 -0000 1.43 --- src/include/catalog/heap.h 13 Mar 2002 23:27:26 -0000 *************** *** 39,45 **** extern void heap_drop_with_catalog(const char *relname, bool allow_system_table_mods); ! extern void heap_truncate(char *relname); extern void AddRelationRawConstraints(Relation rel, List *rawColDefaults, --- 39,45 ---- extern void heap_drop_with_catalog(const char *relname, bool allow_system_table_mods); ! extern void heap_truncate(const char *relname); extern void AddRelationRawConstraints(Relation rel, List *rawColDefaults, Index: src/include/commands/creatinh.h =================================================================== RCS file: /var/lib/cvs/pgsql/src/include/commands/creatinh.h,v retrieving revision 1.17 diff -c -r1.17 creatinh.h *** src/include/commands/creatinh.h 5 Nov 2001 17:46:33 -0000 1.17 --- src/include/commands/creatinh.h 13 Mar 2002 23:27:26 -0000 *************** *** 17,23 **** #include "nodes/parsenodes.h" extern void DefineRelation(CreateStmt *stmt, char relkind); ! extern void RemoveRelation(char *name); ! extern void TruncateRelation(char *name); #endif /* CREATINH_H */ --- 17,23 ---- #include "nodes/parsenodes.h" extern void DefineRelation(CreateStmt *stmt, char relkind); ! extern void RemoveRelation(const char *name); ! extern void TruncateRelation(const char *name); #endif /* CREATINH_H */