【发布时间】:2021-10-13 00:25:30
【问题描述】:
我有一个功能,您可以在下面看到。如果运行这个函数我会得到你可以在标题中看到的错误,你能帮我吗?
不久前我能够用锁解决这个问题,但现在它们不起作用。我知道这与我的连接有关,但我不知道如何解决这个问题
def insertNewValues(self,uselessInput):
self.lock.acquire()
self.connection.reconnect()
mycursor = self.connection.cursor()
query=f"SELECT {self.roomSelect(self.roomNames)} ,time FROM alldata ORDER BY ID DESC LIMIT 1"
mycursor.execute(query,)
records = mycursor.fetchall()
oldValues=[elem for elem in records[0]]
time=self.addMin(oldValues[-1])
del oldValues[-1]
newValues=[self.randomIncreaseDecrease(elem) for elem in oldValues]
query=f"DELETE FROM temp_minutes LIMIT 1"
mycursor.execute(query,)
self.connection.commit()
mycursor.close()
mycursor = self.connection.cursor()
query=f"""
BEGIN;
INSERT INTO alldata ({self.roomSelect(self.roomNames)}, time)
VALUES {*newValues,str(time)};
INSERT INTO temp_minutes ({self.roomSelect(self.roomNames)}, time)
VALUES {*newValues,str(time)};
COMMIT;
"""
mycursor.execute(query,)
self.connection.commit()
mycursor.close()
self.lock.release()
【问题讨论】:
-
你已经在python中有一个事务为什么oyu还要添加另一个查询运行
标签: mysql mysql-python mysql-connector