diff options
author | Petri Lehtinen <petri@digip.org> | 2013-02-26 19:32:02 (GMT) |
---|---|---|
committer | Petri Lehtinen <petri@digip.org> | 2013-02-26 19:38:17 (GMT) |
commit | 5f794098898b49650b2ef6a0c4f48aa0d03b0298 (patch) | |
tree | 9ec7e541c7aefe6c86756138b4b15a47ced052eb /Lib/sqlite3 | |
parent | 7aaa1ef8580660eb6ba94a48ffaf76acbc75a8a6 (diff) | |
download | cpython-5f794098898b49650b2ef6a0c4f48aa0d03b0298.zip cpython-5f794098898b49650b2ef6a0c4f48aa0d03b0298.tar.gz cpython-5f794098898b49650b2ef6a0c4f48aa0d03b0298.tar.bz2 |
Issue #14720: Enhance sqlite3 microsecond conversion, document its behavior
Diffstat (limited to 'Lib/sqlite3')
-rw-r--r-- | Lib/sqlite3/dbapi2.py | 2 | ||||
-rw-r--r-- | Lib/sqlite3/test/regression.py | 13 |
2 files changed, 12 insertions, 3 deletions
diff --git a/Lib/sqlite3/dbapi2.py b/Lib/sqlite3/dbapi2.py index 1048992..9a0b766 100644 --- a/Lib/sqlite3/dbapi2.py +++ b/Lib/sqlite3/dbapi2.py @@ -67,7 +67,7 @@ def register_adapters_and_converters(): timepart_full = timepart.split(b".") hours, minutes, seconds = map(int, timepart_full[0].split(b":")) if len(timepart_full) == 2: - microseconds = int('{:0<6}'.format(timepart_full[1].decode())) + microseconds = int('{:0<6.6}'.format(timepart_full[1].decode())) else: microseconds = 0 diff --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py index 87d2cce..5e2fbf9 100644 --- a/Lib/sqlite3/test/regression.py +++ b/Lib/sqlite3/test/regression.py @@ -313,11 +313,20 @@ class RegressionTests(unittest.TestCase): con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES) cur = con.cursor() cur.execute("CREATE TABLE t (x TIMESTAMP)") + + # Microseconds should be 456000 cur.execute("INSERT INTO t (x) VALUES ('2012-04-04 15:06:00.456')") + + # Microseconds should be truncated to 123456 + cur.execute("INSERT INTO t (x) VALUES ('2012-04-04 15:06:00.123456789')") + cur.execute("SELECT * FROM t") - date = cur.fetchall()[0][0] + values = [x[0] for x in cur.fetchall()] - self.assertEqual(date, datetime.datetime(2012, 4, 4, 15, 6, 0, 456000)) + self.assertEqual(values, [ + datetime.datetime(2012, 4, 4, 15, 6, 0, 456000), + datetime.datetime(2012, 4, 4, 15, 6, 0, 123456), + ]) def suite(): |