Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
I
install.api
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Script
install.api
Commits
f83c54b6
Commit
f83c54b6
authored
Mar 13, 2020
by
金凯强
🎨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
id转字符串
parent
0d68353f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
1 deletion
+21
-1
db_tools.py
app/utils/db_tools.py
+21
-1
No files found.
app/utils/db_tools.py
View file @
f83c54b6
...
@@ -47,7 +47,7 @@ class DBDriver:
...
@@ -47,7 +47,7 @@ class DBDriver:
self
.
dbfile
=
dbfile
self
.
dbfile
=
dbfile
def
cerateDB
(
self
):
def
cerateDB
(
self
):
self
.
conn
=
sqlite3
.
connect
(
self
.
dbfile
,
check_same_thread
=
False
)
self
.
conn
=
sqlite3
.
connect
(
self
.
dbfile
,
check_same_thread
=
False
)
# self.conn.isolation_level = None
# self.conn.isolation_level = None
for
create_table_sql
in
create_table_sql_list
:
for
create_table_sql
in
create_table_sql_list
:
self
.
conn
.
execute
(
create_table_sql
)
####create new table
self
.
conn
.
execute
(
create_table_sql
)
####create new table
...
@@ -70,6 +70,8 @@ class DBDriver:
...
@@ -70,6 +70,8 @@ class DBDriver:
if
res
is
None
:
if
res
is
None
:
return
res
return
res
res
=
self
.
format_result
(
res
)
res_dict
=
dict
(
map
(
lambda
x
,
y
:
[
x
,
y
],
fields
,
res
))
res_dict
=
dict
(
map
(
lambda
x
,
y
:
[
x
,
y
],
fields
,
res
))
cur
.
close
()
cur
.
close
()
return
res_dict
return
res_dict
...
@@ -78,6 +80,9 @@ class DBDriver:
...
@@ -78,6 +80,9 @@ class DBDriver:
cur
=
self
.
exec_sql
(
sql
,
*
args
,
**
kwargs
)
cur
=
self
.
exec_sql
(
sql
,
*
args
,
**
kwargs
)
fields
=
[
item
[
0
]
for
item
in
cur
.
description
]
fields
=
[
item
[
0
]
for
item
in
cur
.
description
]
res
=
cur
.
fetchall
()
res
=
cur
.
fetchall
()
res
=
self
.
format_result
(
res
)
res_list
=
[]
res_list
=
[]
for
r
in
res
:
for
r
in
res
:
res_dict
=
OrderedDict
(
map
(
lambda
x
,
y
:
[
x
,
y
],
fields
,
r
))
res_dict
=
OrderedDict
(
map
(
lambda
x
,
y
:
[
x
,
y
],
fields
,
r
))
...
@@ -97,5 +102,20 @@ class DBDriver:
...
@@ -97,5 +102,20 @@ class DBDriver:
self
.
conn
.
commit
()
self
.
conn
.
commit
()
self
.
conn
.
close
()
self
.
conn
.
close
()
def
format_result
(
self
,
res
):
item_list
=
[]
if
isinstance
(
res
,
list
):
for
r
in
res
:
item_list
.
append
(
self
.
format_result
(
r
))
elif
isinstance
(
res
,
tuple
):
for
r
in
res
:
if
isinstance
(
r
,
int
):
item_list
.
append
(
str
(
r
))
else
:
item_list
.
append
(
r
)
else
:
item_list
=
res
return
item_list
db_driver
=
DBDriver
()
db_driver
=
DBDriver
()
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