Commit f83c54b6 authored by 金凯强's avatar 金凯强 🎨

id转字符串

parent 0d68353f
...@@ -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()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment