~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/backend/commands/lockcmds.c

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * lockcmds.c
 
4
 *        Lock command support code
 
5
 *
 
6
 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
 
7
 * Portions Copyright (c) 1994, Regents of the University of California
 
8
 *
 
9
 *
 
10
 * IDENTIFICATION
 
11
 *        $PostgreSQL: pgsql/src/backend/commands/lockcmds.c,v 1.12 2004-12-31 21:59:41 pgsql Exp $
 
12
 *
 
13
 *-------------------------------------------------------------------------
 
14
 */
 
15
#include "postgres.h"
 
16
 
 
17
#include "access/heapam.h"
 
18
#include "catalog/namespace.h"
 
19
#include "commands/lockcmds.h"
 
20
#include "miscadmin.h"
 
21
#include "utils/acl.h"
 
22
#include "utils/lsyscache.h"
 
23
 
 
24
 
 
25
/*
 
26
 * LOCK TABLE
 
27
 */
 
28
void
 
29
LockTableCommand(LockStmt *lockstmt)
 
30
{
 
31
        ListCell   *p;
 
32
 
 
33
        /*
 
34
         * Iterate over the list and open, lock, and close the relations one
 
35
         * at a time
 
36
         */
 
37
 
 
38
        foreach(p, lockstmt->relations)
 
39
        {
 
40
                RangeVar   *relation = lfirst(p);
 
41
                Oid                     reloid;
 
42
                AclResult       aclresult;
 
43
                Relation        rel;
 
44
 
 
45
                /*
 
46
                 * We don't want to open the relation until we've checked
 
47
                 * privilege. So, manually get the relation OID.
 
48
                 */
 
49
                reloid = RangeVarGetRelid(relation, false);
 
50
 
 
51
                if (lockstmt->mode == AccessShareLock)
 
52
                        aclresult = pg_class_aclcheck(reloid, GetUserId(),
 
53
                                                                                  ACL_SELECT);
 
54
                else
 
55
                        aclresult = pg_class_aclcheck(reloid, GetUserId(),
 
56
                                                                                  ACL_UPDATE | ACL_DELETE);
 
57
 
 
58
                if (aclresult != ACLCHECK_OK)
 
59
                        aclcheck_error(aclresult, ACL_KIND_CLASS,
 
60
                                                   get_rel_name(reloid));
 
61
 
 
62
                rel = conditional_relation_open(reloid, lockstmt->mode, lockstmt->nowait);
 
63
 
 
64
                /* Currently, we only allow plain tables to be locked */
 
65
                if (rel->rd_rel->relkind != RELKIND_RELATION)
 
66
                        ereport(ERROR,
 
67
                                        (errcode(ERRCODE_WRONG_OBJECT_TYPE),
 
68
                                         errmsg("\"%s\" is not a table",
 
69
                                                        relation->relname)));
 
70
 
 
71
                relation_close(rel, NoLock);    /* close rel, keep lock */
 
72
        }
 
73
}