mirror of
https://github.com/python/cpython.git
synced 2025-11-03 11:23:31 +00:00
Issue #14720: sqlite3: Convert datetime microseconds correctly
This commit is contained in:
commit
e460f26b25
4 changed files with 22 additions and 1 deletions
|
|
@ -67,7 +67,7 @@ def register_adapters_and_converters():
|
||||||
timepart_full = timepart.split(b".")
|
timepart_full = timepart.split(b".")
|
||||||
hours, minutes, seconds = map(int, timepart_full[0].split(b":"))
|
hours, minutes, seconds = map(int, timepart_full[0].split(b":"))
|
||||||
if len(timepart_full) == 2:
|
if len(timepart_full) == 2:
|
||||||
microseconds = int(timepart_full[1])
|
microseconds = int('{:0<6}'.format(timepart_full[1].decode()))
|
||||||
else:
|
else:
|
||||||
microseconds = 0
|
microseconds = 0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -302,6 +302,23 @@ class RegressionTests(unittest.TestCase):
|
||||||
cur.executemany("insert into b (baz) values (?)",
|
cur.executemany("insert into b (baz) values (?)",
|
||||||
((i,) for i in foo()))
|
((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():
|
def suite():
|
||||||
regression_suite = unittest.makeSuite(RegressionTests, "Check")
|
regression_suite = unittest.makeSuite(RegressionTests, "Check")
|
||||||
|
|
|
||||||
|
|
@ -1192,6 +1192,7 @@ Anatoly Techtonik
|
||||||
Mikhail Terekhov
|
Mikhail Terekhov
|
||||||
Richard M. Tew
|
Richard M. Tew
|
||||||
Tobias Thelen
|
Tobias Thelen
|
||||||
|
Lowe Thiderman
|
||||||
Nicolas M. Thiéry
|
Nicolas M. Thiéry
|
||||||
James Thomas
|
James Thomas
|
||||||
Robin Thomas
|
Robin Thomas
|
||||||
|
|
|
||||||
|
|
@ -260,6 +260,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #14720: sqlite3: Convert datetime microseconds correctly.
|
||||||
|
Patch by Lowe Thiderman.
|
||||||
|
|
||||||
- Issue #15132: Allow a list for the defaultTest argument of
|
- Issue #15132: Allow a list for the defaultTest argument of
|
||||||
unittest.TestProgram. Patch by Jyrki Pulliainen.
|
unittest.TestProgram. Patch by Jyrki Pulliainen.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue