Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e55aa69e
Commit
e55aa69e
authored
Feb 26, 2013
by
Petri Lehtinen
Browse files
Options
Browse Files
Download
Plain Diff
Issue #14720: Enhance sqlite3 microsecond conversion, document its behavior
parents
8ff7f720
6401ad66
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
3 deletions
+16
-3
Doc/library/sqlite3.rst
Doc/library/sqlite3.rst
+4
-0
Lib/sqlite3/dbapi2.py
Lib/sqlite3/dbapi2.py
+1
-1
Lib/sqlite3/test/regression.py
Lib/sqlite3/test/regression.py
+11
-2
No files found.
Doc/library/sqlite3.rst
View file @
e55aa69e
...
...
@@ -842,6 +842,10 @@ The following example demonstrates this.
.. literalinclude:: ../includes/sqlite3/pysqlite_datetime.py
If a timestamp stored in SQLite has a fractional part longer than 6
numbers, its value will be truncated to microsecond precision by the
timestamp converter.
.. _sqlite3-controlling-transactions:
...
...
Lib/sqlite3/dbapi2.py
View file @
e55aa69e
...
...
@@ -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
...
...
Lib/sqlite3/test/regression.py
View file @
e55aa69e
...
...
@@ -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
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment