Mercurial > cpython-lru_cache-weakref
annotate Lib/sqlite3/test/regression.py @ 78069:a8aa77458e12 3.2
Add c_size_t and c_ssize_t to the ctypes summary table.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Thu, 12 Jul 2012 20:31:50 +0200 |
| parents | d51ceef4b62f |
| children | 46d5317a51fb 630dfddab73c |
| rev | line source |
|---|---|
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
1 #-*- coding: ISO-8859-1 -*- |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
2 # pysqlite2/test/regression.py: pysqlite regression tests |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
3 # |
|
59372
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
4 # Copyright (C) 2006-2010 Gerhard Häring <gh@ghaering.de> |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
5 # |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
6 # This file is part of pysqlite. |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
7 # |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
8 # This software is provided 'as-is', without any express or implied |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
9 # warranty. In no event will the authors be held liable for any damages |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
10 # arising from the use of this software. |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
11 # |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
12 # Permission is granted to anyone to use this software for any purpose, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
13 # including commercial applications, and to alter it and redistribute it |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
14 # freely, subject to the following restrictions: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
15 # |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
16 # 1. The origin of this software must not be misrepresented; you must not |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
17 # claim that you wrote the original software. If you use this software |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
18 # in a product, an acknowledgment in the product documentation would be |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
19 # appreciated but is not required. |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
20 # 2. Altered source versions must be plainly marked as such, and must not be |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
21 # misrepresented as being the original software. |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
22 # 3. This notice may not be removed or altered from any source distribution. |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
23 |
|
46178
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
24 import datetime |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
25 import unittest |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
26 import sqlite3 as sqlite |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
27 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
28 class RegressionTests(unittest.TestCase): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
29 def setUp(self): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
30 self.con = sqlite.connect(":memory:") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
31 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
32 def tearDown(self): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
33 self.con.close() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
34 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
35 def CheckPragmaUserVersion(self): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
36 # This used to crash pysqlite because this pragma command returns NULL for the column name |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
37 cur = self.con.cursor() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
38 cur.execute("pragma user_version") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
39 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
40 def CheckPragmaSchemaVersion(self): |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
41 # This still crashed pysqlite <= 2.2.1 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
42 con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES) |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
43 try: |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
44 cur = self.con.cursor() |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
45 cur.execute("pragma schema_version") |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
46 finally: |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
47 cur.close() |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
48 con.close() |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
49 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
50 def CheckStatementReset(self): |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
51 # pysqlite 2.1.0 to 2.2.0 have the problem that not all statements are |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
52 # reset before a rollback, but only those that are still in the |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
53 # statement cache. The others are not accessible from the connection object. |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
54 con = sqlite.connect(":memory:", cached_statements=5) |
|
41642
a6eb6acfe04a
Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40643
diff
changeset
|
55 cursors = [con.cursor() for x in range(5)] |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
56 cursors[0].execute("create table test(x)") |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
57 for i in range(10): |
|
41642
a6eb6acfe04a
Merged revisions 55007-55179 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40643
diff
changeset
|
58 cursors[0].executemany("insert into test(x) values (?)", [(x,) for x in range(10)]) |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
59 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
60 for i in range(5): |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
61 cursors[i].execute(" " * i + "select x from test") |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
62 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
63 con.rollback() |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
64 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
65 def CheckColumnNameWithSpaces(self): |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
66 cur = self.con.cursor() |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
67 cur.execute('select 1 as "foo bar [datetime]"') |
|
55602
680ad8eed33b
Merged revisions 73833,73838,73850-73852,73856-73857 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49264
diff
changeset
|
68 self.assertEqual(cur.description[0][0], "foo bar") |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
69 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
70 cur.execute('select 1 as "foo baz"') |
|
55602
680ad8eed33b
Merged revisions 73833,73838,73850-73852,73856-73857 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49264
diff
changeset
|
71 self.assertEqual(cur.description[0][0], "foo baz") |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
72 |
|
46178
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
73 def CheckStatementFinalizationOnCloseDb(self): |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
74 # pysqlite versions <= 2.3.3 only finalized statements in the statement |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
75 # cache when closing the database. statements that were still |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
76 # referenced in cursors weren't closed an could provoke " |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
77 # "OperationalError: Unable to close due to unfinalised statements". |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
78 con = sqlite.connect(":memory:") |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
79 cursors = [] |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
80 # default statement cache size is 100 |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
81 for i in range(105): |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
82 cur = con.cursor() |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
83 cursors.append(cur) |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
84 cur.execute("select 1 x union select " + str(i)) |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
85 con.close() |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
86 |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
87 def CheckOnConflictRollback(self): |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
88 if sqlite.sqlite_version_info < (3, 2, 2): |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
89 return |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
90 con = sqlite.connect(":memory:") |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
91 con.execute("create table foo(x, unique(x) on conflict rollback)") |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
92 con.execute("insert into foo(x) values (1)") |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
93 try: |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
94 con.execute("insert into foo(x) values (1)") |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
95 except sqlite.DatabaseError: |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
96 pass |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
97 con.execute("insert into foo(x) values (2)") |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
98 try: |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
99 con.commit() |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
100 except sqlite.OperationalError: |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
101 self.fail("pysqlite knew nothing about the implicit ROLLBACK") |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
102 |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
103 def CheckWorkaroundForBuggySqliteTransferBindings(self): |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
104 """ |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
105 pysqlite would crash with older SQLite versions unless |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
106 a workaround is implemented. |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
107 """ |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
108 self.con.execute("create table foo(bar)") |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
109 self.con.execute("drop table foo") |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
110 self.con.execute("create table foo(bar)") |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
111 |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
112 def CheckEmptyStatement(self): |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
113 """ |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
114 pysqlite used to segfault with SQLite versions 3.5.x. These return NULL |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
115 for "no-operation" statements |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
116 """ |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
117 self.con.execute("") |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
118 |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
119 def CheckTypeMapUsage(self): |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
120 """ |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
121 pysqlite until 2.4.1 did not rebuild the row_cast_map when recompiling |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
122 a statement. This test exhibits the problem. |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
123 """ |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
124 SELECT = "select * from foo" |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
125 con = sqlite.connect(":memory:",detect_types=sqlite.PARSE_DECLTYPES) |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
126 con.execute("create table foo(bar timestamp)") |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
127 con.execute("insert into foo(bar) values (?)", (datetime.datetime.now(),)) |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
128 con.execute(SELECT) |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
129 con.execute("drop table foo") |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
130 con.execute("create table foo(bar integer)") |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
131 con.execute("insert into foo(bar) values (5)") |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
132 con.execute(SELECT) |
|
e06e08e8fdce
Bring sqlite3 module up-to-date with what's now in 2.6. Almost. I intentionally
Gerhard Häring <gh@ghaering.de>
parents:
45581
diff
changeset
|
133 |
|
45581
fc6f90545cb4
Make sure we get usable error messages when text could not be decoded when fetched from the database.
Gerhard Häring <gh@ghaering.de>
parents:
41642
diff
changeset
|
134 def CheckErrorMsgDecodeError(self): |
|
fc6f90545cb4
Make sure we get usable error messages when text could not be decoded when fetched from the database.
Gerhard Häring <gh@ghaering.de>
parents:
41642
diff
changeset
|
135 # When porting the module to Python 3.0, the error message about |
|
fc6f90545cb4
Make sure we get usable error messages when text could not be decoded when fetched from the database.
Gerhard Häring <gh@ghaering.de>
parents:
41642
diff
changeset
|
136 # decoding errors disappeared. This verifies they're back again. |
|
fc6f90545cb4
Make sure we get usable error messages when text could not be decoded when fetched from the database.
Gerhard Häring <gh@ghaering.de>
parents:
41642
diff
changeset
|
137 failure = None |
|
fc6f90545cb4
Make sure we get usable error messages when text could not be decoded when fetched from the database.
Gerhard Häring <gh@ghaering.de>
parents:
41642
diff
changeset
|
138 try: |
|
48563
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46178
diff
changeset
|
139 self.con.execute("select 'xxx' || ? || 'yyy' colname", |
|
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46178
diff
changeset
|
140 (bytes(bytearray([250])),)).fetchone() |
|
45581
fc6f90545cb4
Make sure we get usable error messages when text could not be decoded when fetched from the database.
Gerhard Häring <gh@ghaering.de>
parents:
41642
diff
changeset
|
141 failure = "should have raised an OperationalError with detailed description" |
|
fc6f90545cb4
Make sure we get usable error messages when text could not be decoded when fetched from the database.
Gerhard Häring <gh@ghaering.de>
parents:
41642
diff
changeset
|
142 except sqlite.OperationalError as e: |
|
fc6f90545cb4
Make sure we get usable error messages when text could not be decoded when fetched from the database.
Gerhard Häring <gh@ghaering.de>
parents:
41642
diff
changeset
|
143 msg = e.args[0] |
|
fc6f90545cb4
Make sure we get usable error messages when text could not be decoded when fetched from the database.
Gerhard Häring <gh@ghaering.de>
parents:
41642
diff
changeset
|
144 if not msg.startswith("Could not decode to UTF-8 column 'colname' with text 'xxx"): |
|
fc6f90545cb4
Make sure we get usable error messages when text could not be decoded when fetched from the database.
Gerhard Häring <gh@ghaering.de>
parents:
41642
diff
changeset
|
145 failure = "OperationalError did not have expected description text" |
|
fc6f90545cb4
Make sure we get usable error messages when text could not be decoded when fetched from the database.
Gerhard Häring <gh@ghaering.de>
parents:
41642
diff
changeset
|
146 if failure: |
|
fc6f90545cb4
Make sure we get usable error messages when text could not be decoded when fetched from the database.
Gerhard Häring <gh@ghaering.de>
parents:
41642
diff
changeset
|
147 self.fail(failure) |
|
fc6f90545cb4
Make sure we get usable error messages when text could not be decoded when fetched from the database.
Gerhard Häring <gh@ghaering.de>
parents:
41642
diff
changeset
|
148 |
|
48563
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46178
diff
changeset
|
149 def CheckRegisterAdapter(self): |
|
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46178
diff
changeset
|
150 """ |
|
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46178
diff
changeset
|
151 See issue 3312. |
|
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46178
diff
changeset
|
152 """ |
|
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46178
diff
changeset
|
153 self.assertRaises(TypeError, sqlite.register_adapter, {}, None) |
|
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46178
diff
changeset
|
154 |
|
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46178
diff
changeset
|
155 def CheckSetIsolationLevel(self): |
|
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46178
diff
changeset
|
156 """ |
|
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46178
diff
changeset
|
157 See issue 3312. |
|
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46178
diff
changeset
|
158 """ |
|
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46178
diff
changeset
|
159 con = sqlite.connect(":memory:") |
|
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46178
diff
changeset
|
160 setattr(con, "isolation_level", "\xe9") |
|
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46178
diff
changeset
|
161 |
|
59372
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
162 def CheckCursorConstructorCallCheck(self): |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
163 """ |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
164 Verifies that cursor methods check wether base class __init__ was called. |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
165 """ |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
166 class Cursor(sqlite.Cursor): |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
167 def __init__(self, con): |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
168 pass |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
169 |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
170 con = sqlite.connect(":memory:") |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
171 cur = Cursor(con) |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
172 try: |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
173 cur.execute("select 4+5").fetchall() |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
174 self.fail("should have raised ProgrammingError") |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
175 except sqlite.ProgrammingError: |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
176 pass |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
177 except: |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
178 self.fail("should have raised ProgrammingError") |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
179 |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
180 |
|
49264
54613ba1dcad
Issue #3659: Values of string subclasses were not handled correctly when used
Gerhard Häring <gh@ghaering.de>
parents:
48563
diff
changeset
|
181 def CheckStrSubclass(self): |
|
54613ba1dcad
Issue #3659: Values of string subclasses were not handled correctly when used
Gerhard Häring <gh@ghaering.de>
parents:
48563
diff
changeset
|
182 """ |
|
54613ba1dcad
Issue #3659: Values of string subclasses were not handled correctly when used
Gerhard Häring <gh@ghaering.de>
parents:
48563
diff
changeset
|
183 The Python 3.0 port of the module didn't cope with values of subclasses of str. |
|
54613ba1dcad
Issue #3659: Values of string subclasses were not handled correctly when used
Gerhard Häring <gh@ghaering.de>
parents:
48563
diff
changeset
|
184 """ |
|
54613ba1dcad
Issue #3659: Values of string subclasses were not handled correctly when used
Gerhard Häring <gh@ghaering.de>
parents:
48563
diff
changeset
|
185 class MyStr(str): pass |
|
54613ba1dcad
Issue #3659: Values of string subclasses were not handled correctly when used
Gerhard Häring <gh@ghaering.de>
parents:
48563
diff
changeset
|
186 self.con.execute("select ?", (MyStr("abc"),)) |
|
48563
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
46178
diff
changeset
|
187 |
|
59372
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
188 def CheckConnectionConstructorCallCheck(self): |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
189 """ |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
190 Verifies that connection methods check wether base class __init__ was called. |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
191 """ |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
192 class Connection(sqlite.Connection): |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
193 def __init__(self, name): |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
194 pass |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
195 |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
196 con = Connection(":memory:") |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
197 try: |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
198 cur = con.cursor() |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
199 self.fail("should have raised ProgrammingError") |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
200 except sqlite.ProgrammingError: |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
201 pass |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
202 except: |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
203 self.fail("should have raised ProgrammingError") |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
204 |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
205 def CheckCursorRegistration(self): |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
206 """ |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
207 Verifies that subclassed cursor classes are correctly registered with |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
208 the connection object, too. (fetch-across-rollback problem) |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
209 """ |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
210 class Connection(sqlite.Connection): |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
211 def cursor(self): |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
212 return Cursor(self) |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
213 |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
214 class Cursor(sqlite.Cursor): |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
215 def __init__(self, con): |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
216 sqlite.Cursor.__init__(self, con) |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
217 |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
218 con = Connection(":memory:") |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
219 cur = con.cursor() |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
220 cur.execute("create table foo(x)") |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
221 cur.executemany("insert into foo(x) values (?)", [(3,), (4,), (5,)]) |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
222 cur.execute("select x from foo") |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
223 con.rollback() |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
224 try: |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
225 cur.fetchall() |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
226 self.fail("should have raised InterfaceError") |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
227 except sqlite.InterfaceError: |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
228 pass |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
229 except: |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
230 self.fail("should have raised InterfaceError") |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
231 |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
232 def CheckAutoCommit(self): |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
233 """ |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
234 Verifies that creating a connection in autocommit mode works. |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
235 2.5.3 introduced a regression so that these could no longer |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
236 be created. |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
237 """ |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
238 con = sqlite.connect(":memory:", isolation_level=None) |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
239 |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
240 def CheckPragmaAutocommit(self): |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
241 """ |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
242 Verifies that running a PRAGMA statement that does an autocommit does |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
243 work. This did not work in 2.5.3/2.5.4. |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
244 """ |
|
59560
f40a80852480
Merged revisions 78898 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59372
diff
changeset
|
245 cur = self.con.cursor() |
|
59372
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
246 cur.execute("create table foo(bar)") |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
247 cur.execute("insert into foo(bar) values (5)") |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
248 |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
249 cur.execute("pragma page_size") |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
250 row = cur.fetchone() |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
251 |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
252 def CheckSetDict(self): |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
253 """ |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
254 See http://bugs.python.org/issue7478 |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
255 |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
256 It was possible to successfully register callbacks that could not be |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
257 hashed. Return codes of PyDict_SetItem were not checked properly. |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
258 """ |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
259 class NotHashable: |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
260 def __call__(self, *args, **kw): |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
261 pass |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
262 def __hash__(self): |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
263 raise TypeError() |
|
3003c1656e2a
Merged new pysqlite version 2.6.0 from trunk.
Gerhard Häring <gh@ghaering.de>
parents:
55602
diff
changeset
|
264 var = NotHashable() |
|
59560
f40a80852480
Merged revisions 78898 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59372
diff
changeset
|
265 self.assertRaises(TypeError, self.con.create_function, var) |
|
f40a80852480
Merged revisions 78898 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59372
diff
changeset
|
266 self.assertRaises(TypeError, self.con.create_aggregate, var) |
|
f40a80852480
Merged revisions 78898 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59372
diff
changeset
|
267 self.assertRaises(TypeError, self.con.set_authorizer, var) |
|
f40a80852480
Merged revisions 78898 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59372
diff
changeset
|
268 self.assertRaises(TypeError, self.con.set_progress_handler, var) |
|
f40a80852480
Merged revisions 78898 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59372
diff
changeset
|
269 |
|
59854
c073f3c3276e
Merged revisions 78899 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55602
diff
changeset
|
270 def CheckConnectionCall(self): |
|
c073f3c3276e
Merged revisions 78899 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55602
diff
changeset
|
271 """ |
|
c073f3c3276e
Merged revisions 78899 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55602
diff
changeset
|
272 Call a connection with a non-string SQL request: check error handling |
|
c073f3c3276e
Merged revisions 78899 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55602
diff
changeset
|
273 of the statement constructor. |
|
c073f3c3276e
Merged revisions 78899 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55602
diff
changeset
|
274 """ |
|
c073f3c3276e
Merged revisions 78899 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55602
diff
changeset
|
275 self.assertRaises(sqlite.Warning, self.con, 1) |
|
c073f3c3276e
Merged revisions 78899 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
55602
diff
changeset
|
276 |
|
60847
8c0517f50c4e
Merged revisions 80349 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59854
diff
changeset
|
277 def CheckCollation(self): |
|
8c0517f50c4e
Merged revisions 80349 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59854
diff
changeset
|
278 def collation_cb(a, b): |
|
8c0517f50c4e
Merged revisions 80349 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59854
diff
changeset
|
279 return 1 |
|
8c0517f50c4e
Merged revisions 80349 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59854
diff
changeset
|
280 self.assertRaises(sqlite.ProgrammingError, self.con.create_collation, |
|
8c0517f50c4e
Merged revisions 80349 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59854
diff
changeset
|
281 # Lone surrogate cannot be encoded to the default encoding (utf8) |
|
8c0517f50c4e
Merged revisions 80349 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59854
diff
changeset
|
282 "\uDC80", collation_cb) |
|
8c0517f50c4e
Merged revisions 80349 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59854
diff
changeset
|
283 |
|
74812
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
284 def CheckRecursiveCursorUse(self): |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
285 """ |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
286 http://bugs.python.org/issue10811 |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
287 |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
288 Recursively using a cursor, such as when reusing it from a generator led to segfaults. |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
289 Now we catch recursive cursor usage and raise a ProgrammingError. |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
290 """ |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
291 con = sqlite.connect(":memory:") |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
292 |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
293 cur = con.cursor() |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
294 cur.execute("create table a (bar)") |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
295 cur.execute("create table b (baz)") |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
296 |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
297 def foo(): |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
298 cur.execute("insert into a (bar) values (?)", (1,)) |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
299 yield 1 |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
300 |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
301 with self.assertRaises(sqlite.ProgrammingError): |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
302 cur.executemany("insert into b (baz) values (?)", |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
303 ((i,) for i in foo())) |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
304 |
|
d51ceef4b62f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68257
diff
changeset
|
305 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
306 def suite(): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
307 regression_suite = unittest.makeSuite(RegressionTests, "Check") |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
308 return unittest.TestSuite((regression_suite,)) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
309 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
310 def test(): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
311 runner = unittest.TextTestRunner() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
312 runner.run(suite()) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
313 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
314 if __name__ == "__main__": |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
315 test() |
