[Python-checkins] cpython (merge 3.3 -> default): Issue #14720: sqlite3: Convert datetime microseconds correctly
petri.lehtinen
python-checkins at python.org
Sat Feb 23 19:12:49 CET 2013
http://hg.python.org/cpython/rev/6342055ac220
changeset: 82351:6342055ac220
parent: 82347:4e2bfe6b227a
parent: 82350:46c96693296f
user: Petri Lehtinen <petri at digip.org>
date: Sat Feb 23 19:10:29 2013 +0100
summary:
Issue #14720: sqlite3: Convert datetime microseconds correctly
files:
Lib/sqlite3/dbapi2.py | 2 +-
Lib/sqlite3/test/regression.py | 17 +++++++++++++++++
Misc/ACKS | 1 +
Misc/NEWS | 3 +++
4 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/Lib/sqlite3/dbapi2.py b/Lib/sqlite3/dbapi2.py
--- a/Lib/sqlite3/dbapi2.py
+++ b/Lib/sqlite3/dbapi2.py
@@ -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 --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py
--- a/Lib/sqlite3/test/regression.py
+++ b/Lib/sqlite3/test/regression.py
@@ -302,6 +302,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 --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1192,6 +1192,7 @@
Mikhail Terekhov
Richard M. Tew
Tobias Thelen
+Lowe Thiderman
Nicolas M. Thiéry
James Thomas
Robin Thomas
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -260,6 +260,9 @@
Library
-------
+- Issue #14720: sqlite3: Convert datetime microseconds correctly.
+ Patch by Lowe Thiderman.
+
- Issue #15132: Allow a list for the defaultTest argument of
unittest.TestProgram. Patch by Jyrki Pulliainen.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list