Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
website
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jannik Hellenkamp
website
Commits
bffb4913
Commit
bffb4913
authored
8 years ago
by
Julian Rother
Browse files
Options
Downloads
Patches
Plain Diff
Strip microseconds in query parameters
parent
7b01c4e7
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
db.py
+7
-6
7 additions, 6 deletions
db.py
with
7 additions
and
6 deletions
db.py
+
7
−
6
View file @
bffb4913
from
server
import
*
from
server
import
*
import
sqlite3
import
sqlite3
import
re
import
re
import
datetime
if
config
[
'
DB_ENGINE
'
]
==
'
sqlite
'
:
if
config
[
'
DB_ENGINE
'
]
==
'
sqlite
'
:
created
=
not
os
.
path
.
exists
(
config
[
'
SQLITE_DB
'
])
created
=
not
os
.
path
.
exists
(
config
[
'
SQLITE_DB
'
])
...
@@ -31,11 +30,7 @@ def convert_timestamp(val):
...
@@ -31,11 +30,7 @@ def convert_timestamp(val):
year
,
month
,
day
=
map
(
int
,
datepart
.
split
(
b
"
-
"
))
year
,
month
,
day
=
map
(
int
,
datepart
.
split
(
b
"
-
"
))
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
:
val
=
datetime
(
year
,
month
,
day
,
hours
,
minutes
,
seconds
,
0
)
microseconds
=
int
(
'
{:0<6.6}
'
.
format
(
timepart_full
[
1
].
decode
()))
else
:
microseconds
=
0
val
=
datetime
.
datetime
(
year
,
month
,
day
,
hours
,
minutes
,
seconds
,
microseconds
)
except
ValueError
:
except
ValueError
:
val
=
None
val
=
None
return
val
return
val
...
@@ -44,6 +39,12 @@ sqlite3.register_converter('datetime', convert_timestamp)
...
@@ -44,6 +39,12 @@ sqlite3.register_converter('datetime', convert_timestamp)
sqlite3
.
register_converter
(
'
timestamp
'
,
convert_timestamp
)
sqlite3
.
register_converter
(
'
timestamp
'
,
convert_timestamp
)
def
query
(
operation
,
*
params
):
def
query
(
operation
,
*
params
):
_params
=
[]
for
p
in
params
:
if
isinstance
(
p
,
datetime
):
p
=
p
.
replace
(
microsecond
=
0
)
_params
.
append
(
p
)
params
=
_params
if
config
[
'
DB_ENGINE
'
]
==
'
mysql
'
:
if
config
[
'
DB_ENGINE
'
]
==
'
mysql
'
:
import
mysql.connector
import
mysql.connector
if
'
db
'
not
in
g
or
not
g
.
db
.
is_connected
():
if
'
db
'
not
in
g
or
not
g
.
db
.
is_connected
():
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment