-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuery.py
35 lines (32 loc) · 1.12 KB
/
Query.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
#!C:\Python\python.exe
from Connection import Connection
class On():
def execute(self):
try:
conn = Connection("localhost", "root", "", "db")
mydb = conn.connect()
mycursor = mydb.cursor()
sql = "UPDATE state SET state = 'ON' WHERE ID = 1;"
mycursor.execute(sql)
mydb.commit()
# print("State updated to ON in the database")
except mysql.connector.Error as err:
print("Error: {}".format(err))
finally:
mycursor.close()
mydb.close()
class Off():
def execute(self):
try:
conn = Connection("localhost", "root", "", "db")
mydb = conn.connect()
mycursor = mydb.cursor()
sql = "UPDATE state SET state = 'OFF' WHERE ID = 1;"
mycursor.execute(sql)
mydb.commit()
# print("State updated to OFF in the database")
except mysql.connector.Error as err:
print("Error: {}".format(err))
finally:
mycursor.close()
mydb.close()