Mercurial > cpython-lru_cache-weakref
annotate Lib/sqlite3/test/types.py @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | b36cb4602e21 |
| children | 5295ed192ffd |
| 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/types.py: tests for type conversion and detection |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
3 # |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44408
diff
changeset
|
4 # Copyright (C) 2005-2007 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 |
|
55920
39be3ef82d23
#6026 - fix tests that failed without zlib
Ezio Melotti <ezio.melotti@gmail.com>
parents:
55106
diff
changeset
|
24 import datetime |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
25 import unittest |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
26 import sqlite3 as sqlite |
|
55920
39be3ef82d23
#6026 - fix tests that failed without zlib
Ezio Melotti <ezio.melotti@gmail.com>
parents:
55106
diff
changeset
|
27 try: |
|
39be3ef82d23
#6026 - fix tests that failed without zlib
Ezio Melotti <ezio.melotti@gmail.com>
parents:
55106
diff
changeset
|
28 import zlib |
|
39be3ef82d23
#6026 - fix tests that failed without zlib
Ezio Melotti <ezio.melotti@gmail.com>
parents:
55106
diff
changeset
|
29 except ImportError: |
|
39be3ef82d23
#6026 - fix tests that failed without zlib
Ezio Melotti <ezio.melotti@gmail.com>
parents:
55106
diff
changeset
|
30 zlib = None |
|
39be3ef82d23
#6026 - fix tests that failed without zlib
Ezio Melotti <ezio.melotti@gmail.com>
parents:
55106
diff
changeset
|
31 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
32 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
33 class SqliteTypeTests(unittest.TestCase): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
34 def setUp(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
35 self.con = sqlite.connect(":memory:") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
36 self.cur = self.con.cursor() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
37 self.cur.execute("create table test(i integer, s varchar, f number, b blob)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
38 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
39 def tearDown(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
40 self.cur.close() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
41 self.con.close() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
42 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
43 def CheckString(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
44 self.cur.execute("insert into test(s) values (?)", (u"Österreich",)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
45 self.cur.execute("select s from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
46 row = self.cur.fetchone() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
47 self.assertEqual(row[0], u"Österreich") |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
48 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
49 def CheckSmallInt(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
50 self.cur.execute("insert into test(i) values (?)", (42,)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
51 self.cur.execute("select i from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
52 row = self.cur.fetchone() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
53 self.assertEqual(row[0], 42) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
54 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
55 def CheckLargeInt(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
56 num = 2**40 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
57 self.cur.execute("insert into test(i) values (?)", (num,)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
58 self.cur.execute("select i from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
59 row = self.cur.fetchone() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
60 self.assertEqual(row[0], num) |
|
37362
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 CheckFloat(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
63 val = 3.14 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
64 self.cur.execute("insert into test(f) values (?)", (val,)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
65 self.cur.execute("select f from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
66 row = self.cur.fetchone() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
67 self.assertEqual(row[0], val) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
68 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
69 def CheckBlob(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
70 val = buffer("Guglhupf") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
71 self.cur.execute("insert into test(b) values (?)", (val,)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
72 self.cur.execute("select b from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
73 row = self.cur.fetchone() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
74 self.assertEqual(row[0], val) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
75 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
76 def CheckUnicodeExecute(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
77 self.cur.execute(u"select 'Österreich'") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
78 row = self.cur.fetchone() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
79 self.assertEqual(row[0], u"Österreich") |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
80 |
|
59362
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
81 def CheckNonUtf8_Default(self): |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
82 try: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
83 self.cur.execute("select ?", (chr(150),)) |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
84 self.fail("should have raised a ProgrammingError") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
85 except sqlite.ProgrammingError: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
86 pass |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
87 |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
88 def CheckNonUtf8_TextFactoryString(self): |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
89 orig_text_factory = self.con.text_factory |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
90 try: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
91 self.con.text_factory = str |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
92 self.cur.execute("select ?", (chr(150),)) |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
93 finally: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
94 self.con.text_factory = orig_text_factory |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
95 |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
96 def CheckNonUtf8_TextFactoryOptimizedUnicode(self): |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
97 orig_text_factory = self.con.text_factory |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
98 try: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
99 try: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
100 self.con.text_factory = sqlite.OptimizedUnicode |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
101 self.cur.execute("select ?", (chr(150),)) |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
102 self.fail("should have raised a ProgrammingError") |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
103 except sqlite.ProgrammingError: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
104 pass |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
105 finally: |
|
04d3ae52ff73
Merged code from pysqlite 2.6.0.
Gerhard Häring <gh@ghaering.de>
parents:
58669
diff
changeset
|
106 self.con.text_factory = orig_text_factory |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
107 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
108 class DeclTypesTests(unittest.TestCase): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
109 class Foo: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
110 def __init__(self, _val): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
111 self.val = _val |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
112 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
113 def __cmp__(self, other): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
114 if not isinstance(other, DeclTypesTests.Foo): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
115 raise ValueError |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
116 if self.val == other.val: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
117 return 0 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
118 else: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
119 return 1 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
120 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
121 def __conform__(self, protocol): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
122 if protocol is sqlite.PrepareProtocol: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
123 return self.val |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
124 else: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
125 return None |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
126 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
127 def __str__(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
128 return "<%s>" % self.val |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
129 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
130 def setUp(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
131 self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
132 self.cur = self.con.cursor() |
|
46659
28b099ac4cd8
Implemented feature request 2157: Converter names are cut off at '('
Gerhard Häring <gh@ghaering.de>
parents:
45580
diff
changeset
|
133 self.cur.execute("create table test(i int, s str, f float, b bool, u unicode, foo foo, bin blob, n1 number, n2 number(5))") |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
134 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
135 # override float, make them always return the same number |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37362
diff
changeset
|
136 sqlite.converters["FLOAT"] = lambda x: 47.2 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
137 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
138 # and implement two custom ones |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37362
diff
changeset
|
139 sqlite.converters["BOOL"] = lambda x: bool(int(x)) |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37362
diff
changeset
|
140 sqlite.converters["FOO"] = DeclTypesTests.Foo |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38978
diff
changeset
|
141 sqlite.converters["WRONG"] = lambda x: "WRONG" |
|
46659
28b099ac4cd8
Implemented feature request 2157: Converter names are cut off at '('
Gerhard Häring <gh@ghaering.de>
parents:
45580
diff
changeset
|
142 sqlite.converters["NUMBER"] = float |
|
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 def tearDown(self): |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37362
diff
changeset
|
145 del sqlite.converters["FLOAT"] |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37362
diff
changeset
|
146 del sqlite.converters["BOOL"] |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37362
diff
changeset
|
147 del sqlite.converters["FOO"] |
|
46659
28b099ac4cd8
Implemented feature request 2157: Converter names are cut off at '('
Gerhard Häring <gh@ghaering.de>
parents:
45580
diff
changeset
|
148 del sqlite.converters["NUMBER"] |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
149 self.cur.close() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
150 self.con.close() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
151 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
152 def CheckString(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
153 # default |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
154 self.cur.execute("insert into test(s) values (?)", ("foo",)) |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38978
diff
changeset
|
155 self.cur.execute('select s as "s [WRONG]" from test') |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
156 row = self.cur.fetchone() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
157 self.assertEqual(row[0], "foo") |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
158 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
159 def CheckSmallInt(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
160 # default |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
161 self.cur.execute("insert into test(i) values (?)", (42,)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
162 self.cur.execute("select i from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
163 row = self.cur.fetchone() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
164 self.assertEqual(row[0], 42) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
165 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
166 def CheckLargeInt(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
167 # default |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
168 num = 2**40 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
169 self.cur.execute("insert into test(i) values (?)", (num,)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
170 self.cur.execute("select i from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
171 row = self.cur.fetchone() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
172 self.assertEqual(row[0], num) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
173 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
174 def CheckFloat(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
175 # custom |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
176 val = 3.14 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
177 self.cur.execute("insert into test(f) values (?)", (val,)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
178 self.cur.execute("select f from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
179 row = self.cur.fetchone() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
180 self.assertEqual(row[0], 47.2) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
181 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
182 def CheckBool(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
183 # custom |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
184 self.cur.execute("insert into test(b) values (?)", (False,)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
185 self.cur.execute("select b from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
186 row = self.cur.fetchone() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
187 self.assertEqual(row[0], False) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
188 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
189 self.cur.execute("delete from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
190 self.cur.execute("insert into test(b) values (?)", (True,)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
191 self.cur.execute("select b from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
192 row = self.cur.fetchone() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
193 self.assertEqual(row[0], True) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
194 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
195 def CheckUnicode(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
196 # default |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
197 val = u"\xd6sterreich" |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
198 self.cur.execute("insert into test(u) values (?)", (val,)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
199 self.cur.execute("select u from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
200 row = self.cur.fetchone() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
201 self.assertEqual(row[0], val) |
|
37362
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 CheckFoo(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
204 val = DeclTypesTests.Foo("bla") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
205 self.cur.execute("insert into test(foo) values (?)", (val,)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
206 self.cur.execute("select foo from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
207 row = self.cur.fetchone() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
208 self.assertEqual(row[0], val) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
209 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
210 def CheckUnsupportedSeq(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
211 class Bar: pass |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
212 val = Bar() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
213 try: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
214 self.cur.execute("insert into test(f) values (?)", (val,)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
215 self.fail("should have raised an InterfaceError") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
216 except sqlite.InterfaceError: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
217 pass |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
218 except: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
219 self.fail("should have raised an InterfaceError") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
220 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
221 def CheckUnsupportedDict(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
222 class Bar: pass |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
223 val = Bar() |
|
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.cur.execute("insert into test(f) values (:val)", {"val": val}) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
226 self.fail("should have raised an InterfaceError") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
227 except sqlite.InterfaceError: |
|
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 except: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
230 self.fail("should have raised an InterfaceError") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
231 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
232 def CheckBlob(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
233 # default |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
234 val = buffer("Guglhupf") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
235 self.cur.execute("insert into test(bin) values (?)", (val,)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
236 self.cur.execute("select bin from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
237 row = self.cur.fetchone() |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
238 self.assertEqual(row[0], val) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
239 |
|
46659
28b099ac4cd8
Implemented feature request 2157: Converter names are cut off at '('
Gerhard Häring <gh@ghaering.de>
parents:
45580
diff
changeset
|
240 def CheckNumber1(self): |
|
28b099ac4cd8
Implemented feature request 2157: Converter names are cut off at '('
Gerhard Häring <gh@ghaering.de>
parents:
45580
diff
changeset
|
241 self.cur.execute("insert into test(n1) values (5)") |
|
28b099ac4cd8
Implemented feature request 2157: Converter names are cut off at '('
Gerhard Häring <gh@ghaering.de>
parents:
45580
diff
changeset
|
242 value = self.cur.execute("select n1 from test").fetchone()[0] |
|
28b099ac4cd8
Implemented feature request 2157: Converter names are cut off at '('
Gerhard Häring <gh@ghaering.de>
parents:
45580
diff
changeset
|
243 # if the converter is not used, it's an int instead of a float |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
244 self.assertEqual(type(value), float) |
|
46659
28b099ac4cd8
Implemented feature request 2157: Converter names are cut off at '('
Gerhard Häring <gh@ghaering.de>
parents:
45580
diff
changeset
|
245 |
|
28b099ac4cd8
Implemented feature request 2157: Converter names are cut off at '('
Gerhard Häring <gh@ghaering.de>
parents:
45580
diff
changeset
|
246 def CheckNumber2(self): |
|
28b099ac4cd8
Implemented feature request 2157: Converter names are cut off at '('
Gerhard Häring <gh@ghaering.de>
parents:
45580
diff
changeset
|
247 """Checks wether converter names are cut off at '(' characters""" |
|
28b099ac4cd8
Implemented feature request 2157: Converter names are cut off at '('
Gerhard Häring <gh@ghaering.de>
parents:
45580
diff
changeset
|
248 self.cur.execute("insert into test(n2) values (5)") |
|
28b099ac4cd8
Implemented feature request 2157: Converter names are cut off at '('
Gerhard Häring <gh@ghaering.de>
parents:
45580
diff
changeset
|
249 value = self.cur.execute("select n2 from test").fetchone()[0] |
|
28b099ac4cd8
Implemented feature request 2157: Converter names are cut off at '('
Gerhard Häring <gh@ghaering.de>
parents:
45580
diff
changeset
|
250 # if the converter is not used, it's an int instead of a float |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
251 self.assertEqual(type(value), float) |
|
46659
28b099ac4cd8
Implemented feature request 2157: Converter names are cut off at '('
Gerhard Häring <gh@ghaering.de>
parents:
45580
diff
changeset
|
252 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
253 class ColNamesTests(unittest.TestCase): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
254 def setUp(self): |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38978
diff
changeset
|
255 self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
256 self.cur = self.con.cursor() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
257 self.cur.execute("create table test(x foo)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
258 |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37362
diff
changeset
|
259 sqlite.converters["FOO"] = lambda x: "[%s]" % x |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37362
diff
changeset
|
260 sqlite.converters["BAR"] = lambda x: "<%s>" % x |
|
63556
dba99828d91c
Merged revisions 77942,79023 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
46659
diff
changeset
|
261 sqlite.converters["EXC"] = lambda x: 5 // 0 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38978
diff
changeset
|
262 sqlite.converters["B1B1"] = lambda x: "MARKER" |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
263 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
264 def tearDown(self): |
|
38808
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37362
diff
changeset
|
265 del sqlite.converters["FOO"] |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37362
diff
changeset
|
266 del sqlite.converters["BAR"] |
|
3e5fd2b70e5a
Merged changes from external pysqlite 2.3.0 release. Documentation updates will
Gerhard Häring <gh@ghaering.de>
parents:
37362
diff
changeset
|
267 del sqlite.converters["EXC"] |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38978
diff
changeset
|
268 del sqlite.converters["B1B1"] |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
269 self.cur.close() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
270 self.con.close() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
271 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38978
diff
changeset
|
272 def CheckDeclTypeNotUsed(self): |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38978
diff
changeset
|
273 """ |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38978
diff
changeset
|
274 Assures that the declared type is not used when PARSE_DECLTYPES |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38978
diff
changeset
|
275 is not set. |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38978
diff
changeset
|
276 """ |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
277 self.cur.execute("insert into test(x) values (?)", ("xxx",)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
278 self.cur.execute("select x from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
279 val = self.cur.fetchone()[0] |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
280 self.assertEqual(val, "xxx") |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
281 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
282 def CheckNone(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
283 self.cur.execute("insert into test(x) values (?)", (None,)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
284 self.cur.execute("select x from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
285 val = self.cur.fetchone()[0] |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
286 self.assertEqual(val, None) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
287 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
288 def CheckColName(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
289 self.cur.execute("insert into test(x) values (?)", ("xxx",)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
290 self.cur.execute('select x as "x [bar]" from test') |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
291 val = self.cur.fetchone()[0] |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
292 self.assertEqual(val, "<xxx>") |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
293 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
294 # Check if the stripping of colnames works. Everything after the first |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
295 # whitespace should be stripped. |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
296 self.assertEqual(self.cur.description[0][0], "x") |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
297 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38978
diff
changeset
|
298 def CheckCaseInConverterName(self): |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38978
diff
changeset
|
299 self.cur.execute("""select 'other' as "x [b1b1]\"""") |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38978
diff
changeset
|
300 val = self.cur.fetchone()[0] |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
301 self.assertEqual(val, "MARKER") |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38978
diff
changeset
|
302 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
303 def CheckCursorDescriptionNoRow(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
304 """ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
305 cursor.description should at least provide the column name(s), even if |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
306 no row returned. |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
307 """ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
308 self.cur.execute("select * from test where 0 = 1") |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
59362
diff
changeset
|
309 self.assertEqual(self.cur.description[0][0], "x") |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
310 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
311 class ObjectAdaptationTests(unittest.TestCase): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
312 def cast(obj): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
313 return float(obj) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
314 cast = staticmethod(cast) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
315 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
316 def setUp(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
317 self.con = sqlite.connect(":memory:") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
318 try: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
319 del sqlite.adapters[int] |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
320 except: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
321 pass |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
322 sqlite.register_adapter(int, ObjectAdaptationTests.cast) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
323 self.cur = self.con.cursor() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
324 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
325 def tearDown(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
326 del sqlite.adapters[(int, sqlite.PrepareProtocol)] |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
327 self.cur.close() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
328 self.con.close() |
|
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 CheckCasterIsUsed(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
331 self.cur.execute("select ?", (4,)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
332 val = self.cur.fetchone()[0] |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
333 self.assertEqual(type(val), float) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
334 |
|
55920
39be3ef82d23
#6026 - fix tests that failed without zlib
Ezio Melotti <ezio.melotti@gmail.com>
parents:
55106
diff
changeset
|
335 @unittest.skipUnless(zlib, "requires zlib") |
|
38978
5dd736268ff4
The sqlite3 module did cut off data from the SQLite database at the first null
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
336 class BinaryConverterTests(unittest.TestCase): |
|
5dd736268ff4
The sqlite3 module did cut off data from the SQLite database at the first null
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
337 def convert(s): |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44408
diff
changeset
|
338 return zlib.decompress(s) |
|
38978
5dd736268ff4
The sqlite3 module did cut off data from the SQLite database at the first null
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
339 convert = staticmethod(convert) |
|
5dd736268ff4
The sqlite3 module did cut off data from the SQLite database at the first null
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
340 |
|
5dd736268ff4
The sqlite3 module did cut off data from the SQLite database at the first null
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
341 def setUp(self): |
|
5dd736268ff4
The sqlite3 module did cut off data from the SQLite database at the first null
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
342 self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES) |
|
5dd736268ff4
The sqlite3 module did cut off data from the SQLite database at the first null
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
343 sqlite.register_converter("bin", BinaryConverterTests.convert) |
|
5dd736268ff4
The sqlite3 module did cut off data from the SQLite database at the first null
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
344 |
|
5dd736268ff4
The sqlite3 module did cut off data from the SQLite database at the first null
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
345 def tearDown(self): |
|
5dd736268ff4
The sqlite3 module did cut off data from the SQLite database at the first null
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
346 self.con.close() |
|
5dd736268ff4
The sqlite3 module did cut off data from the SQLite database at the first null
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
347 |
|
5dd736268ff4
The sqlite3 module did cut off data from the SQLite database at the first null
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
348 def CheckBinaryInputForConverter(self): |
|
5dd736268ff4
The sqlite3 module did cut off data from the SQLite database at the first null
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
349 testdata = "abcdefg" * 10 |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44408
diff
changeset
|
350 result = self.con.execute('select ? as "x [bin]"', (buffer(zlib.compress(testdata)),)).fetchone()[0] |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
351 self.assertEqual(testdata, result) |
|
38978
5dd736268ff4
The sqlite3 module did cut off data from the SQLite database at the first null
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
352 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
353 class DateTimeTests(unittest.TestCase): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
354 def setUp(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
355 self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
356 self.cur = self.con.cursor() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
357 self.cur.execute("create table test(d date, ts timestamp)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
358 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
359 def tearDown(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
360 self.cur.close() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
361 self.con.close() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
362 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
363 def CheckSqliteDate(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
364 d = sqlite.Date(2004, 2, 14) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
365 self.cur.execute("insert into test(d) values (?)", (d,)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
366 self.cur.execute("select d from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
367 d2 = self.cur.fetchone()[0] |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
368 self.assertEqual(d, d2) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
369 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
370 def CheckSqliteTimestamp(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
371 ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
372 self.cur.execute("insert into test(ts) values (?)", (ts,)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
373 self.cur.execute("select ts from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
374 ts2 = self.cur.fetchone()[0] |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
375 self.assertEqual(ts, ts2) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
376 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
377 def CheckSqlTimestamp(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
378 # The date functions are only available in SQLite version 3.1 or later |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
379 if sqlite.sqlite_version_info < (3, 1): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
380 return |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
381 |
|
45580
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44408
diff
changeset
|
382 # SQLite's current_timestamp uses UTC time, while datetime.datetime.now() uses local time. |
|
b7ee9074ca0e
Updated to pysqlite 2.4.1. Documentation additions will come later.
Gerhard Häring <gh@ghaering.de>
parents:
44408
diff
changeset
|
383 now = datetime.datetime.now() |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
384 self.cur.execute("insert into test(ts) values (current_timestamp)") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
385 self.cur.execute("select ts from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
386 ts = self.cur.fetchone()[0] |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
387 self.assertEqual(type(ts), datetime.datetime) |
|
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
388 self.assertEqual(ts.year, now.year) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
389 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
390 def CheckDateTimeSubSeconds(self): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
391 ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0, 500000) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
392 self.cur.execute("insert into test(ts) values (?)", (ts,)) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
393 self.cur.execute("select ts from test") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
394 ts2 = self.cur.fetchone()[0] |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
395 self.assertEqual(ts, ts2) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
396 |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38978
diff
changeset
|
397 def CheckDateTimeSubSecondsFloatingPoint(self): |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38978
diff
changeset
|
398 ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0, 510241) |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38978
diff
changeset
|
399 self.cur.execute("insert into test(ts) values (?)", (ts,)) |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38978
diff
changeset
|
400 self.cur.execute("select ts from test") |
|
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38978
diff
changeset
|
401 ts2 = self.cur.fetchone()[0] |
|
55106
7ff1405ccb64
Merge r73838 from py3k branch. Use the nondeprecated unittest method
Gregory P. Smith <greg@mad-scientist.com>
parents:
46659
diff
changeset
|
402 self.assertEqual(ts, ts2) |
|
40625
b9d4ced23506
Merged changes from standalone version 2.3.3. This should probably all be
Gerhard Häring <gh@ghaering.de>
parents:
38978
diff
changeset
|
403 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
404 def suite(): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
405 sqlite_type_suite = unittest.makeSuite(SqliteTypeTests, "Check") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
406 decltypes_type_suite = unittest.makeSuite(DeclTypesTests, "Check") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
407 colnames_type_suite = unittest.makeSuite(ColNamesTests, "Check") |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
408 adaptation_suite = unittest.makeSuite(ObjectAdaptationTests, "Check") |
|
38978
5dd736268ff4
The sqlite3 module did cut off data from the SQLite database at the first null
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
409 bin_suite = unittest.makeSuite(BinaryConverterTests, "Check") |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
410 date_suite = unittest.makeSuite(DateTimeTests, "Check") |
|
38978
5dd736268ff4
The sqlite3 module did cut off data from the SQLite database at the first null
Gerhard Häring <gh@ghaering.de>
parents:
38808
diff
changeset
|
411 return unittest.TestSuite((sqlite_type_suite, decltypes_type_suite, colnames_type_suite, adaptation_suite, bin_suite, date_suite)) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
412 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
413 def test(): |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
414 runner = unittest.TextTestRunner() |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
415 runner.run(suite()) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
416 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
417 if __name__ == "__main__": |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
418 test() |
