~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to tests/t/savepoints.test

  • Committer: Padraig O'Sullivan
  • Date: 2010-03-15 14:05:26 UTC
  • mfrom: (1237.9.99 staging)
  • Revision ID: osullivan.padraig@gmail.com-20100315140526-opbgwdwn6tfecdkq
MergeĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Tests of various SAVEPOINT functionality
 
2
 
 
3
# Test for Bug #534806 - SAVEPOINT without active transaction
 
4
# triggers assert in InnoDB handler
 
5
 
 
6
SET AUTOCOMMIT = 0;
 
7
CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY);
 
8
COMMIT;
 
9
UPDATE t1 SET id = 2 WHERE id != 2 LIMIT 0;
 
10
SAVEPOINT A;
 
11
 
 
12
DROP TABLE t1;
 
13
 
 
14
# Let's test the non-edge case for SAVEPOINTS:
 
15
#
 
16
# Typical usage pattern of starting a transaction, doing
 
17
# some work, savepointing, do more work, savepointing, etc
 
18
# and committing without any rollbacks or savepoint releases.
 
19
 
 
20
CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY);
 
21
 
 
22
START TRANSACTION;
 
23
 
 
24
INSERT INTO t1 VALUES (1);
 
25
 
 
26
SAVEPOINT A;
 
27
 
 
28
INSERT INTO t1 VALUES (2);
 
29
 
 
30
SAVEPOINT B;
 
31
 
 
32
INSERT INTO t1 VALUES (3);
 
33
 
 
34
COMMIT;
 
35
 
 
36
# t1 should now have 1,2,3 in it.
 
37
SELECT * FROM t1;
 
38
 
 
39
# We now test another typical usage pattern, similar to above,
 
40
# but we issue a ROLLBACK at the end instead of a COMMIT.  All
 
41
# work done in all savepoints should be rolled back.
 
42
 
 
43
START TRANSACTION;
 
44
 
 
45
INSERT INTO t1 VALUES (4);
 
46
 
 
47
SAVEPOINT A;
 
48
 
 
49
INSERT INTO t1 VALUES (5);
 
50
 
 
51
SAVEPOINT B;
 
52
 
 
53
INSERT INTO t1 VALUES (6);
 
54
 
 
55
ROLLBACK;
 
56
 
 
57
# t1 should still have 1,2,3 in it.
 
58
SELECT * FROM t1;
 
59
 
 
60
# We now test the final typical usage pattern, where we
 
61
# ROLLBACK work to a specific SAVEPOINT and then COMMIT.
 
62
 
 
63
START TRANSACTION;
 
64
 
 
65
INSERT INTO t1 VALUES (4);
 
66
 
 
67
SAVEPOINT A;
 
68
 
 
69
INSERT INTO t1 VALUES (5);
 
70
 
 
71
SAVEPOINT B;
 
72
 
 
73
INSERT INTO t1 VALUES (6);
 
74
 
 
75
ROLLBACK TO SAVEPOINT A;
 
76
 
 
77
COMMIT;
 
78
 
 
79
# t1 should have 1,2,3,4 in it.
 
80
SELECT * FROM t1;
 
81
 
 
82
DROP TABLE t1;