(original) (raw)

changeset: 82348:6911df35b7b6 branch: 2.7 parent: 82343:8b177aea9ddd user: Petri Lehtinen petri@digip.org date: Sat Feb 23 19:05:09 2013 +0100 files: Lib/sqlite3/dbapi2.py Lib/sqlite3/test/regression.py Misc/ACKS Misc/NEWS description: Issue #14720: sqlite3: Convert datetime microseconds correctly Patch by Lowe Thiderman diff -r 8b177aea9ddd -r 6911df35b7b6 Lib/sqlite3/dbapi2.py --- a/Lib/sqlite3/dbapi2.py Sat Feb 23 17:05:28 2013 +0100 +++ b/Lib/sqlite3/dbapi2.py Sat Feb 23 19:05:09 2013 +0100 @@ -68,7 +68,7 @@ timepart_full = timepart.split(".") hours, minutes, seconds = map(int, timepart_full[0].split(":")) if len(timepart_full) == 2: - microseconds = int(timepart_full[1]) + microseconds = int('{:0<6}'.format(timepart_full[1].decode())) else: microseconds = 0 diff -r 8b177aea9ddd -r 6911df35b7b6 Lib/sqlite3/test/regression.py --- a/Lib/sqlite3/test/regression.py Sat Feb 23 17:05:28 2013 +0100 +++ b/Lib/sqlite3/test/regression.py Sat Feb 23 19:05:09 2013 +0100 @@ -1,4 +1,4 @@ -#-*- coding: ISO-8859-1 -*- +#-*- coding: iso-8859-1 -*- # pysqlite2/test/regression.py: pysqlite regression tests # # Copyright (C) 2006-2007 Gerhard H�ring gh@ghaering.de @@ -285,6 +285,23 @@ cur.executemany("insert into b (baz) values (?)", ((i,) for i in foo())) + def CheckConvertTimestampMicrosecondPadding(self): + """ + http://bugs.python.org/issue14720 + + The microsecond parsing of convert_timestamp() should pad with zeros, + since the microsecond string "456" actually represents "456000". + """ + + con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES) + cur = con.cursor() + cur.execute("CREATE TABLE t (x TIMESTAMP)") + cur.execute("INSERT INTO t (x) VALUES ('2012-04-04 15:06:00.456')") + cur.execute("SELECT * FROM t") + date = cur.fetchall()[0][0] + + self.assertEqual(date, datetime.datetime(2012, 4, 4, 15, 6, 0, 456000)) + def suite(): regression_suite = unittest.makeSuite(RegressionTests, "Check") diff -r 8b177aea9ddd -r 6911df35b7b6 Misc/ACKS --- a/Misc/ACKS Sat Feb 23 17:05:28 2013 +0100 +++ b/Misc/ACKS Sat Feb 23 19:05:09 2013 +0100 @@ -990,6 +990,7 @@ Mikhail Terekhov Richard M. Tew Tobias Thelen +Lowe Thiderman Nicolas M. Thiéry James Thomas Robin Thomas diff -r 8b177aea9ddd -r 6911df35b7b6 Misc/NEWS --- a/Misc/NEWS Sat Feb 23 17:05:28 2013 +0100 +++ b/Misc/NEWS Sat Feb 23 19:05:09 2013 +0100 @@ -208,6 +208,9 @@ Library ------- +- Issue #14720: sqlite3: Convert datetime microseconds correctly. + Patch by Lowe Thiderman. + - Issue #17225: JSON decoder now counts columns in the first line starting with 1, as in other lines. /gh@ghaering.de/petri@digip.org