summaryrefslogtreecommitdiff
path: root/Lib/sqlite3/test
diff options
context:
space:
mode:
authorGerhard Häring <gh@ghaering.de>2008-05-04 13:42:44 +0000
committerGerhard Häring <gh@ghaering.de>2008-05-04 13:42:44 +0000
commite11c9b3dfd5a17eb4dba21dcc54e4ad0e79a8c87 (patch)
tree17c25cc209f253b90514355d5f9f4c3751daea11 /Lib/sqlite3/test
parent5a366c3b8bf1e8afb2d48a02b498f2eaab812c49 (diff)
downloadcpython-git-e11c9b3dfd5a17eb4dba21dcc54e4ad0e79a8c87.tar.gz
Implemented feature request 2157: Converter names are cut off at '('
characters. This avoids the common case of something like 'NUMBER(10)' not being parsed as 'NUMBER', like expected. Also corrected the docs about converter names being case-sensitive. They aren't any longer.
Diffstat (limited to 'Lib/sqlite3/test')
-rw-r--r--Lib/sqlite3/test/types.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/Lib/sqlite3/test/types.py b/Lib/sqlite3/test/types.py
index 197040172c..471425d604 100644
--- a/Lib/sqlite3/test/types.py
+++ b/Lib/sqlite3/test/types.py
@@ -98,7 +98,7 @@ class DeclTypesTests(unittest.TestCase):
def setUp(self):
self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES)
self.cur = self.con.cursor()
- self.cur.execute("create table test(i int, s str, f float, b bool, u unicode, foo foo, bin blob)")
+ 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))")
# override float, make them always return the same number
sqlite.converters["FLOAT"] = lambda x: 47.2
@@ -107,11 +107,13 @@ class DeclTypesTests(unittest.TestCase):
sqlite.converters["BOOL"] = lambda x: bool(int(x))
sqlite.converters["FOO"] = DeclTypesTests.Foo
sqlite.converters["WRONG"] = lambda x: "WRONG"
+ sqlite.converters["NUMBER"] = float
def tearDown(self):
del sqlite.converters["FLOAT"]
del sqlite.converters["BOOL"]
del sqlite.converters["FOO"]
+ del sqlite.converters["NUMBER"]
self.cur.close()
self.con.close()
@@ -203,6 +205,19 @@ class DeclTypesTests(unittest.TestCase):
row = self.cur.fetchone()
self.failUnlessEqual(row[0], val)
+ def CheckNumber1(self):
+ self.cur.execute("insert into test(n1) values (5)")
+ value = self.cur.execute("select n1 from test").fetchone()[0]
+ # if the converter is not used, it's an int instead of a float
+ self.failUnlessEqual(type(value), float)
+
+ def CheckNumber2(self):
+ """Checks wether converter names are cut off at '(' characters"""
+ self.cur.execute("insert into test(n2) values (5)")
+ value = self.cur.execute("select n2 from test").fetchone()[0]
+ # if the converter is not used, it's an int instead of a float
+ self.failUnlessEqual(type(value), float)
+
class ColNamesTests(unittest.TestCase):
def setUp(self):
self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES)