-
Notifications
You must be signed in to change notification settings - Fork 0
/
manageMysql.py
128 lines (120 loc) · 5.06 KB
/
manageMysql.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import pymysql
def show_leakrate():
db = pymysql.connect("localhost", "root", "021213", "optorun")
cursor = db.cursor()
sql = "SELECT 0_min,1_min,2_min,3_min,4_min,5_min,\
6_min,7_min,8_min,9_min,10_min,11_min,12_min,13_min,\
14_min,15_min,16_min,17_min,18_min,19_min,20_min from LeakRate;"
try:
cursor.execute(sql)
result = cursor.fetchall()
return result
except:
print("Error: leakrate unable fetch data")
db.close()
def show_exhaust_nor():
db = pymysql.connect("localhost", "root", "021213", "optorun")
cursor = db.cursor()
sql = "SELECT aa,bb,cc,dd,ee,ff,\
gg,hh,ii,jj,kk,ll,mm from Exhaust_nor;"
try:
cursor.execute(sql)
result = cursor.fetchall()
return result
except:
print("Error:exhaust_nor unable fetch data")
db.close()
def show_exhaust_150():
db = pymysql.connect("localhost", "root", "021213", "optorun")
cursor = db.cursor()
sql = "SELECT aa,bb,cc,dd,ee,ff,\
gg,hh,ii,jj,kk,ll,mm from Exhaust_150;"
try:
cursor.execute(sql)
result = cursor.fetchall()
return result
except:
print("Error:exhaust_nor unable fetch data")
db.close()
def insert_leakrate(serial_no,coater_style,times):
db = pymysql.connect("localhost", "root", "021213", "optorun")
cursor = db.cursor()
sql = "INSERT INTO LeakRate (SerialNo,Coater_Style,0_min,1_min,2_min,3_min,4_min,5_min," \
"6_min,7_min,8_min,9_min,10_min,11_min,12_min,13_min,14_min,15_min," \
"16_min,17_min,18_min,19_min,20_min) values ('%s','%s'," \
"%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s," \
"%s,%s,%s)" %(serial_no,coater_style,times[0],times[1],times[2],times[3],times[4],
times[5],times[6],times[7],times[8],times[9],
times[10],times[11],times[12],times[13],times[14],times[15],
times[16],times[17],times[18],times[19],times[20])
try:
cursor.execute(sql)
db.commit()
except:
print("存入表insert_leakrate失败")
db.rollback()
db.close()
def insert_exhaust_nor(serial_no,coater_style,exhaust_nor_data):
db = pymysql.connect("localhost", "root", "021213", "optorun")
cursor = db.cursor()
sql = "INSERT INTO Exhaust_nor (SerialNo,Coater_Style,aa,bb,cc,dd,ee,ff,gg," \
"hh,ii,jj,kk,ll,mm) values ('%s','%s',%s,%s,%s,%s,%s,%s,%s," \
"%s,%s,%s,%s,%s,%s)" %(serial_no,coater_style,exhaust_nor_data[0],exhaust_nor_data[1],
exhaust_nor_data[2],exhaust_nor_data[3],exhaust_nor_data[4],
exhaust_nor_data[5],exhaust_nor_data[6],exhaust_nor_data[7],
exhaust_nor_data[8],exhaust_nor_data[9],exhaust_nor_data[10],
exhaust_nor_data[11],exhaust_nor_data[12])
try:
cursor.execute(sql)
db.commit()
except:
print("存入表insert_exhaust_nor失败")
db.rollback()
db.close()
def insert_exhaust_150(serial_no,coater_style,exhaust_150_data):
db = pymysql.connect("localhost", "root", "021213", "optorun")
cursor = db.cursor()
sql = "INSERT INTO Exhaust_150 (SerialNo,Coater_Style,aa,bb,cc,dd,ee,ff,gg," \
"hh,ii,jj,kk,ll,mm) values ('%s','%s',%s,%s,%s,%s,%s,%s,%s," \
"%s,%s,%s,%s,%s,%s)" %(serial_no,coater_style,exhaust_150_data[0],exhaust_150_data[1],
exhaust_150_data[2],exhaust_150_data[3],exhaust_150_data[4],
exhaust_150_data[5],exhaust_150_data[6],exhaust_150_data[7],
exhaust_150_data[8],exhaust_150_data[9],exhaust_150_data[10],
exhaust_150_data[11],exhaust_150_data[12])
try:
cursor.execute(sql)
db.commit()
except:
print("存入表insert_exhaust_150失败")
db.rollback()
db.close()
def inquire_mode_2(machine_no, selected_mode):
db = pymysql.connect("localhost", "root", "021213", "optorun")
cursor = db.cursor()
if selected_mode == '抽速(室温)':
sql = "SELECT * FROM Exhaust_nor WHERE SerialNo = '%s'" % (machine_no)
elif selected_mode == '抽速(150℃)':
sql = "SELECT * FROM Exhaust_150 WHERE SerialNo = '%s'" % (machine_no)
else:
sql = "SELECT * FROM Leakrate WHERE SerialNo = '%s'" % (machine_no)
try:
cursor.execute(sql)
result = cursor.fetchall()
return result
except:
print("Error:exhaust_nor unable fetch data")
db.close()
def show_machine_no():
db = pymysql.connect("localhost", "root", "021213", "optorun")
cursor = db.cursor()
sql = "SELECT SerialNo FROM Exhaust_nor"
try:
cursor.execute(sql)
result = cursor.fetchall() # 未经处理的数据库的数据
except:
print("Error:show_machine_no unable fetch data")
buffer = [] # 用来存数据库中获取的数据
for item in result:
buffer.append(item[0])
return buffer
db.close()