diff -r 1f3ce7ba410b Lib/sqlite3/dbapi2.py --- a/Lib/sqlite3/dbapi2.py Mon Feb 18 21:44:03 2013 -0500 +++ b/Lib/sqlite3/dbapi2.py Sat Feb 23 17:44:36 2013 +0100 @@ -67,7 +67,7 @@ timepart_full = timepart.split(b".") hours, minutes, seconds = map(int, timepart_full[0].split(b":")) if len(timepart_full) == 2: - microseconds = int(timepart_full[1]) + microseconds = int('{:0<6}'.format(timepart_full[1].decode())) else: microseconds = 0 diff -r 1f3ce7ba410b Lib/sqlite3/test/regression.py --- a/Lib/sqlite3/test/regression.py Mon Feb 18 21:44:03 2013 -0500 +++ b/Lib/sqlite3/test/regression.py Sat Feb 23 17:44:36 2013 +0100 @@ -302,6 +302,23 @@ cur.executemany("insert into b (baz) values (?)", ((i,) for i in foo())) + def CheckCovertTimestampMicrosecondPadding(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")