python mysql执行挂起

时间:2017-05-10 16:52:13

标签: 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 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");

当我执行此功能并尝试更改金额列时,我得到了回复:

Start
FWerte erhalten: [2, 3, 4, 5, 6, 7]
alter table Feuchtigkeitswerte add column Ort_4 NUMERIC, add column Ort_5 NUMERIC, add column Ort_6 NUMERIC

我添加了

print("Checkpoint")

检查,他是否经过了

self._curs.execute(command)
行,但他显然没有通过。我尝试过像autocommit这样的东西,但它不起作用,有人可以帮助我吗?

0 个答案:

没有答案