python mysql执行挂起
我正在使用python控制我的mysql数据库,用于一个自动花园浇水项目 我正在使用MySQLdb,一切正常,但最近我遇到了一个错误python mysql执行挂起,python,mysql,Python,Mysql,我正在使用python控制我的mysql数据库,用于一个自动花园浇水项目 我正在使用MySQLdb,一切正常,但最近我遇到了一个错误 def changeSize(self, size, table): command = "select * from Feuchtigkeitswerte order by ID desc limit 1" self._curs.execute(command) lastRow = self._curs.fetchone() if
def changeSize(self, size, table):
command = "select * from Feuchtigkeitswerte order by ID desc limit 1"
self._curs.execute(command)
lastRow = self._curs.fetchone()
if len(lastRow)-3 < size:
command = "alter table Feuchtigkeitswerte "
for x in range(len(lastRow)-2, size):
command += "add column Ort_{:d} NUMERIC, ".format(x)
command += "add column Ort_{:d} NUMERIC".format(size)
print command
if len(lastRow)-3 > size:
command = "alter table Feuchtigkeitswerte "
for x in range(size+1,len(lastRow)-3):
command += "drop Ort_{:d}, ".format(x)
command += "drop Ort_{:d}".format(len(lastRow)-3)
print command
self._curs.execute("SET autocommit=1");
self._curs.execute(command)
print("Checkpoint");
self._curs.execute("SET autocommit=0");
我加了一行
print("Checkpoint")
检查一下,他是否通过了考试
self._curs.execute(command)
但他显然没有通过。我尝试了自动提交之类的几种方法,但都不起作用,有人能帮我吗?我忘了补充一点,如果我复制函数正在打印的命令并将其粘贴到mysql控制台,它就不会挂起,也不会返回任何错误。我不清楚您的实际问题是什么。您希望发生什么?一个
altertable
可能需要很长很长时间。与其添加更多的列,不如找到一个不需要不断更改表的数据库架构。因此,我的问题是,程序在这一点上挂起,它没有通过这一点,因为它在这一点上执行了self.\u curs.execute(command)
和@KlausD.:我在mysql控制台上试过,没花那么长时间。。。
self._curs.execute(command)