File: test.sql

package info (click to toggle)
postgis 2.3.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 58,660 kB
  • ctags: 10,181
  • sloc: ansic: 132,858; sql: 131,148; xml: 46,460; sh: 4,832; perl: 4,476; makefile: 2,749; python: 1,198; yacc: 442; lex: 131
file content (59 lines) | stat: -rw-r--r-- 1,342 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

CREATE TABLE test_locks (id serial, b char(16), c char(16) );
INSERT INTO test_locks(b) VALUES ('one');
INSERT INTO test_locks(b) VALUES ('two');
INSERT INTO test_locks(b) VALUES ('three');

-- Enable locks checking on the table
SELECT CheckAuth('test_locks', 'id');

-- this has no lock
UPDATE test_locks SET c = 'nolocks';

-- place the lock
SELECT LockRow('test_locks', '1', 'auth1', now()::timestamp+'00:01');
SELECT LockRow('test_locks', '2', 'auth2', now()::timestamp+'00:01');

-- this should fail due to missing auth
UPDATE test_locks SET c = 'unauthorized' where id = 1;

BEGIN;

	-- Add authorization for row 1
	SELECT AddAuth('auth1');

	-- we're authorized for row 1
	UPDATE test_locks SET c = 'authorized' where id = 1;

END;

-- Out of transaction we're no more authorized for row 1
UPDATE test_locks SET c = 'unauthorized' where id = 1;

BEGIN;

	-- Add authorization for row 2
	SELECT AddAuth('auth2');

	-- we're authorized for row 2
	UPDATE test_locks SET c = 'authorized' where id = 2;

END;


BEGIN;

	-- Add authorization for row 2
	SELECT AddAuth('auth2');

	-- we're *not* authorized for row 1
	UPDATE test_locks SET c = 'unauthorized' where id = 1;

END;

UPDATE test_locks SET c = 'unauthorized' where id = 2;
UPDATE test_locks SET c = 'unauthorized' where id = 1;

SELECT * from test_locks;
DROP TABLE test_locks;