-
Notifications
You must be signed in to change notification settings - Fork 0
/
patchDB.py
62 lines (51 loc) · 1.45 KB
/
patchDB.py
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
#!/bin/python3
#// Author: Thomas Grothe, [email protected]
#// 2024/2/22
import sys
import csv
import sqlite3 as sq
#a simple abstraction between a sqlite db and patch code
patches = [] #associate id with filename and other attributes
db = sq.connect('patches.db')
dbc = db.cursor()
res = dbc.execute('SELECT name FROM sqlite_master WHERE name="patches"')
if res.fetchone() == None:
res = dbc.execute('CREATE TABLE patches(hash,filename,tag)')
def __init__():
global db
global dbc
try:
db = sq.connect('patches.db')
dbc = db.cursor()
except sq.ProgrammingError:
return None
def get_patches():
try:
res = dbc.execute('SELECT * FROM patches')
return res.fetchall()
except sq.ProgrammingError:
return None
def add_patch(pchID, filename, tag=None):
try:
res = dbc.execute('INSERT INTO patches(hash,filename) VALUES(?,?)', (pchID, filename))
db.commit()
return res
except sq.ProgrammingError:
return None
def remove_patch(pchID):
try:
res = db.execute(f'DELETE FROM patches WHERE hash={pchID}')
db.commit()
return res
except sq.ProgrammingError:
return None
def set_patch_tag(pchID, tag):
try:
res = dbc.execute(f'UPDATE patches SET tag={tag} WHERE hash={pchID}')
db.commit()
return res
except sq.ProgrammingError:
return None
def close():
dbc.close()
db.close()