我正在尝试使用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)
答案 0 :(得分:4)
MySQLdb
和
mysql-connector
是两个
用于Python的独立,独立的MySQL数据库适配器。
这两个适配器都符合DB API specification versions 2.0。
multi
关键字参数不属于标准数据库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