annotate Lib/sqlite3/test/dbapi.py @ 65035:87f4b32905df 2.7

Cosmetic fix to use print function.
author Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
date Fri, 01 Oct 2010 10:48:47 +0000
parents 3a0484200034
children 614c84670c63
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
1 #-*- coding: ISO-8859-1 -*-
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
2 # pysqlite2/test/dbapi.py: tests for DB-API compliance
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
3 #
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
4 # Copyright (C) 2004-2010 Gerhard Häring <gh@ghaering.de>
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
5 #
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
6 # This file is part of pysqlite.
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
7 #
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
8 # This software is provided 'as-is', without any express or implied
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
9 # warranty. In no event will the authors be held liable for any damages
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
10 # arising from the use of this software.
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
11 #
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
12 # Permission is granted to anyone to use this software for any purpose,
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
13 # including commercial applications, and to alter it and redistribute it
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
14 # freely, subject to the following restrictions:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
15 #
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
16 # 1. The origin of this software must not be misrepresented; you must not
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
17 # claim that you wrote the original software. If you use this software
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
18 # in a product, an acknowledgment in the product documentation would be
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
19 # appreciated but is not required.
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
20 # 2. Altered source versions must be plainly marked as such, and must not be
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
21 # misrepresented as being the original software.
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
22 # 3. This notice may not be removed or altered from any source distribution.
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
23
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
24 import unittest
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
25 import sys
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
26 import sqlite3 as sqlite
61046
3a0484200034 Issue #7449, last part (11): fix many tests if thread support is disabled
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59362
diff changeset
27 try:
3a0484200034 Issue #7449, last part (11): fix many tests if thread support is disabled
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59362
diff changeset
28 import threading
3a0484200034 Issue #7449, last part (11): fix many tests if thread support is disabled
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59362
diff changeset
29 except ImportError:
3a0484200034 Issue #7449, last part (11): fix many tests if thread support is disabled
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59362
diff changeset
30 threading = None
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
31
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
32 class ModuleTests(unittest.TestCase):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
33 def CheckAPILevel(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
34 self.assertEqual(sqlite.apilevel, "2.0",
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
35 "apilevel is %s, should be 2.0" % sqlite.apilevel)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
36
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
37 def CheckThreadSafety(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
38 self.assertEqual(sqlite.threadsafety, 1,
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
39 "threadsafety is %d, should be 1" % sqlite.threadsafety)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
40
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
41 def CheckParamStyle(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
42 self.assertEqual(sqlite.paramstyle, "qmark",
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
43 "paramstyle is '%s', should be 'qmark'" %
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
44 sqlite.paramstyle)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
45
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
46 def CheckWarning(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
47 self.assert_(issubclass(sqlite.Warning, StandardError),
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
48 "Warning is not a subclass of StandardError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
49
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
50 def CheckError(self):
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
51 self.assertTrue(issubclass(sqlite.Error, StandardError),
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
52 "Error is not a subclass of StandardError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
53
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
54 def CheckInterfaceError(self):
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
55 self.assertTrue(issubclass(sqlite.InterfaceError, sqlite.Error),
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
56 "InterfaceError is not a subclass of Error")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
57
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
58 def CheckDatabaseError(self):
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
59 self.assertTrue(issubclass(sqlite.DatabaseError, sqlite.Error),
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
60 "DatabaseError is not a subclass of Error")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
61
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
62 def CheckDataError(self):
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
63 self.assertTrue(issubclass(sqlite.DataError, sqlite.DatabaseError),
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
64 "DataError is not a subclass of DatabaseError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
65
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
66 def CheckOperationalError(self):
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
67 self.assertTrue(issubclass(sqlite.OperationalError, sqlite.DatabaseError),
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
68 "OperationalError is not a subclass of DatabaseError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
69
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
70 def CheckIntegrityError(self):
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
71 self.assertTrue(issubclass(sqlite.IntegrityError, sqlite.DatabaseError),
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
72 "IntegrityError is not a subclass of DatabaseError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
73
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
74 def CheckInternalError(self):
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
75 self.assertTrue(issubclass(sqlite.InternalError, sqlite.DatabaseError),
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
76 "InternalError is not a subclass of DatabaseError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
77
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
78 def CheckProgrammingError(self):
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
79 self.assertTrue(issubclass(sqlite.ProgrammingError, sqlite.DatabaseError),
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
80 "ProgrammingError is not a subclass of DatabaseError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
81
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
82 def CheckNotSupportedError(self):
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
83 self.assertTrue(issubclass(sqlite.NotSupportedError,
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
84 sqlite.DatabaseError),
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
85 "NotSupportedError is not a subclass of DatabaseError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
86
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
87 class ConnectionTests(unittest.TestCase):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
88 def setUp(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
89 self.cx = sqlite.connect(":memory:")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
90 cu = self.cx.cursor()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
91 cu.execute("create table test(id integer primary key, name text)")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
92 cu.execute("insert into test(name) values (?)", ("foo",))
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
93
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
94 def tearDown(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
95 self.cx.close()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
96
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
97 def CheckCommit(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
98 self.cx.commit()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
99
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
100 def CheckCommitAfterNoChanges(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
101 """
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
102 A commit should also work when no changes were made to the database.
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
103 """
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
104 self.cx.commit()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
105 self.cx.commit()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
106
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
107 def CheckRollback(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
108 self.cx.rollback()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
109
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
110 def CheckRollbackAfterNoChanges(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
111 """
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
112 A rollback should also work when no changes were made to the database.
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
113 """
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
114 self.cx.rollback()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
115 self.cx.rollback()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
116
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
117 def CheckCursor(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
118 cu = self.cx.cursor()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
119
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
120 def CheckFailedOpen(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
121 YOU_CANNOT_OPEN_THIS = "/foo/bar/bla/23534/mydb.db"
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
122 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
123 con = sqlite.connect(YOU_CANNOT_OPEN_THIS)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
124 except sqlite.OperationalError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
125 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
126 self.fail("should have raised an OperationalError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
127
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
128 def CheckClose(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
129 self.cx.close()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
130
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
131 def CheckExceptions(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
132 # Optional DB-API extension.
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
133 self.assertEqual(self.cx.Warning, sqlite.Warning)
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
134 self.assertEqual(self.cx.Error, sqlite.Error)
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
135 self.assertEqual(self.cx.InterfaceError, sqlite.InterfaceError)
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
136 self.assertEqual(self.cx.DatabaseError, sqlite.DatabaseError)
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
137 self.assertEqual(self.cx.DataError, sqlite.DataError)
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
138 self.assertEqual(self.cx.OperationalError, sqlite.OperationalError)
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
139 self.assertEqual(self.cx.IntegrityError, sqlite.IntegrityError)
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
140 self.assertEqual(self.cx.InternalError, sqlite.InternalError)
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
141 self.assertEqual(self.cx.ProgrammingError, sqlite.ProgrammingError)
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
142 self.assertEqual(self.cx.NotSupportedError, sqlite.NotSupportedError)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
143
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
144 class CursorTests(unittest.TestCase):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
145 def setUp(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
146 self.cx = sqlite.connect(":memory:")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
147 self.cu = self.cx.cursor()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
148 self.cu.execute("create table test(id integer primary key, name text, income number)")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
149 self.cu.execute("insert into test(name) values (?)", ("foo",))
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
150
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
151 def tearDown(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
152 self.cu.close()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
153 self.cx.close()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
154
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
155 def CheckExecuteNoArgs(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
156 self.cu.execute("delete from test")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
157
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
158 def CheckExecuteIllegalSql(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
159 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
160 self.cu.execute("select asdf")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
161 self.fail("should have raised an OperationalError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
162 except sqlite.OperationalError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
163 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
164 except:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
165 self.fail("raised wrong exception")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
166
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
167 def CheckExecuteTooMuchSql(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
168 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
169 self.cu.execute("select 5+4; select 4+5")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
170 self.fail("should have raised a Warning")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
171 except sqlite.Warning:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
172 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
173 except:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
174 self.fail("raised wrong exception")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
175
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
176 def CheckExecuteTooMuchSql2(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
177 self.cu.execute("select 5+4; -- foo bar")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
178
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
179 def CheckExecuteTooMuchSql3(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
180 self.cu.execute("""
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
181 select 5+4;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
182
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
183 /*
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
184 foo
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
185 */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
186 """)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
187
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
188 def CheckExecuteWrongSqlArg(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
189 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
190 self.cu.execute(42)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
191 self.fail("should have raised a ValueError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
192 except ValueError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
193 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
194 except:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
195 self.fail("raised wrong exception.")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
196
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
197 def CheckExecuteArgInt(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
198 self.cu.execute("insert into test(id) values (?)", (42,))
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
199
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
200 def CheckExecuteArgFloat(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
201 self.cu.execute("insert into test(income) values (?)", (2500.32,))
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
202
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
203 def CheckExecuteArgString(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
204 self.cu.execute("insert into test(name) values (?)", ("Hugo",))
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
205
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
206 def CheckExecuteWrongNoOfArgs1(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
207 # too many parameters
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
208 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
209 self.cu.execute("insert into test(id) values (?)", (17, "Egon"))
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
210 self.fail("should have raised ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
211 except sqlite.ProgrammingError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
212 pass
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
213
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
214 def CheckExecuteWrongNoOfArgs2(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
215 # too little parameters
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
216 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
217 self.cu.execute("insert into test(id) values (?)")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
218 self.fail("should have raised ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
219 except sqlite.ProgrammingError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
220 pass
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
221
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
222 def CheckExecuteWrongNoOfArgs3(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
223 # no parameters, parameters are needed
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
224 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
225 self.cu.execute("insert into test(id) values (?)")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
226 self.fail("should have raised ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
227 except sqlite.ProgrammingError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
228 pass
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
229
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
230 def CheckExecuteParamList(self):
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
231 self.cu.execute("insert into test(name) values ('foo')")
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
232 self.cu.execute("select name from test where name=?", ["foo"])
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
233 row = self.cu.fetchone()
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
234 self.assertEqual(row[0], "foo")
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
235
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
236 def CheckExecuteParamSequence(self):
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
237 class L(object):
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
238 def __len__(self):
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
239 return 1
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
240 def __getitem__(self, x):
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
241 assert x == 0
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
242 return "foo"
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
243
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
244 self.cu.execute("insert into test(name) values ('foo')")
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
245 self.cu.execute("select name from test where name=?", L())
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
246 row = self.cu.fetchone()
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
247 self.assertEqual(row[0], "foo")
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
248
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
249 def CheckExecuteDictMapping(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
250 self.cu.execute("insert into test(name) values ('foo')")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
251 self.cu.execute("select name from test where name=:name", {"name": "foo"})
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
252 row = self.cu.fetchone()
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
253 self.assertEqual(row[0], "foo")
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
254
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
255 def CheckExecuteDictMapping_Mapping(self):
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
256 # Test only works with Python 2.5 or later
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
257 if sys.version_info < (2, 5, 0):
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
258 return
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
259
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
260 class D(dict):
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
261 def __missing__(self, key):
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
262 return "foo"
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
263
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
264 self.cu.execute("insert into test(name) values ('foo')")
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
265 self.cu.execute("select name from test where name=:name", D())
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
266 row = self.cu.fetchone()
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
267 self.assertEqual(row[0], "foo")
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
268
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
269 def CheckExecuteDictMappingTooLittleArgs(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
270 self.cu.execute("insert into test(name) values ('foo')")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
271 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
272 self.cu.execute("select name from test where name=:name and id=:id", {"name": "foo"})
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
273 self.fail("should have raised ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
274 except sqlite.ProgrammingError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
275 pass
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
276
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
277 def CheckExecuteDictMappingNoArgs(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
278 self.cu.execute("insert into test(name) values ('foo')")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
279 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
280 self.cu.execute("select name from test where name=:name")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
281 self.fail("should have raised ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
282 except sqlite.ProgrammingError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
283 pass
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
284
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
285 def CheckExecuteDictMappingUnnamed(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
286 self.cu.execute("insert into test(name) values ('foo')")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
287 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
288 self.cu.execute("select name from test where name=?", {"name": "foo"})
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
289 self.fail("should have raised ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
290 except sqlite.ProgrammingError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
291 pass
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
292
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
293 def CheckClose(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
294 self.cu.close()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
295
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
296 def CheckRowcountExecute(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
297 self.cu.execute("delete from test")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
298 self.cu.execute("insert into test(name) values ('foo')")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
299 self.cu.execute("insert into test(name) values ('foo')")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
300 self.cu.execute("update test set name='bar'")
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
301 self.assertEqual(self.cu.rowcount, 2)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
302
47409
0156c336e6b3 Fixed rowcount for SELECT statements. They're -1 now (again), for better DB-API 2.0 compliance.
Gerhard Häring <gh@ghaering.de>
parents: 45580
diff changeset
303 def CheckRowcountSelect(self):
0156c336e6b3 Fixed rowcount for SELECT statements. They're -1 now (again), for better DB-API 2.0 compliance.
Gerhard Häring <gh@ghaering.de>
parents: 45580
diff changeset
304 """
0156c336e6b3 Fixed rowcount for SELECT statements. They're -1 now (again), for better DB-API 2.0 compliance.
Gerhard Häring <gh@ghaering.de>
parents: 45580
diff changeset
305 pysqlite does not know the rowcount of SELECT statements, because we
0156c336e6b3 Fixed rowcount for SELECT statements. They're -1 now (again), for better DB-API 2.0 compliance.
Gerhard Häring <gh@ghaering.de>
parents: 45580
diff changeset
306 don't fetch all rows after executing the select statement. The rowcount
0156c336e6b3 Fixed rowcount for SELECT statements. They're -1 now (again), for better DB-API 2.0 compliance.
Gerhard Häring <gh@ghaering.de>
parents: 45580
diff changeset
307 has thus to be -1.
0156c336e6b3 Fixed rowcount for SELECT statements. They're -1 now (again), for better DB-API 2.0 compliance.
Gerhard Häring <gh@ghaering.de>
parents: 45580
diff changeset
308 """
0156c336e6b3 Fixed rowcount for SELECT statements. They're -1 now (again), for better DB-API 2.0 compliance.
Gerhard Häring <gh@ghaering.de>
parents: 45580
diff changeset
309 self.cu.execute("select 5 union select 6")
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
310 self.assertEqual(self.cu.rowcount, -1)
47409
0156c336e6b3 Fixed rowcount for SELECT statements. They're -1 now (again), for better DB-API 2.0 compliance.
Gerhard Häring <gh@ghaering.de>
parents: 45580
diff changeset
311
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
312 def CheckRowcountExecutemany(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
313 self.cu.execute("delete from test")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
314 self.cu.executemany("insert into test(name) values (?)", [(1,), (2,), (3,)])
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
315 self.assertEqual(self.cu.rowcount, 3)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
316
37458
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37362
diff changeset
317 def CheckTotalChanges(self):
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37362
diff changeset
318 self.cu.execute("insert into test(name) values ('foo')")
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37362
diff changeset
319 self.cu.execute("insert into test(name) values ('foo')")
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37362
diff changeset
320 if self.cx.total_changes < 2:
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37362
diff changeset
321 self.fail("total changes reported wrong value")
d27058c409df Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents: 37362
diff changeset
322
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
323 # Checks for executemany:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
324 # Sequences are required by the DB-API, iterators
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
325 # enhancements in pysqlite.
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
326
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
327 def CheckExecuteManySequence(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
328 self.cu.executemany("insert into test(income) values (?)", [(x,) for x in range(100, 110)])
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
329
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
330 def CheckExecuteManyIterator(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
331 class MyIter:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
332 def __init__(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
333 self.value = 5
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
334
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
335 def next(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
336 if self.value == 10:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
337 raise StopIteration
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
338 else:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
339 self.value += 1
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
340 return (self.value,)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
341
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
342 self.cu.executemany("insert into test(income) values (?)", MyIter())
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
343
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
344 def CheckExecuteManyGenerator(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
345 def mygen():
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
346 for i in range(5):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
347 yield (i,)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
348
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
349 self.cu.executemany("insert into test(income) values (?)", mygen())
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
350
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
351 def CheckExecuteManyWrongSqlArg(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
352 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
353 self.cu.executemany(42, [(3,)])
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
354 self.fail("should have raised a ValueError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
355 except ValueError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
356 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
357 except:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
358 self.fail("raised wrong exception.")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
359
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
360 def CheckExecuteManySelect(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
361 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
362 self.cu.executemany("select ?", [(3,)])
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
363 self.fail("should have raised a ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
364 except sqlite.ProgrammingError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
365 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
366 except:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
367 self.fail("raised wrong exception.")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
368
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
369 def CheckExecuteManyNotIterable(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
370 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
371 self.cu.executemany("insert into test(income) values (?)", 42)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
372 self.fail("should have raised a TypeError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
373 except TypeError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
374 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
375 except Exception, e:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
376 print "raised", e.__class__
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
377 self.fail("raised wrong exception.")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
378
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
379 def CheckFetchIter(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
380 # Optional DB-API extension.
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
381 self.cu.execute("delete from test")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
382 self.cu.execute("insert into test(id) values (?)", (5,))
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
383 self.cu.execute("insert into test(id) values (?)", (6,))
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
384 self.cu.execute("select id from test order by id")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
385 lst = []
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
386 for row in self.cu:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
387 lst.append(row[0])
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
388 self.assertEqual(lst[0], 5)
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
389 self.assertEqual(lst[1], 6)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
390
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
391 def CheckFetchone(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
392 self.cu.execute("select name from test")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
393 row = self.cu.fetchone()
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
394 self.assertEqual(row[0], "foo")
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
395 row = self.cu.fetchone()
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
396 self.assertEqual(row, None)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
397
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
398 def CheckFetchoneNoStatement(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
399 cur = self.cx.cursor()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
400 row = cur.fetchone()
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
401 self.assertEqual(row, None)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
402
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
403 def CheckArraySize(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
404 # must default ot 1
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
405 self.assertEqual(self.cu.arraysize, 1)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
406
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
407 # now set to 2
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
408 self.cu.arraysize = 2
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
409
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
410 # now make the query return 3 rows
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
411 self.cu.execute("delete from test")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
412 self.cu.execute("insert into test(name) values ('A')")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
413 self.cu.execute("insert into test(name) values ('B')")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
414 self.cu.execute("insert into test(name) values ('C')")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
415 self.cu.execute("select name from test")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
416 res = self.cu.fetchmany()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
417
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
418 self.assertEqual(len(res), 2)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
419
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
420 def CheckFetchmany(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
421 self.cu.execute("select name from test")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
422 res = self.cu.fetchmany(100)
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
423 self.assertEqual(len(res), 1)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
424 res = self.cu.fetchmany(100)
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
425 self.assertEqual(res, [])
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
426
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
427 def CheckFetchmanyKwArg(self):
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
428 """Checks if fetchmany works with keyword arguments"""
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
429 self.cu.execute("select name from test")
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
430 res = self.cu.fetchmany(size=100)
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
431 self.assertEqual(len(res), 1)
45580
b7ee9074ca0e Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents: 37458
diff changeset
432
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
433 def CheckFetchall(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
434 self.cu.execute("select name from test")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
435 res = self.cu.fetchall()
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
436 self.assertEqual(len(res), 1)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
437 res = self.cu.fetchall()
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
438 self.assertEqual(res, [])
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
439
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
440 def CheckSetinputsizes(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
441 self.cu.setinputsizes([3, 4, 5])
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
442
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
443 def CheckSetoutputsize(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
444 self.cu.setoutputsize(5, 0)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
445
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
446 def CheckSetoutputsizeNoColumn(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
447 self.cu.setoutputsize(42)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
448
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
449 def CheckCursorConnection(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
450 # Optional DB-API extension.
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
451 self.assertEqual(self.cu.connection, self.cx)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
452
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
453 def CheckWrongCursorCallable(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
454 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
455 def f(): pass
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
456 cur = self.cx.cursor(f)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
457 self.fail("should have raised a TypeError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
458 except TypeError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
459 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
460 self.fail("should have raised a ValueError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
461
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
462 def CheckCursorWrongClass(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
463 class Foo: pass
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
464 foo = Foo()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
465 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
466 cur = sqlite.Cursor(foo)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
467 self.fail("should have raised a ValueError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
468 except TypeError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
469 pass
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
470
61046
3a0484200034 Issue #7449, last part (11): fix many tests if thread support is disabled
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59362
diff changeset
471 @unittest.skipUnless(threading, 'This test requires threading.')
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
472 class ThreadTests(unittest.TestCase):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
473 def setUp(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
474 self.con = sqlite.connect(":memory:")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
475 self.cur = self.con.cursor()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
476 self.cur.execute("create table test(id integer primary key, name text, bin binary, ratio number, ts timestamp)")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
477
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
478 def tearDown(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
479 self.cur.close()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
480 self.con.close()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
481
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
482 def CheckConCursor(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
483 def run(con, errors):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
484 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
485 cur = con.cursor()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
486 errors.append("did not raise ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
487 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
488 except sqlite.ProgrammingError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
489 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
490 except:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
491 errors.append("raised wrong exception")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
492
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
493 errors = []
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
494 t = threading.Thread(target=run, kwargs={"con": self.con, "errors": errors})
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
495 t.start()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
496 t.join()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
497 if len(errors) > 0:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
498 self.fail("\n".join(errors))
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
499
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
500 def CheckConCommit(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
501 def run(con, errors):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
502 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
503 con.commit()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
504 errors.append("did not raise ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
505 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
506 except sqlite.ProgrammingError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
507 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
508 except:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
509 errors.append("raised wrong exception")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
510
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
511 errors = []
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
512 t = threading.Thread(target=run, kwargs={"con": self.con, "errors": errors})
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
513 t.start()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
514 t.join()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
515 if len(errors) > 0:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
516 self.fail("\n".join(errors))
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
517
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
518 def CheckConRollback(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
519 def run(con, errors):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
520 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
521 con.rollback()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
522 errors.append("did not raise ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
523 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
524 except sqlite.ProgrammingError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
525 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
526 except:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
527 errors.append("raised wrong exception")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
528
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
529 errors = []
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
530 t = threading.Thread(target=run, kwargs={"con": self.con, "errors": errors})
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
531 t.start()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
532 t.join()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
533 if len(errors) > 0:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
534 self.fail("\n".join(errors))
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
535
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
536 def CheckConClose(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
537 def run(con, errors):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
538 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
539 con.close()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
540 errors.append("did not raise ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
541 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
542 except sqlite.ProgrammingError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
543 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
544 except:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
545 errors.append("raised wrong exception")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
546
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
547 errors = []
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
548 t = threading.Thread(target=run, kwargs={"con": self.con, "errors": errors})
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
549 t.start()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
550 t.join()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
551 if len(errors) > 0:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
552 self.fail("\n".join(errors))
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
553
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
554 def CheckCurImplicitBegin(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
555 def run(cur, errors):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
556 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
557 cur.execute("insert into test(name) values ('a')")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
558 errors.append("did not raise ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
559 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
560 except sqlite.ProgrammingError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
561 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
562 except:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
563 errors.append("raised wrong exception")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
564
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
565 errors = []
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
566 t = threading.Thread(target=run, kwargs={"cur": self.cur, "errors": errors})
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
567 t.start()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
568 t.join()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
569 if len(errors) > 0:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
570 self.fail("\n".join(errors))
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
571
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
572 def CheckCurClose(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
573 def run(cur, errors):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
574 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
575 cur.close()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
576 errors.append("did not raise ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
577 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
578 except sqlite.ProgrammingError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
579 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
580 except:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
581 errors.append("raised wrong exception")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
582
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
583 errors = []
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
584 t = threading.Thread(target=run, kwargs={"cur": self.cur, "errors": errors})
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
585 t.start()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
586 t.join()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
587 if len(errors) > 0:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
588 self.fail("\n".join(errors))
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
589
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
590 def CheckCurExecute(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
591 def run(cur, errors):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
592 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
593 cur.execute("select name from test")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
594 errors.append("did not raise ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
595 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
596 except sqlite.ProgrammingError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
597 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
598 except:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
599 errors.append("raised wrong exception")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
600
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
601 errors = []
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
602 self.cur.execute("insert into test(name) values ('a')")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
603 t = threading.Thread(target=run, kwargs={"cur": self.cur, "errors": errors})
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
604 t.start()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
605 t.join()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
606 if len(errors) > 0:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
607 self.fail("\n".join(errors))
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
608
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
609 def CheckCurIterNext(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
610 def run(cur, errors):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
611 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
612 row = cur.fetchone()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
613 errors.append("did not raise ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
614 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
615 except sqlite.ProgrammingError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
616 return
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
617 except:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
618 errors.append("raised wrong exception")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
619
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
620 errors = []
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
621 self.cur.execute("insert into test(name) values ('a')")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
622 self.cur.execute("select name from test")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
623 t = threading.Thread(target=run, kwargs={"cur": self.cur, "errors": errors})
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
624 t.start()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
625 t.join()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
626 if len(errors) > 0:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
627 self.fail("\n".join(errors))
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
628
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
629 class ConstructorTests(unittest.TestCase):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
630 def CheckDate(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
631 d = sqlite.Date(2004, 10, 28)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
632
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
633 def CheckTime(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
634 t = sqlite.Time(12, 39, 35)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
635
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
636 def CheckTimestamp(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
637 ts = sqlite.Timestamp(2004, 10, 28, 12, 39, 35)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
638
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
639 def CheckDateFromTicks(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
640 d = sqlite.DateFromTicks(42)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
641
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
642 def CheckTimeFromTicks(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
643 t = sqlite.TimeFromTicks(42)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
644
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
645 def CheckTimestampFromTicks(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
646 ts = sqlite.TimestampFromTicks(42)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
647
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
648 def CheckBinary(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
649 b = sqlite.Binary(chr(0) + "'")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
650
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
651 class ExtensionTests(unittest.TestCase):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
652 def CheckScriptStringSql(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
653 con = sqlite.connect(":memory:")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
654 cur = con.cursor()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
655 cur.executescript("""
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
656 -- bla bla
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
657 /* a stupid comment */
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
658 create table a(i);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
659 insert into a(i) values (5);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
660 """)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
661 cur.execute("select i from a")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
662 res = cur.fetchone()[0]
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
663 self.assertEqual(res, 5)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
664
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
665 def CheckScriptStringUnicode(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
666 con = sqlite.connect(":memory:")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
667 cur = con.cursor()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
668 cur.executescript(u"""
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
669 create table a(i);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
670 insert into a(i) values (5);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
671 select i from a;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
672 delete from a;
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
673 insert into a(i) values (6);
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
674 """)
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
675 cur.execute("select i from a")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
676 res = cur.fetchone()[0]
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
677 self.assertEqual(res, 6)
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
678
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
679 def CheckScriptSyntaxError(self):
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
680 con = sqlite.connect(":memory:")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
681 cur = con.cursor()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
682 raised = False
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
683 try:
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
684 cur.executescript("create table test(x); asdf; create table test2(x)")
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
685 except sqlite.OperationalError:
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
686 raised = True
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
687 self.assertEqual(raised, True, "should have raised an exception")
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
688
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
689 def CheckScriptErrorNormal(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
690 con = sqlite.connect(":memory:")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
691 cur = con.cursor()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
692 raised = False
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
693 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
694 cur.executescript("create table test(sadfsadfdsa); select foo from hurz;")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
695 except sqlite.OperationalError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
696 raised = True
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
697 self.assertEqual(raised, True, "should have raised an exception")
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
698
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
699 def CheckConnectionExecute(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
700 con = sqlite.connect(":memory:")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
701 result = con.execute("select 5").fetchone()[0]
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
702 self.assertEqual(result, 5, "Basic test of Connection.execute")
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
703
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
704 def CheckConnectionExecutemany(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
705 con = sqlite.connect(":memory:")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
706 con.execute("create table test(foo)")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
707 con.executemany("insert into test(foo) values (?)", [(3,), (4,)])
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
708 result = con.execute("select foo from test order by foo").fetchall()
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
709 self.assertEqual(result[0][0], 3, "Basic test of Connection.executemany")
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
710 self.assertEqual(result[1][0], 4, "Basic test of Connection.executemany")
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
711
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
712 def CheckConnectionExecutescript(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
713 con = sqlite.connect(":memory:")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
714 con.executescript("create table test(foo); insert into test(foo) values (5);")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
715 result = con.execute("select foo from test").fetchone()[0]
55106
7ff1405ccb64 Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents: 47409
diff changeset
716 self.assertEqual(result, 5, "Basic test of Connection.executescript")
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
717
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
718 class ClosedConTests(unittest.TestCase):
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
719 def setUp(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
720 pass
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
721
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
722 def tearDown(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
723 pass
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
724
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
725 def CheckClosedConCursor(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
726 con = sqlite.connect(":memory:")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
727 con.close()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
728 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
729 cur = con.cursor()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
730 self.fail("Should have raised a ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
731 except sqlite.ProgrammingError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
732 pass
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
733 except:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
734 self.fail("Should have raised a ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
735
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
736 def CheckClosedConCommit(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
737 con = sqlite.connect(":memory:")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
738 con.close()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
739 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
740 con.commit()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
741 self.fail("Should have raised a ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
742 except sqlite.ProgrammingError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
743 pass
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
744 except:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
745 self.fail("Should have raised a ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
746
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
747 def CheckClosedConRollback(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
748 con = sqlite.connect(":memory:")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
749 con.close()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
750 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
751 con.rollback()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
752 self.fail("Should have raised a ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
753 except sqlite.ProgrammingError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
754 pass
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
755 except:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
756 self.fail("Should have raised a ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
757
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
758 def CheckClosedCurExecute(self):
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
759 con = sqlite.connect(":memory:")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
760 cur = con.cursor()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
761 con.close()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
762 try:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
763 cur.execute("select 4")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
764 self.fail("Should have raised a ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
765 except sqlite.ProgrammingError:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
766 pass
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
767 except:
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
768 self.fail("Should have raised a ProgrammingError")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
769
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
770 def CheckClosedCreateFunction(self):
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
771 con = sqlite.connect(":memory:")
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
772 con.close()
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
773 def f(x): return 17
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
774 try:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
775 con.create_function("foo", 1, f)
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
776 self.fail("Should have raised a ProgrammingError")
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
777 except sqlite.ProgrammingError:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
778 pass
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
779 except:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
780 self.fail("Should have raised a ProgrammingError")
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
781
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
782 def CheckClosedCreateAggregate(self):
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
783 con = sqlite.connect(":memory:")
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
784 con.close()
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
785 class Agg:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
786 def __init__(self):
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
787 pass
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
788 def step(self, x):
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
789 pass
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
790 def finalize(self):
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
791 return 17
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
792 try:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
793 con.create_aggregate("foo", 1, Agg)
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
794 self.fail("Should have raised a ProgrammingError")
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
795 except sqlite.ProgrammingError:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
796 pass
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
797 except:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
798 self.fail("Should have raised a ProgrammingError")
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
799
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
800 def CheckClosedSetAuthorizer(self):
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
801 con = sqlite.connect(":memory:")
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
802 con.close()
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
803 def authorizer(*args):
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
804 return sqlite.DENY
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
805 try:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
806 con.set_authorizer(authorizer)
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
807 self.fail("Should have raised a ProgrammingError")
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
808 except sqlite.ProgrammingError:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
809 pass
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
810 except:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
811 self.fail("Should have raised a ProgrammingError")
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
812
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
813 def CheckClosedSetProgressCallback(self):
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
814 con = sqlite.connect(":memory:")
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
815 con.close()
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
816 def progress(): pass
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
817 try:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
818 con.set_progress_handler(progress, 100)
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
819 self.fail("Should have raised a ProgrammingError")
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
820 except sqlite.ProgrammingError:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
821 pass
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
822 except:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
823 self.fail("Should have raised a ProgrammingError")
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
824
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
825 def CheckClosedCall(self):
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
826 con = sqlite.connect(":memory:")
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
827 con.close()
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
828 try:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
829 con()
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
830 self.fail("Should have raised a ProgrammingError")
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
831 except sqlite.ProgrammingError:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
832 pass
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
833 except:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
834 self.fail("Should have raised a ProgrammingError")
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
835
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
836 class ClosedCurTests(unittest.TestCase):
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
837 def setUp(self):
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
838 pass
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
839
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
840 def tearDown(self):
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
841 pass
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
842
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
843 def CheckClosed(self):
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
844 con = sqlite.connect(":memory:")
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
845 cur = con.cursor()
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
846 cur.close()
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
847
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
848 for method_name in ("execute", "executemany", "executescript", "fetchall", "fetchmany", "fetchone"):
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
849 if method_name in ("execute", "executescript"):
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
850 params = ("select 4 union select 5",)
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
851 elif method_name == "executemany":
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
852 params = ("insert into foo(bar) values (?)", [(3,), (4,)])
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
853 else:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
854 params = []
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
855
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
856 try:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
857 method = getattr(cur, method_name)
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
858
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
859 method(*params)
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
860 self.fail("Should have raised a ProgrammingError: method " + method_name)
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
861 except sqlite.ProgrammingError:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
862 pass
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
863 except:
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
864 self.fail("Should have raised a ProgrammingError: " + method_name)
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
865
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
866 def suite():
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
867 module_suite = unittest.makeSuite(ModuleTests, "Check")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
868 connection_suite = unittest.makeSuite(ConnectionTests, "Check")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
869 cursor_suite = unittest.makeSuite(CursorTests, "Check")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
870 thread_suite = unittest.makeSuite(ThreadTests, "Check")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
871 constructor_suite = unittest.makeSuite(ConstructorTests, "Check")
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
872 ext_suite = unittest.makeSuite(ExtensionTests, "Check")
59362
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
873 closed_con_suite = unittest.makeSuite(ClosedConTests, "Check")
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
874 closed_cur_suite = unittest.makeSuite(ClosedCurTests, "Check")
04d3ae52ff73 Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents: 55106
diff changeset
875 return unittest.TestSuite((module_suite, connection_suite, cursor_suite, thread_suite, constructor_suite, ext_suite, closed_con_suite, closed_cur_suite))
37362
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
876
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
877 def test():
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
878 runner = unittest.TextTestRunner()
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
879 runner.run(suite())
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
880
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
881 if __name__ == "__main__":
e546274d6503 merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff changeset
882 test()