-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBOperate.py
More file actions
61 lines (57 loc) · 1.55 KB
/
Copy pathDBOperate.py
File metadata and controls
61 lines (57 loc) · 1.55 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
filedb = {
'PATH' : '',
'STAT' : '',
'MD5' : '',
'Rule_Type' : '',
'Rule_Check' : '',
'Record' : 'o'
}
recordmap = {
'a':'ADDED',
'm':'MODIFIED',
'o':'REMOVED'
}
def SQLcreatetable(c,tablename):
try:
c.execute('''DROP TABLE %s;''' % tablename)
except:
pass
SQLCreat = '''CREATE TABLE %s
(PATH char(600) PRIMARY KEY NOT NULL,
STAT char NOT NULL,
MD5 char,
Rule_Type char,
Rule_Check char,
Record char(1));
''' % tablename
c.execute(SQLCreat)
print('数据表创建成功',tablename)
def SQLupdate(tablename,path,data:dict):
str = ''
SQLUpdate1 = "UPDATE %s SET " %tablename
SQLUpdate2="WHERE PATH='%s'" %path
for i in data:
str = str+i+"='"+data[i]+"',"
str = str[:-1]
SQLUpdate = SQLUpdate1+str+SQLUpdate2
return SQLUpdate
def SQLinsert(tablename,data):
SQLInsert1 = "INSERT INTO %s " %tablename
SQLInsert2 = ''
SQLInsert3 = ''
for i in data:
SQLInsert2 = SQLInsert2+i+','
SQLInsert2=SQLInsert2[:-1]
for i in data:
SQLInsert3 = SQLInsert3+"'"+data[i]+"'"+','
SQLInsert3 = SQLInsert3[:-1]
SQLInsert = SQLInsert1+'('+SQLInsert2+')VALUES('+SQLInsert3+');'
return SQLInsert
def queryFileData(c,tablename,path):
SQLQuery = "select * from %s where path=\'%s\'"%(tablename,path)
c.execute(SQLQuery)
values = c.fetchall()
if values==[]:
return None
else:
return values[0]