annotate Lib/sqlite3/test/regression.py @ 57303:4aa4c19dfaed legacy-trunk

#1757126: fix typo with the cyrillic_asian alias
author Philip Jenvey <pjenvey@underboss.org>
date Tue, 17 Nov 2009 02:42:26 +0000
parents 7ff1405ccb64
children 04d3ae52ff73
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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")
38808
3e5fd2b70e5a Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents: 37938
diff changeset
72
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
73 def CheckStatementAvailable(self):
b9d4ced23506 Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents: 38808
diff changeset
74 # pysqlite up to 2.3.2 crashed on this, because the active statement handle was not checked
b9d4ced23506 Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents: 38808
diff changeset
75 # before trying to fetch data from it. close() destroys the active statement ...
b9d4ced23506 Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents: 38808
diff changeset
76 con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES)
b9d4ced23506 Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents: 38808
diff changeset
77 cur = con.cursor()
b9d4ced23506 Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents: 38808
diff changeset
78 cur.execute("select 4 union select 5")
b9d4ced23506 Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents: 38808
diff changeset
79 cur.close()
b9d4ced23506 Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents: 38808
diff changeset
80 cur.fetchone()
b9d4ced23506 Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents: 38808
diff changeset
81 cur.fetchone()
b9d4ced23506 Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents: 38808
diff changeset
82
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
83 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
84 # 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
85 # 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
86 # 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
87 # "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
88 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
89 cursors = []
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
90 # 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
91 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
92 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
93 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
94 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
95 con.close()
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
96
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
97 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
98 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
99 return
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
100 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
101 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
102 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
103 try:
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
104 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
105 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
106 pass
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
107 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
108 try:
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
109 con.commit()
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
110 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
111 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
112
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
113 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
114 """
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
115 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
116 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
117 """
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
118 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
119 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
120 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
121
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
122 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
123 """
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
124 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
125 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
126 """
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
127 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
128
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
129 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
130 """
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
131 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
132 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
133
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
134 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
135
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
136 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
137 """
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
138 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
139 con.close()
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
140
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
141 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
142 """
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
143 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
144 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
145 """
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
146 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
147 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
148 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
149 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
150 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
151 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
152 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
153 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
154 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
155
47991
091df4c08d99 #3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents: 45608
diff changeset
156 def CheckRegisterAdapter(self):
091df4c08d99 #3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents: 45608
diff changeset
157 """
091df4c08d99 #3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents: 45608
diff changeset
158 See issue 3312.
091df4c08d99 #3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents: 45608
diff changeset
159 """
091df4c08d99 #3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents: 45608
diff changeset
160 self.assertRaises(TypeError, sqlite.register_adapter, {}, None)
091df4c08d99 #3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents: 45608
diff changeset
161
091df4c08d99 #3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents: 45608
diff changeset
162 def CheckSetIsolationLevel(self):
091df4c08d99 #3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents: 45608
diff changeset
163 """
091df4c08d99 #3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents: 45608
diff changeset
164 See issue 3312.
091df4c08d99 #3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents: 45608
diff changeset
165 """
091df4c08d99 #3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents: 45608
diff changeset
166 con = sqlite.connect(":memory:")
091df4c08d99 #3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents: 45608
diff changeset
167 self.assertRaises(UnicodeEncodeError, setattr, con,
091df4c08d99 #3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents: 45608
diff changeset
168 "isolation_level", u"\xe9")
091df4c08d99 #3312: fix two sqlite3 crashes.
Georg Brandl <georg@python.org>
parents: 45608
diff changeset
169
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 40625
diff changeset
170
37458
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
171 def suite():
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
172 regression_suite = unittest.makeSuite(RegressionTests, "Check")
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
173 return unittest.TestSuite((regression_suite,))
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
174
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
175 def test():
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
176 runner = unittest.TextTestRunner()
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
177 runner.run(suite())
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
178
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
179 if __name__ == "__main__":
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
180 test()