aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/lockcmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-04-15 05:22:04 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-04-15 05:22:04 +0000
commit71dc300a375f4932693b064b161a400448c9bc2e (patch)
treeab20c095125a6eab33644befd187f936cf4fd093 /src/backend/commands/lockcmds.c
parentab1ead6b9761531787c78e0c80daf98b421ac06f (diff)
downloadpostgresql-71dc300a375f4932693b064b161a400448c9bc2e.tar.gz
postgresql-71dc300a375f4932693b064b161a400448c9bc2e.zip
The contents of command.c, creatinh.c, define.c, remove.c and rename.c
have been divided according to the type of object manipulated - so ALTER TABLE code is in tablecmds.c, aggregate commands in aggregatecmds.c and so on. A few common support routines remain in define.c (prototypes in src/include/commands/defrem.h). No code has been changed except for includes to reflect the new files. The prototypes for aggregatecmds.c, functioncmds.c, operatorcmds.c, and typecmds.c remain in src/include/commands/defrem.h. From John Gray <jgray@azuli.co.uk>
Diffstat (limited to 'src/backend/commands/lockcmds.c')
-rw-r--r--src/backend/commands/lockcmds.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/backend/commands/lockcmds.c b/src/backend/commands/lockcmds.c
new file mode 100644
index 00000000000..c91669572ef
--- /dev/null
+++ b/src/backend/commands/lockcmds.c
@@ -0,0 +1,69 @@
+/*-------------------------------------------------------------------------
+ *
+ * lockcmds.c
+ * Lock command support code
+ *
+ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ *
+ * IDENTIFICATION
+ * $Header: /cvsroot/pgsql/src/backend/commands/lockcmds.c,v 1.1 2002/04/15 05:22:03 tgl Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+#include "postgres.h"
+
+#include "access/heapam.h"
+#include "catalog/namespace.h"
+#include "commands/lockcmds.h"
+#include "miscadmin.h"
+#include "utils/acl.h"
+
+
+/*
+ * LOCK TABLE
+ */
+void
+LockTableCommand(LockStmt *lockstmt)
+{
+ List *p;
+
+ /*
+ * Iterate over the list and open, lock, and close the relations one
+ * at a time
+ */
+
+ foreach(p, lockstmt->relations)
+ {
+ RangeVar *relation = lfirst(p);
+ Oid reloid;
+ int32 aclresult;
+ Relation rel;
+
+ /*
+ * We don't want to open the relation until we've checked privilege.
+ * So, manually get the relation OID.
+ */
+ reloid = RangeVarGetRelid(relation, false);
+
+ if (lockstmt->mode == AccessShareLock)
+ aclresult = pg_class_aclcheck(reloid, GetUserId(),
+ ACL_SELECT);
+ else
+ aclresult = pg_class_aclcheck(reloid, GetUserId(),
+ ACL_UPDATE | ACL_DELETE);
+
+ if (aclresult != ACLCHECK_OK)
+ elog(ERROR, "LOCK TABLE: permission denied");
+
+ rel = relation_open(reloid, lockstmt->mode);
+
+ /* Currently, we only allow plain tables to be locked */
+ if (rel->rd_rel->relkind != RELKIND_RELATION)
+ elog(ERROR, "LOCK TABLE: %s is not a table",
+ relation->relname);
+
+ relation_close(rel, NoLock); /* close rel, keep lock */
+ }
+}