summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2013-02-23 18:05:09 (GMT)
committerPetri Lehtinen <petri@digip.org>2013-02-23 18:05:09 (GMT)
commit9e14755b46c48207b44be92093ca2eae6ba22fac (patch)
tree1bbb90a9c86258902251605e9f64a7e841334376 /Lib
parentc23178ba36097764bc3c1c33aa8dba2a0871e778 (diff)
downloadcpython-9e14755b46c48207b44be92093ca2eae6ba22fac.zip
cpython-9e14755b46c48207b44be92093ca2eae6ba22fac.tar.gz
cpython-9e14755b46c48207b44be92093ca2eae6ba22fac.tar.bz2
Issue #14720: sqlite3: Convert datetime microseconds correctly
Patch by Lowe Thiderman
Diffstat (limited to 'Lib')
-rw-r--r--Lib/sqlite3/dbapi2.py2
-rw-r--r--Lib/sqlite3/test/regression.py19
2 files changed, 19 insertions, 2 deletions
diff --git a/Lib/sqlite3/dbapi2.py b/Lib/sqlite3/dbapi2.py
index 7eb28e8..be7a50a 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(timepart_full[1])
+ microseconds = int('{:0<6}'.format(timepart_full[1].decode()))
else:
microseconds = 0
diff --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py
index eec2fcd..06de982 100644
--- a/Lib/sqlite3/test/regression.py
+++ b/Lib/sqlite3/test/regression.py
@@ -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 @@ class RegressionTests(unittest.TestCase):
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")