Mercurial > cpython-lru_cache-weakref
annotate Lib/sqlite3/test/transactions.py @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | 04d3ae52ff73 |
| children |
| rev | line source |
|---|---|
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1 #-*- coding: ISO-8859-1 -*- |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
2 # pysqlite2/test/transactions.py: tests transactions |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
3 # |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
4 # Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de> |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
5 # |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
6 # This file is part of pysqlite. |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
7 # |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
8 # This software is provided 'as-is', without any express or implied |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
9 # warranty. In no event will the authors be held liable for any damages |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
10 # arising from the use of this software. |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
11 # |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
12 # Permission is granted to anyone to use this software for any purpose, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
13 # including commercial applications, and to alter it and redistribute it |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
14 # freely, subject to the following restrictions: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
15 # |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
16 # 1. The origin of this software must not be misrepresented; you must not |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
17 # claim that you wrote the original software. If you use this software |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
18 # in a product, an acknowledgment in the product documentation would be |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
19 # appreciated but is not required. |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
20 # 2. Altered source versions must be plainly marked as such, and must not be |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
21 # misrepresented as being the original software. |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
22 # 3. This notice may not be removed or altered from any source distribution. |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
23 |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
24 import sys |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
25 import os, unittest |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
26 import sqlite3 as sqlite |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
27 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
28 def get_db_path(): |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
29 return "sqlite_testdb" |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
30 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
31 class TransactionTests(unittest.TestCase): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
32 def setUp(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
33 try: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
34 os.remove(get_db_path()) |
|
45664
beab9e10a18b
Catch OSError when trying to remove a file in case removal fails. This
Neal Norwitz <nnorwitz@gmail.com>
parents:
45580
diff
changeset
|
35 except OSError: |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
36 pass |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
37 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
38 self.con1 = sqlite.connect(get_db_path(), timeout=0.1) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
39 self.cur1 = self.con1.cursor() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
40 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
41 self.con2 = sqlite.connect(get_db_path(), timeout=0.1) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
42 self.cur2 = self.con2.cursor() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
43 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
44 def tearDown(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
45 self.cur1.close() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
46 self.con1.close() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
47 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
48 self.cur2.close() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
49 self.con2.close() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
50 |
|
45664
beab9e10a18b
Catch OSError when trying to remove a file in case removal fails. This
Neal Norwitz <nnorwitz@gmail.com>
parents:
45580
diff
changeset
|
51 try: |
|
beab9e10a18b
Catch OSError when trying to remove a file in case removal fails. This
Neal Norwitz <nnorwitz@gmail.com>
parents:
45580
diff
changeset
|
52 os.unlink(get_db_path()) |
|
beab9e10a18b
Catch OSError when trying to remove a file in case removal fails. This
Neal Norwitz <nnorwitz@gmail.com>
parents:
45580
diff
changeset
|
53 except OSError: |
|
beab9e10a18b
Catch OSError when trying to remove a file in case removal fails. This
Neal Norwitz <nnorwitz@gmail.com>
parents:
45580
diff
changeset
|
54 pass |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
55 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
56 def CheckDMLdoesAutoCommitBefore(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
57 self.cur1.execute("create table test(i)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
58 self.cur1.execute("insert into test(i) values (5)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
59 self.cur1.execute("create table test2(j)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
60 self.cur2.execute("select i from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
61 res = self.cur2.fetchall() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46303
diff
changeset
|
62 self.assertEqual(len(res), 1) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
63 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
64 def CheckInsertStartsTransaction(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
65 self.cur1.execute("create table test(i)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
66 self.cur1.execute("insert into test(i) values (5)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
67 self.cur2.execute("select i from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
68 res = self.cur2.fetchall() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46303
diff
changeset
|
69 self.assertEqual(len(res), 0) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
70 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
71 def CheckUpdateStartsTransaction(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
72 self.cur1.execute("create table test(i)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
73 self.cur1.execute("insert into test(i) values (5)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
74 self.con1.commit() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
75 self.cur1.execute("update test set i=6") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
76 self.cur2.execute("select i from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
77 res = self.cur2.fetchone()[0] |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46303
diff
changeset
|
78 self.assertEqual(res, 5) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
79 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
80 def CheckDeleteStartsTransaction(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
81 self.cur1.execute("create table test(i)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
82 self.cur1.execute("insert into test(i) values (5)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
83 self.con1.commit() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
84 self.cur1.execute("delete from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
85 self.cur2.execute("select i from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
86 res = self.cur2.fetchall() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46303
diff
changeset
|
87 self.assertEqual(len(res), 1) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
88 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
89 def CheckReplaceStartsTransaction(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
90 self.cur1.execute("create table test(i)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
91 self.cur1.execute("insert into test(i) values (5)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
92 self.con1.commit() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
93 self.cur1.execute("replace into test(i) values (6)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
94 self.cur2.execute("select i from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
95 res = self.cur2.fetchall() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46303
diff
changeset
|
96 self.assertEqual(len(res), 1) |
|
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46303
diff
changeset
|
97 self.assertEqual(res[0][0], 5) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
98 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
99 def CheckToggleAutoCommit(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
100 self.cur1.execute("create table test(i)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
101 self.cur1.execute("insert into test(i) values (5)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
102 self.con1.isolation_level = None |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46303
diff
changeset
|
103 self.assertEqual(self.con1.isolation_level, None) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
104 self.cur2.execute("select i from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
105 res = self.cur2.fetchall() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46303
diff
changeset
|
106 self.assertEqual(len(res), 1) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
107 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
108 self.con1.isolation_level = "DEFERRED" |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46303
diff
changeset
|
109 self.assertEqual(self.con1.isolation_level , "DEFERRED") |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
110 self.cur1.execute("insert into test(i) values (5)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
111 self.cur2.execute("select i from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
112 res = self.cur2.fetchall() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46303
diff
changeset
|
113 self.assertEqual(len(res), 1) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
114 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
115 def CheckRaiseTimeout(self): |
|
46303
de77973d7e1a
Prevent test_sqlite from hanging on older versions of sqlite.
Neal Norwitz <nnorwitz@gmail.com>
parents:
45664
diff
changeset
|
116 if sqlite.sqlite_version_info < (3, 2, 2): |
|
de77973d7e1a
Prevent test_sqlite from hanging on older versions of sqlite.
Neal Norwitz <nnorwitz@gmail.com>
parents:
45664
diff
changeset
|
117 # This will fail (hang) on earlier versions of sqlite. |
|
de77973d7e1a
Prevent test_sqlite from hanging on older versions of sqlite.
Neal Norwitz <nnorwitz@gmail.com>
parents:
45664
diff
changeset
|
118 # Determine exact version it was fixed. 3.2.1 hangs. |
|
de77973d7e1a
Prevent test_sqlite from hanging on older versions of sqlite.
Neal Norwitz <nnorwitz@gmail.com>
parents:
45664
diff
changeset
|
119 return |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
120 self.cur1.execute("create table test(i)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
121 self.cur1.execute("insert into test(i) values (5)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
122 try: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
123 self.cur2.execute("insert into test(i) values (5)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
124 self.fail("should have raised an OperationalError") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
125 except sqlite.OperationalError: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
126 pass |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
127 except: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
128 self.fail("should have raised an OperationalError") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
129 |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
130 def CheckLocking(self): |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
131 """ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
132 This tests the improved concurrency with pysqlite 2.3.4. You needed |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
133 to roll back con2 before you could commit con1. |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
134 """ |
|
46303
de77973d7e1a
Prevent test_sqlite from hanging on older versions of sqlite.
Neal Norwitz <nnorwitz@gmail.com>
parents:
45664
diff
changeset
|
135 if sqlite.sqlite_version_info < (3, 2, 2): |
|
de77973d7e1a
Prevent test_sqlite from hanging on older versions of sqlite.
Neal Norwitz <nnorwitz@gmail.com>
parents:
45664
diff
changeset
|
136 # This will fail (hang) on earlier versions of sqlite. |
|
de77973d7e1a
Prevent test_sqlite from hanging on older versions of sqlite.
Neal Norwitz <nnorwitz@gmail.com>
parents:
45664
diff
changeset
|
137 # Determine exact version it was fixed. 3.2.1 hangs. |
|
de77973d7e1a
Prevent test_sqlite from hanging on older versions of sqlite.
Neal Norwitz <nnorwitz@gmail.com>
parents:
45664
diff
changeset
|
138 return |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
139 self.cur1.execute("create table test(i)") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
140 self.cur1.execute("insert into test(i) values (5)") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
141 try: |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
142 self.cur2.execute("insert into test(i) values (5)") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
143 self.fail("should have raised an OperationalError") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
144 except sqlite.OperationalError: |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
145 pass |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
146 except: |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
147 self.fail("should have raised an OperationalError") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
148 # NO self.con2.rollback() HERE!!! |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
149 self.con1.commit() |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
150 |
|
59362
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
151 def CheckRollbackCursorConsistency(self): |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
152 """ |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
153 Checks if cursors on the connection are set into a "reset" state |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
154 when a rollback is done on the connection. |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
155 """ |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
156 con = sqlite.connect(":memory:") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
157 cur = con.cursor() |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
158 cur.execute("create table test(x)") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
159 cur.execute("insert into test(x) values (5)") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
160 cur.execute("select 1 union select 2 union select 3") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
161 |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
162 con.rollback() |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
163 try: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
164 cur.fetchall() |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
165 self.fail("InterfaceError should have been raised") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
166 except sqlite.InterfaceError, e: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
167 pass |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
168 except: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
169 self.fail("InterfaceError should have been raised") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
170 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
171 class SpecialCommandTests(unittest.TestCase): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
172 def setUp(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
173 self.con = sqlite.connect(":memory:") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
174 self.cur = self.con.cursor() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
175 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
176 def CheckVacuum(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
177 self.cur.execute("create table test(i)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
178 self.cur.execute("insert into test(i) values (5)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
179 self.cur.execute("vacuum") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
180 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
181 def CheckDropTable(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
182 self.cur.execute("create table test(i)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
183 self.cur.execute("insert into test(i) values (5)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
184 self.cur.execute("drop table test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
185 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
186 def CheckPragma(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
187 self.cur.execute("create table test(i)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
188 self.cur.execute("insert into test(i) values (5)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
189 self.cur.execute("pragma count_changes=1") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
190 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
191 def tearDown(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
192 self.cur.close() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
193 self.con.close() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
194 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
195 def suite(): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
196 default_suite = unittest.makeSuite(TransactionTests, "Check") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
197 special_command_suite = unittest.makeSuite(SpecialCommandTests, "Check") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
198 return unittest.TestSuite((default_suite, special_command_suite)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
199 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
200 def test(): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
201 runner = unittest.TextTestRunner() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
202 runner.run(suite()) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
203 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
204 if __name__ == "__main__": |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
205 test() |
