blob: df2a6fb96e7952de8f86e6e8e891284779d2359f [file] [log] [blame]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001#-*- coding: ISO-8859-1 -*-
2# pysqlite2/test/regression.py: pysqlite regression tests
3#
4# Copyright (C) 2006 Gerhard Häring <gh@ghaering.de>
5#
6# This file is part of pysqlite.
7#
8# This software is provided 'as-is', without any express or implied
9# warranty. In no event will the authors be held liable for any damages
10# arising from the use of this software.
11#
12# Permission is granted to anyone to use this software for any purpose,
13# including commercial applications, and to alter it and redistribute it
14# freely, subject to the following restrictions:
15#
16# 1. The origin of this software must not be misrepresented; you must not
17# claim that you wrote the original software. If you use this software
18# in a product, an acknowledgment in the product documentation would be
19# appreciated but is not required.
20# 2. Altered source versions must be plainly marked as such, and must not be
21# misrepresented as being the original software.
22# 3. This notice may not be removed or altered from any source distribution.
23
24import unittest
Thomas Wouters477c8d52006-05-27 19:21:47 +000025import sqlite3 as sqlite
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000026
27class RegressionTests(unittest.TestCase):
28 def setUp(self):
29 self.con = sqlite.connect(":memory:")
30
31 def tearDown(self):
32 self.con.close()
33
34 def CheckPragmaUserVersion(self):
35 # This used to crash pysqlite because this pragma command returns NULL for the column name
36 cur = self.con.cursor()
37 cur.execute("pragma user_version")
38
Thomas Wouters477c8d52006-05-27 19:21:47 +000039 def CheckPragmaSchemaVersion(self):
40 # This still crashed pysqlite <= 2.2.1
41 con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES)
42 try:
43 cur = self.con.cursor()
44 cur.execute("pragma schema_version")
45 finally:
46 cur.close()
47 con.close()
48
49 def CheckStatementReset(self):
50 # pysqlite 2.1.0 to 2.2.0 have the problem that not all statements are
51 # reset before a rollback, but only those that are still in the
52 # statement cache. The others are not accessible from the connection object.
53 con = sqlite.connect(":memory:", cached_statements=5)
Guido van Rossum805365e2007-05-07 22:24:25 +000054 cursors = [con.cursor() for x in range(5)]
Thomas Wouters477c8d52006-05-27 19:21:47 +000055 cursors[0].execute("create table test(x)")
56 for i in range(10):
Guido van Rossum805365e2007-05-07 22:24:25 +000057 cursors[0].executemany("insert into test(x) values (?)", [(x,) for x in range(10)])
Thomas Wouters477c8d52006-05-27 19:21:47 +000058
59 for i in range(5):
60 cursors[i].execute(" " * i + "select x from test")
61
62 con.rollback()
63
Thomas Wouters0e3f5912006-08-11 14:57:12 +000064 def CheckColumnNameWithSpaces(self):
65 cur = self.con.cursor()
66 cur.execute('select 1 as "foo bar [datetime]"')
67 self.failUnlessEqual(cur.description[0][0], "foo bar")
68
69 cur.execute('select 1 as "foo baz"')
70 self.failUnlessEqual(cur.description[0][0], "foo baz")
71
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +000072 def CheckStatementAvailable(self):
73 # pysqlite up to 2.3.2 crashed on this, because the active statement handle was not checked
74 # before trying to fetch data from it. close() destroys the active statement ...
75 con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES)
76 cur = con.cursor()
77 cur.execute("select 4 union select 5")
78 cur.close()
79 cur.fetchone()
80 cur.fetchone()
81
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000082def suite():
83 regression_suite = unittest.makeSuite(RegressionTests, "Check")
84 return unittest.TestSuite((regression_suite,))
85
86def test():
87 runner = unittest.TextTestRunner()
88 runner.run(suite())
89
90if __name__ == "__main__":
91 test()