diff options
Diffstat (limited to 'Lib/sqlite3')
-rw-r--r-- | Lib/sqlite3/dbapi2.py | 2 | ||||
-rw-r--r-- | Lib/sqlite3/test/factory.py | 23 | ||||
-rw-r--r-- | Lib/sqlite3/test/regression.py | 10 | ||||
-rw-r--r-- | Lib/sqlite3/test/types.py | 27 |
4 files changed, 56 insertions, 6 deletions
diff --git a/Lib/sqlite3/dbapi2.py b/Lib/sqlite3/dbapi2.py index 9b7d56d..7eb28e8 100644 --- a/Lib/sqlite3/dbapi2.py +++ b/Lib/sqlite3/dbapi2.py @@ -68,7 +68,7 @@ def register_adapters_and_converters(): timepart_full = timepart.split(".") hours, minutes, seconds = map(int, timepart_full[0].split(":")) if len(timepart_full) == 2: - microseconds = int(float("0." + timepart_full[1]) * 1000000) + microseconds = int(timepart_full[1]) else: microseconds = 0 diff --git a/Lib/sqlite3/test/factory.py b/Lib/sqlite3/test/factory.py index 8778056..8a77d5d 100644 --- a/Lib/sqlite3/test/factory.py +++ b/Lib/sqlite3/test/factory.py @@ -91,7 +91,7 @@ class RowFactoryTests(unittest.TestCase): list), "row is not instance of list") - def CheckSqliteRow(self): + def CheckSqliteRowIndex(self): self.con.row_factory = sqlite.Row row = self.con.execute("select 1 as a, 2 as b").fetchone() self.failUnless(isinstance(row, @@ -110,6 +110,27 @@ class RowFactoryTests(unittest.TestCase): self.failUnless(col1 == 1, "by index: wrong result for column 0") self.failUnless(col2 == 2, "by index: wrong result for column 1") + def CheckSqliteRowIter(self): + """Checks if the row object is iterable""" + self.con.row_factory = sqlite.Row + row = self.con.execute("select 1 as a, 2 as b").fetchone() + for col in row: + pass + + def CheckSqliteRowAsTuple(self): + """Checks if the row object can be converted to a tuple""" + self.con.row_factory = sqlite.Row + row = self.con.execute("select 1 as a, 2 as b").fetchone() + t = tuple(row) + + def CheckSqliteRowAsDict(self): + """Checks if the row object can be correctly converted to a dictionary""" + self.con.row_factory = sqlite.Row + row = self.con.execute("select 1 as a, 2 as b").fetchone() + d = dict(row) + self.failUnlessEqual(d["a"], row["a"]) + self.failUnlessEqual(d["b"], row["b"]) + def tearDown(self): self.con.close() diff --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py index c8733b9..addedb1 100644 --- a/Lib/sqlite3/test/regression.py +++ b/Lib/sqlite3/test/regression.py @@ -69,6 +69,16 @@ class RegressionTests(unittest.TestCase): cur.execute('select 1 as "foo baz"') self.failUnlessEqual(cur.description[0][0], "foo baz") + def CheckStatementAvailable(self): + # pysqlite up to 2.3.2 crashed on this, because the active statement handle was not checked + # before trying to fetch data from it. close() destroys the active statement ... + con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES) + cur = con.cursor() + cur.execute("select 4 union select 5") + cur.close() + cur.fetchone() + cur.fetchone() + def suite(): regression_suite = unittest.makeSuite(RegressionTests, "Check") return unittest.TestSuite((regression_suite,)) diff --git a/Lib/sqlite3/test/types.py b/Lib/sqlite3/test/types.py index 9a11f5c..a357b2e 100644 --- a/Lib/sqlite3/test/types.py +++ b/Lib/sqlite3/test/types.py @@ -112,6 +112,7 @@ class DeclTypesTests(unittest.TestCase): # and implement two custom ones sqlite.converters["BOOL"] = lambda x: bool(int(x)) sqlite.converters["FOO"] = DeclTypesTests.Foo + sqlite.converters["WRONG"] = lambda x: "WRONG" def tearDown(self): del sqlite.converters["FLOAT"] @@ -123,7 +124,7 @@ class DeclTypesTests(unittest.TestCase): def CheckString(self): # default self.cur.execute("insert into test(s) values (?)", ("foo",)) - self.cur.execute("select s from test") + self.cur.execute('select s as "s [WRONG]" from test') row = self.cur.fetchone() self.failUnlessEqual(row[0], "foo") @@ -210,26 +211,32 @@ class DeclTypesTests(unittest.TestCase): class ColNamesTests(unittest.TestCase): def setUp(self): - self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES|sqlite.PARSE_DECLTYPES) + self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES) self.cur = self.con.cursor() self.cur.execute("create table test(x foo)") sqlite.converters["FOO"] = lambda x: "[%s]" % x sqlite.converters["BAR"] = lambda x: "<%s>" % x sqlite.converters["EXC"] = lambda x: 5/0 + sqlite.converters["B1B1"] = lambda x: "MARKER" def tearDown(self): del sqlite.converters["FOO"] del sqlite.converters["BAR"] del sqlite.converters["EXC"] + del sqlite.converters["B1B1"] self.cur.close() self.con.close() - def CheckDeclType(self): + def CheckDeclTypeNotUsed(self): + """ + Assures that the declared type is not used when PARSE_DECLTYPES + is not set. + """ self.cur.execute("insert into test(x) values (?)", ("xxx",)) self.cur.execute("select x from test") val = self.cur.fetchone()[0] - self.failUnlessEqual(val, "[xxx]") + self.failUnlessEqual(val, "xxx") def CheckNone(self): self.cur.execute("insert into test(x) values (?)", (None,)) @@ -247,6 +254,11 @@ class ColNamesTests(unittest.TestCase): # whitespace should be stripped. self.failUnlessEqual(self.cur.description[0][0], "x") + def CheckCaseInConverterName(self): + self.cur.execute("""select 'other' as "x [b1b1]\"""") + val = self.cur.fetchone()[0] + self.failUnlessEqual(val, "MARKER") + def CheckCursorDescriptionNoRow(self): """ cursor.description should at least provide the column name(s), even if @@ -340,6 +352,13 @@ class DateTimeTests(unittest.TestCase): ts2 = self.cur.fetchone()[0] self.failUnlessEqual(ts, ts2) + def CheckDateTimeSubSecondsFloatingPoint(self): + ts = sqlite.Timestamp(2004, 2, 14, 7, 15, 0, 510241) + self.cur.execute("insert into test(ts) values (?)", (ts,)) + self.cur.execute("select ts from test") + ts2 = self.cur.fetchone()[0] + self.failUnlessEqual(ts, ts2) + def suite(): sqlite_type_suite = unittest.makeSuite(SqliteTypeTests, "Check") decltypes_type_suite = unittest.makeSuite(DeclTypesTests, "Check") |