0

Tengo un script en Python bastante sencillo, dónde inserto un registro en Mysql, pero por alguna razón, no se está insertando, y no me da error alguno, ya que ejecuta el print(sql)

Es raro, porque si cambio la sentencia por TRUNCATE TEMPERATURE funciona perfecto y trunca la tabla

class DataBase:
    def __init__(self):
        self.connection = pymysql.connect(
            host='localhost',
            user='root',
            password='',
            db='home'
        )

        self.cursor = self.connection.cursor()
    
    def insert_temperature(self, date, temperature, humidity):
        sql = "INSERT INTO TEMPERATURE (DATE, TEMPERATURE, HUMIDITY) VALUES ('{}', '{}', '{}')".format(now, temperature_c, humidity)
        
        try:
            self.cursor.execute(sql)
            print(sql)

        except Exception as e:
            raise

dhtDevice = adafruit_dht.DHT11(board.D2)
temperature_c = dhtDevice.temperature
humidity = dhtDevice.humidity
now = '2020-12-18'

database = DataBase()
database.insert_temperature(now, temperature_c, humidity)

1 respuesta 1

0

Lo he solucionado, me faltaba añadir commit()

self.cursor.execute(sql)
self.connection.commit()

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.