diff options
author | Gerhard Häring <gh@ghaering.de> | 2008-05-04 13:42:44 (GMT) |
---|---|---|
committer | Gerhard Häring <gh@ghaering.de> | 2008-05-04 13:42:44 (GMT) |
commit | e11c9b3dfd5a17eb4dba21dcc54e4ad0e79a8c87 (patch) | |
tree | 17c25cc209f253b90514355d5f9f4c3751daea11 /Lib | |
parent | 5a366c3b8bf1e8afb2d48a02b498f2eaab812c49 (diff) | |
download | cpython-e11c9b3dfd5a17eb4dba21dcc54e4ad0e79a8c87.zip cpython-e11c9b3dfd5a17eb4dba21dcc54e4ad0e79a8c87.tar.gz cpython-e11c9b3dfd5a17eb4dba21dcc54e4ad0e79a8c87.tar.bz2 |
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')
-rw-r--r-- | Lib/sqlite3/test/types.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/Lib/sqlite3/test/types.py b/Lib/sqlite3/test/types.py index 1970401..471425d 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) |