-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
67 lines (60 loc) · 1.36 KB
/
database.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
# 在Oppressor完成以后请不要直接使用这里面的函数
# 详细请看oppressor.py中的select/insert/update
from pymysql import connect, cursors
import traceback # 更好的错误输出
# (临时的)设置,记得改密码!
conn = connect(
host = "127.0.0.1",
user = "zvms",
password = "123456",
db = "zvms"
)
cur = conn.cursor()
def close(): # 这玩意有被用到吗?
global conn,cur
try:
cur.close()
conn.close()
except:
traceback.print_exc()
def test_connection():
global conn, cur
try:
conn.ping()
except:
conn = connect(
host = "127.0.0.1",
user = "zvms",
password = "123456",
db = "zvms"
)
cur = conn.cursor()
def execute(sql, param = None):
test_connection()
print("sql =", sql)
print("param =", param)
global cur, conn
try:
cur.execute(sql, param)
conn.commit()
except:
traceback.print_exc()
conn.rollback()
def fetchall():
test_connection()
global cur
try:
r=cur.fetchall()
conn.commit()
return r
except:
traceback.print_exc()
def fetchone():
test_connection()
global cur
try:
r=cur.fetchone()
conn.commit()
return r
except:
traceback.print_exc()