MySQLdb.cursor.execute can't run multiple queries

前端 未结 7 1336
暗喜
暗喜 2020-12-06 05:11

We\'re trying to run SQL files containing multiple insert statements as a single query, but it seems rollback fails when any of the statements contain an error.

相关标签:
7条回答
  • 2020-12-06 05:58
    for _ in cursor.execute(query, multi=True): 
        pass
    

    This works for me!

    And according to the doc, this is the right thing to do, cursor.execute() returns an iterator and only when the contents in the iterator is consumed, will the commit be successful.

    0 讨论(0)
提交回复
热议问题