Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1 | #-*- 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 | |
| 24 | import unittest |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 25 | import sqlite3 as sqlite |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 26 | |
| 27 | class 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 Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 39 | 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 Rossum | 805365e | 2007-05-07 22:24:25 +0000 | [diff] [blame] | 54 | cursors = [con.cursor() for x in range(5)] |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 55 | cursors[0].execute("create table test(x)") |
| 56 | for i in range(10): |
Guido van Rossum | 805365e | 2007-05-07 22:24:25 +0000 | [diff] [blame] | 57 | cursors[0].executemany("insert into test(x) values (?)", [(x,) for x in range(10)]) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 58 | |
| 59 | for i in range(5): |
| 60 | cursors[i].execute(" " * i + "select x from test") |
| 61 | |
| 62 | con.rollback() |
| 63 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 64 | 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 Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 72 | 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 Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 82 | def suite(): |
| 83 | regression_suite = unittest.makeSuite(RegressionTests, "Check") |
| 84 | return unittest.TestSuite((regression_suite,)) |
| 85 | |
| 86 | def test(): |
| 87 | runner = unittest.TextTestRunner() |
| 88 | runner.run(suite()) |
| 89 | |
| 90 | if __name__ == "__main__": |
| 91 | test() |