-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathdb.py
89 lines (75 loc) · 2.32 KB
/
db.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import os.path
import sqlite3
from models import *
from settings import magicalpath
def create_connection():
db = sqlite3.connect(magicalpath)
return db
def select_process():
db = create_connection()
con = db.cursor()
con.execute("select * from process")
res = con.fetchall()
con.close()
db.close()
return res
def select_process_name(processName:str)->Process:
db = create_connection()
con = db.cursor()
con.execute("select * from process where processName=?",(processName,))
res = con.fetchone()
con.close()
db.close()
return res
def select_process_id(processId:str)->Process:
db = create_connection()
con = db.cursor()
con.execute("select * from process where processId=?",(processId,))
res = con.fetchone()
con.close()
db.close()
return res
def insert_process(process:Process)->Process:
db = create_connection()
cursor = db.cursor()
try:
cursor.execute("insert into process(processId, processName, processUrl, createTime) values ('%s','%s','%s','%s')" % (process.processId, process.processName, process.processUrl,datetime.datetime.now()))
db.commit()
cursor.close()
db.close()
return process
except Exception as e:
print(e)
db.rollback()
cursor.close()
db.close()
def delete_process(process_name):
db = create_connection()
cursor = db.cursor()
try:
cursor.execute("delete FROM process where processName ='%s'" % (process_name))
db.commit()
cursor.close()
db.close()
except Exception as e:
db.rollback()
cursor.close()
db.close()
def delete_process_id(processId):
db = create_connection()
cursor = db.cursor()
try:
cursor.execute("delete FROM process where processId ='%s'" % (processId))
db.commit()
cursor.close()
db.close()
except Exception as e:
db.rollback()
cursor.close()
db.close()
if __name__ == '__main__':
if not os.path.exists(magicalpath):
con = sqlite3.connect(magicalpath)
cursor = con.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS `process`(`processId` VARCHAR(90),`processName` VARCHAR(90) UNIQUE,`processUrl` VARCHAR(256),`createTime` DATA,`baseUrl` VARCHAR(256));")
con.commit()