为什么意外的关键字' multi'在Python的MySQLdb模块中?

时间:2016-02-10 17:55:29

标签: python mysql-connector-python

我正在尝试使用MySQLdb模块删除数据库中的记录。在https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-execute.html中,我发现multi=True用于在执行中执行多个查询,但它会生成错误。有人能帮助我知道我所缺少的东西吗?

query = "DELETE FROM Service_Machine WHERE Id=(SELECT Id FROM Machines WHERE Id="+id+");" \
        "DELETE FROM Machine_Usage WHERE Id=(SELECT Id FROM Machines WHERE Id="+id+");" \
        "DELETE FROM Machines WHERE Id="+id+");
print(query)
self.cursor.execute(query, multi=True)

3 个答案:

答案 0 :(得分:4)

MySQLdbmysql-connector是两个 用于Python的独立,独立的MySQL数据库适配器。

这两个适配器都符合DB API specification versions 2.0multi关键字参数不属于标准数据库API,也不属于MySQLdb API。

只有mysql-connector的{​​{3}}个multi关键字参数。

答案 1 :(得分:0)

试试这个:

InSql1 = "DELETE FROM Service_Machine WHERE Id=(SELECT Id FROM Machines WHERE Id="+id+");" 
InSql2 = "DELETE FROM Machine_Usage WHERE Id=(SELECT Id FROM Machines WHERE Id="+id+");" 
InSql3 =  "DELETE FROM Machines WHERE Id="+id+");
#print(query)

self.cursor.execute(InSql1)
self.cursor.execute(InSql2)
self.cursor.execute(InSql3)
self.cursor.execute("Commit;")

答案 2 :(得分:0)

请改用以下方法

MyDocument