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
| import os,sys
import RPi.GPIO as GPIO
import time
import threading
class CreationSql(QtCore.QThread): # Thread de creation Table SQL
def __init__(self, parent, NomSQL):
super(CreationSql, self).__init__(parent) # Permet la transmission de parametre entre la class fenetre et le QThread
self.NomSQL = NomSQL # Transmission de la variable NomSQL
def run(self):
try:
mydb = mc.connect(
host="localhost",
user=USER.strip(),
password=MDP.strip(),
database="RADIORT",
charset='utf8mb4'
)
mycursor = mydb.cursor()
query = "SHOW TABLES LIKE '" + self.NomSQL + "'"
mycursor.execute(query)
result = mycursor.fetchone()
if result:
pymsgbox.alert("La table exist", "Nom Table SQL")
else:
query = "CREATE TABLE IF NOT EXISTS " + self.NomSQL + " (time bigint(30) NOT NULL, BdfMoy int(6) DEFAULT NULL, MesMoy int(6) DEFAULT NULL, MesNet int(6) DEFAULT NULL)"
mycursor.execute(query)
mydb.commit()
pymsgbox.alert("La table à etait creer", "Nom Table SQL")
except mc.Error as e:
print("echec")
finally:
mydb.close() |
Partager