Mercurial > cpython-lru_cache-weakref
annotate Lib/sqlite3/test/regression.py @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | 631e99961c5f |
| children | 6911df35b7b6 |
| rev | line source |
|---|---|
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1 #-*- coding: ISO-8859-1 -*- |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
2 # pysqlite2/test/regression.py: pysqlite regression tests |
|
d27058c409df
Update to pysqlite 2.2.0
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:
40625
diff
changeset
|
4 # Copyright (C) 2006-2007 Gerhard Häring <gh@ghaering.de> |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
5 # |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
6 # This file is part of pysqlite. |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
7 # |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
8 # This software is provided 'as-is', without any express or implied |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
9 # warranty. In no event will the authors be held liable for any damages |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
10 # arising from the use of this software. |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
11 # |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
12 # Permission is granted to anyone to use this software for any purpose, |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
13 # including commercial applications, and to alter it and redistribute it |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
14 # freely, subject to the following restrictions: |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
15 # |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
16 # 1. The origin of this software must not be misrepresented; you must not |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
17 # claim that you wrote the original software. If you use this software |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
18 # in a product, an acknowledgment in the product documentation would be |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
19 # appreciated but is not required. |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
20 # 2. Altered source versions must be plainly marked as such, and must not be |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
21 # misrepresented as being the original software. |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
22 # 3. This notice may not be removed or altered from any source distribution. |
|
d27058c409df
Update to pysqlite 2.2.0
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:
40625
diff
changeset
|
24 import datetime |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
25 import unittest |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
26 import sqlite3 as sqlite |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
27 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
28 class RegressionTests(unittest.TestCase): |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
29 def setUp(self): |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
30 self.con = sqlite.connect(":memory:") |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
31 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
32 def tearDown(self): |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
33 self.con.close() |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
34 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
35 def CheckPragmaUserVersion(self): |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
36 # This used to crash pysqlite because this pragma command returns NULL for the column name |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
37 cur = self.con.cursor() |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
38 cur.execute("pragma user_version") |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
39 |
|
37938
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
40 def CheckPragmaSchemaVersion(self): |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
41 # This still crashed pysqlite <= 2.2.1 |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
42 con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES) |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
43 try: |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
44 cur = self.con.cursor() |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
45 cur.execute("pragma schema_version") |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
46 finally: |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
47 cur.close() |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
48 con.close() |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
49 |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
50 def CheckStatementReset(self): |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
51 # pysqlite 2.1.0 to 2.2.0 have the problem that not all statements are |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
52 # reset before a rollback, but only those that are still in the |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
53 # statement cache. The others are not accessible from the connection object. |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
54 con = sqlite.connect(":memory:", cached_statements=5) |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
55 cursors = [con.cursor() for x in xrange(5)] |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
56 cursors[0].execute("create table test(x)") |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
57 for i in range(10): |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
58 cursors[0].executemany("insert into test(x) values (?)", [(x,) for x in xrange(10)]) |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
59 |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
60 for i in range(5): |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
61 cursors[i].execute(" " * i + "select x from test") |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
62 |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
63 con.rollback() |
|
7da4af95ebad
Updated the sqlite3 module to the external pysqlite 2.2.2 version.
Gerhard Häring <gh@ghaering.de>
parents:
37458
diff
changeset
|
64 |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
65 def CheckColumnNameWithSpaces(self): |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
66 cur = self.con.cursor() |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
67 cur.execute('select 1 as "foo bar [datetime]"') |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
47991
diff
changeset
|
68 self.assertEqual(cur.description[0][0], "foo bar") |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
69 |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37938
diff
changeset
|
70 cur.execute('select 1 as "foo baz"') |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
47991
diff
changeset
|
71 self.assertEqual(cur.description[0][0], "foo baz") |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
72 |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
73 def CheckStatementFinalizationOnCloseDb(self): |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
74 # pysqlite versions <= 2.3.3 only finalized statements in the statement |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
75 # cache when closing the database. statements that were still |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
76 # referenced in cursors weren't closed an could provoke " |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
77 # "OperationalError: Unable to close due to unfinalised statements". |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
78 con = sqlite.connect(":memory:") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
79 cursors = [] |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
80 # default statement cache size is 100 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
81 for i in range(105): |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
82 cur = con.cursor() |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
83 cursors.append(cur) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
84 cur.execute("select 1 x union select " + str(i)) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
85 con.close() |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
86 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
87 def CheckOnConflictRollback(self): |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
88 if sqlite.sqlite_version_info < (3, 2, 2): |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
89 return |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
90 con = sqlite.connect(":memory:") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
91 con.execute("create table foo(x, unique(x) on conflict rollback)") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
92 con.execute("insert into foo(x) values (1)") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
93 try: |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
94 con.execute("insert into foo(x) values (1)") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
95 except sqlite.DatabaseError: |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
96 pass |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
97 con.execute("insert into foo(x) values (2)") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
98 try: |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
99 con.commit() |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
100 except sqlite.OperationalError: |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
101 self.fail("pysqlite knew nothing about the implicit ROLLBACK") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
102 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
103 def CheckWorkaroundForBuggySqliteTransferBindings(self): |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
104 """ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
105 pysqlite would crash with older SQLite versions unless |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
106 a workaround is implemented. |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
107 """ |
|
45608
7628cb403c53
Made sqlite3 module's regression tests work with SQLite versions that don't
Gerhard Häring <gh@ghaering.de>
parents:
45580
diff
changeset
|
108 self.con.execute("create table foo(bar)") |
|
7628cb403c53
Made sqlite3 module's regression tests work with SQLite versions that don't
Gerhard Häring <gh@ghaering.de>
parents:
45580
diff
changeset
|
109 self.con.execute("drop table foo") |
|
7628cb403c53
Made sqlite3 module's regression tests work with SQLite versions that don't
Gerhard Häring <gh@ghaering.de>
parents:
45580
diff
changeset
|
110 self.con.execute("create table foo(bar)") |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
111 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
112 def CheckEmptyStatement(self): |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
113 """ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
114 pysqlite used to segfault with SQLite versions 3.5.x. These return NULL |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
115 for "no-operation" statements |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
116 """ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
117 self.con.execute("") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
118 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
119 def CheckUnicodeConnect(self): |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
120 """ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
121 With pysqlite 2.4.0 you needed to use a string or a APSW connection |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
122 object for opening database connections. |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
123 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
124 Formerly, both bytestrings and unicode strings used to work. |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
125 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
126 Let's make sure unicode strings work in the future. |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
127 """ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
128 con = sqlite.connect(u":memory:") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
129 con.close() |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
130 |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
131 def CheckTypeMapUsage(self): |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
132 """ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
133 pysqlite until 2.4.1 did not rebuild the row_cast_map when recompiling |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
134 a statement. This test exhibits the problem. |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
135 """ |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
136 SELECT = "select * from foo" |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
137 con = sqlite.connect(":memory:",detect_types=sqlite.PARSE_DECLTYPES) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
138 con.execute("create table foo(bar timestamp)") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
139 con.execute("insert into foo(bar) values (?)", (datetime.datetime.now(),)) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
140 con.execute(SELECT) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
141 con.execute("drop table foo") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
142 con.execute("create table foo(bar integer)") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
143 con.execute("insert into foo(bar) values (5)") |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
144 con.execute(SELECT) |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
145 |
|
47991
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
45608
diff
changeset
|
146 def CheckRegisterAdapter(self): |
|
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
45608
diff
changeset
|
147 """ |
|
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
45608
diff
changeset
|
148 See issue 3312. |
|
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
45608
diff
changeset
|
149 """ |
|
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
45608
diff
changeset
|
150 self.assertRaises(TypeError, sqlite.register_adapter, {}, None) |
|
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
45608
diff
changeset
|
151 |
|
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
45608
diff
changeset
|
152 def CheckSetIsolationLevel(self): |
|
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
45608
diff
changeset
|
153 """ |
|
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
45608
diff
changeset
|
154 See issue 3312. |
|
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
45608
diff
changeset
|
155 """ |
|
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
45608
diff
changeset
|
156 con = sqlite.connect(":memory:") |
|
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
45608
diff
changeset
|
157 self.assertRaises(UnicodeEncodeError, setattr, con, |
|
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
45608
diff
changeset
|
158 "isolation_level", u"\xe9") |
|
091df4c08d99
#3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents:
45608
diff
changeset
|
159 |
|
59362
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
160 def CheckCursorConstructorCallCheck(self): |
|
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 Verifies that cursor methods check wether base class __init__ was called. |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
163 """ |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
164 class Cursor(sqlite.Cursor): |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
165 def __init__(self, con): |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
166 pass |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
167 |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
168 con = sqlite.connect(":memory:") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
169 cur = Cursor(con) |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
170 try: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
171 cur.execute("select 4+5").fetchall() |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
172 self.fail("should have raised ProgrammingError") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
173 except sqlite.ProgrammingError: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
174 pass |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
175 except: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
176 self.fail("should have raised ProgrammingError") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
177 |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
178 def CheckConnectionConstructorCallCheck(self): |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
179 """ |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
180 Verifies that connection methods check wether base class __init__ was called. |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
181 """ |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
182 class Connection(sqlite.Connection): |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
183 def __init__(self, name): |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
184 pass |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
185 |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
186 con = Connection(":memory:") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
187 try: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
188 cur = con.cursor() |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
189 self.fail("should have raised ProgrammingError") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
190 except sqlite.ProgrammingError: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
191 pass |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
192 except: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
193 self.fail("should have raised ProgrammingError") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
194 |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
195 def CheckCursorRegistration(self): |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
196 """ |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
197 Verifies that subclassed cursor classes are correctly registered with |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
198 the connection object, too. (fetch-across-rollback problem) |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
199 """ |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
200 class Connection(sqlite.Connection): |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
201 def cursor(self): |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
202 return Cursor(self) |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
203 |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
204 class Cursor(sqlite.Cursor): |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
205 def __init__(self, con): |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
206 sqlite.Cursor.__init__(self, con) |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
207 |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
208 con = Connection(":memory:") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
209 cur = con.cursor() |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
210 cur.execute("create table foo(x)") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
211 cur.executemany("insert into foo(x) values (?)", [(3,), (4,), (5,)]) |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
212 cur.execute("select x from foo") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
213 con.rollback() |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
214 try: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
215 cur.fetchall() |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
216 self.fail("should have raised InterfaceError") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
217 except sqlite.InterfaceError: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
218 pass |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
219 except: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
220 self.fail("should have raised InterfaceError") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
221 |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
222 def CheckAutoCommit(self): |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
223 """ |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
224 Verifies that creating a connection in autocommit mode works. |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
225 2.5.3 introduced a regression so that these could no longer |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
226 be created. |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
227 """ |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
228 con = sqlite.connect(":memory:", isolation_level=None) |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
229 |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
230 def CheckPragmaAutocommit(self): |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
231 """ |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
232 Verifies that running a PRAGMA statement that does an autocommit does |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
233 work. This did not work in 2.5.3/2.5.4. |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
234 """ |
|
59559
1ee2452ce942
sqlite3: Fix a segfault on calling a connection with something else than a
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59362
diff
changeset
|
235 cur = self.con.cursor() |
|
59362
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
236 cur.execute("create table foo(bar)") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
237 cur.execute("insert into foo(bar) values (5)") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
238 |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
239 cur.execute("pragma page_size") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
240 row = cur.fetchone() |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
241 |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
242 def CheckSetDict(self): |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
243 """ |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
244 See http://bugs.python.org/issue7478 |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
245 |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
246 It was possible to successfully register callbacks that could not be |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
247 hashed. Return codes of PyDict_SetItem were not checked properly. |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
248 """ |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
249 class NotHashable: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
250 def __call__(self, *args, **kw): |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
251 pass |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
252 def __hash__(self): |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
253 raise TypeError() |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
55106
diff
changeset
|
254 var = NotHashable() |
|
59559
1ee2452ce942
sqlite3: Fix a segfault on calling a connection with something else than a
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59362
diff
changeset
|
255 self.assertRaises(TypeError, self.con.create_function, var) |
|
1ee2452ce942
sqlite3: Fix a segfault on calling a connection with something else than a
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59362
diff
changeset
|
256 self.assertRaises(TypeError, self.con.create_aggregate, var) |
|
1ee2452ce942
sqlite3: Fix a segfault on calling a connection with something else than a
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59362
diff
changeset
|
257 self.assertRaises(TypeError, self.con.set_authorizer, var) |
|
1ee2452ce942
sqlite3: Fix a segfault on calling a connection with something else than a
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59362
diff
changeset
|
258 self.assertRaises(TypeError, self.con.set_progress_handler, var) |
|
1ee2452ce942
sqlite3: Fix a segfault on calling a connection with something else than a
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59362
diff
changeset
|
259 |
|
59821
581263af5820
Merged revisions 78898 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47991
diff
changeset
|
260 def CheckConnectionCall(self): |
|
581263af5820
Merged revisions 78898 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47991
diff
changeset
|
261 """ |
|
581263af5820
Merged revisions 78898 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47991
diff
changeset
|
262 Call a connection with a non-string SQL request: check error handling |
|
581263af5820
Merged revisions 78898 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47991
diff
changeset
|
263 of the statement constructor. |
|
581263af5820
Merged revisions 78898 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47991
diff
changeset
|
264 """ |
|
581263af5820
Merged revisions 78898 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
47991
diff
changeset
|
265 self.assertRaises(sqlite.Warning, self.con, 1) |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
40625
diff
changeset
|
266 |
|
74811
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
267 def CheckRecursiveCursorUse(self): |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
268 """ |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
269 http://bugs.python.org/issue10811 |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
270 |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
271 Recursively using a cursor, such as when reusing it from a generator led to segfaults. |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
272 Now we catch recursive cursor usage and raise a ProgrammingError. |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
273 """ |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
274 con = sqlite.connect(":memory:") |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
275 |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
276 cur = con.cursor() |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
277 cur.execute("create table a (bar)") |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
278 cur.execute("create table b (baz)") |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
279 |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
280 def foo(): |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
281 cur.execute("insert into a (bar) values (?)", (1,)) |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
282 yield 1 |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
283 |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
284 with self.assertRaises(sqlite.ProgrammingError): |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
285 cur.executemany("insert into b (baz) values (?)", |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
286 ((i,) for i in foo())) |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
287 |
|
631e99961c5f
Issue #10811: Fix recursive usage of cursors. Instead of crashing, raise a ProgrammingError now.
Petri Lehtinen <petri@digip.org>
parents:
68256
diff
changeset
|
288 |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
289 def suite(): |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
290 regression_suite = unittest.makeSuite(RegressionTests, "Check") |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
291 return unittest.TestSuite((regression_suite,)) |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
292 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
293 def test(): |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
294 runner = unittest.TextTestRunner() |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
295 runner.run(suite()) |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
296 |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
297 if __name__ == "__main__": |
|
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
298 test() |
