2002-04-15 07:22:04 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* lockcmds.c
|
|
|
|
* Lock command support code
|
|
|
|
*
|
2004-12-31 23:04:05 +01:00
|
|
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
2002-04-15 07:22:04 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2005-10-15 04:49:52 +02:00
|
|
|
* $PostgreSQL: pgsql/src/backend/commands/lockcmds.c,v 1.13 2005/10/15 02:49:15 momjian Exp $
|
2002-04-15 07:22:04 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include "access/heapam.h"
|
|
|
|
#include "catalog/namespace.h"
|
|
|
|
#include "commands/lockcmds.h"
|
|
|
|
#include "miscadmin.h"
|
|
|
|
#include "utils/acl.h"
|
2002-04-27 05:45:03 +02:00
|
|
|
#include "utils/lsyscache.h"
|
2002-04-15 07:22:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LOCK TABLE
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
LockTableCommand(LockStmt *lockstmt)
|
|
|
|
{
|
2004-05-26 06:41:50 +02:00
|
|
|
ListCell *p;
|
2002-04-15 07:22:04 +02:00
|
|
|
|
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* Iterate over the list and open, lock, and close the relations one at a
|
|
|
|
* time
|
2002-04-15 07:22:04 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
foreach(p, lockstmt->relations)
|
|
|
|
{
|
|
|
|
RangeVar *relation = lfirst(p);
|
|
|
|
Oid reloid;
|
2002-04-27 05:45:03 +02:00
|
|
|
AclResult aclresult;
|
2002-04-15 07:22:04 +02:00
|
|
|
Relation rel;
|
|
|
|
|
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* We don't want to open the relation until we've checked privilege.
|
|
|
|
* So, manually get the relation OID.
|
2002-04-15 07:22:04 +02:00
|
|
|
*/
|
|
|
|
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)
|
2003-08-01 02:15:26 +02:00
|
|
|
aclcheck_error(aclresult, ACL_KIND_CLASS,
|
|
|
|
get_rel_name(reloid));
|
2002-04-15 07:22:04 +02:00
|
|
|
|
2004-03-11 02:47:41 +01:00
|
|
|
rel = conditional_relation_open(reloid, lockstmt->mode, lockstmt->nowait);
|
2002-04-15 07:22:04 +02:00
|
|
|
|
|
|
|
/* Currently, we only allow plain tables to be locked */
|
|
|
|
if (rel->rd_rel->relkind != RELKIND_RELATION)
|
2003-07-20 23:56:35 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
|
|
|
errmsg("\"%s\" is not a table",
|
|
|
|
relation->relname)));
|
2002-04-15 07:22:04 +02:00
|
|
|
|
|
|
|
relation_close(rel, NoLock); /* close rel, keep lock */
|
|
|
|
}
|
|
|
|
}
|