Repository navigation
Expand file tree
/
Copy pathsqlite3Util.py
More file actions
84 lines (56 loc) · 2.18 KB
/
Copy pathsqlite3Util.py
File metadata and controls
84 lines (56 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#author: june
import sqlite3
import globals as G
########################################################################
class Sqlite3Util:
""""""
#----------------------------------------------------------------------
def __init__(self, path):
"""Constructor"""
#db path
self.db_path = path
#conn obj
self.conn = sqlite3.connect(self.db_path)
#cursor obj
self.c = self.conn.cursor()
#----------------------------------------------------------------------
def list_tables(self):
""""""
cmd = "select name from sqlite_master where type = 'table'"
try:
self.c.execute(cmd)
except:
G.log(G.INFO, 'Select \'{}\' failed!File maybe encrypt.'.format(self.db_path))
return None
return self.c.fetchall()
#----------------------------------------------------------------------
def select_all(self, tablename):
""""""
cmd = "select * from {} ".format(tablename)
field = []
records = []
try:
self.c.execute(cmd)
records = self.c.fetchall()
field = [i[0] for i in self.c.description]
except:
idx = self.db_path.rfind('/') + 1
G.log(G.ERROR, 'Fail to check db_file:\'{}\' on table: \'{}\''.format(self.db_path[idx:], tablename))
s = "({})".format(", ".join(field))
#records2 = [dict(zip(field,i)) for i in records]
result = list()
result.append(s)
result.extend(records)
return result#self.c.fetchall()
#----------------------------------------------------------------------
def select_pattern_in_tablename(self, tablename, pattern):
""""""
cmd = "select * from {} where "
#----------------------------------------------------------------------
def dump_db(self):
""""""
return self.conn.iterdump()
#----------------------------------------------------------------------
def close(self):
""""""
self.conn.close()