python-2.5.2/win32/Lib/sqlite3/test/regression.py
changeset 0 ae805ac0140d
equal deleted inserted replaced
-1:000000000000 0:ae805ac0140d
       
     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
       
    25 import sqlite3 as sqlite
       
    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 
       
    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)
       
    54         cursors = [con.cursor() for x in xrange(5)]
       
    55         cursors[0].execute("create table test(x)")
       
    56         for i in range(10):
       
    57             cursors[0].executemany("insert into test(x) values (?)", [(x,) for x in xrange(10)])
       
    58 
       
    59         for i in range(5):
       
    60             cursors[i].execute(" " * i + "select x from test")
       
    61 
       
    62         con.rollback()
       
    63 
       
    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 
       
    72 def suite():
       
    73     regression_suite = unittest.makeSuite(RegressionTests, "Check")
       
    74     return unittest.TestSuite((regression_suite,))
       
    75 
       
    76 def test():
       
    77     runner = unittest.TextTestRunner()
       
    78     runner.run(suite())
       
    79 
       
    80 if __name__ == "__main__":
       
    81     test()