cursor.executemany(...)的pymssql模块有一个有保证的执行顺序吗?
import pymssql
# Example retrieved from: http://pymssql.org/en/stable/pymssql_examples.html
# ...
conn = pymssql.connect(server, user, password, "tempdb")
cursor = conn.cursor()
# ...
cursor.executemany(
"INSERT INTO persons VALUES (%d, %s, %s)",
[(1, 'John Smith', 'John Doe'),
(2, 'Jane Doe', 'Joe Dog'),
(3, 'Mike T.', 'Sarah H.')])
conn.commit()
conn.close()另见:examples.html
在实际场景中,我需要按特定顺序更新值(我有一个有序的元组数组),并且希望避免使用cursor.execute(...)逐个执行这些更新。
看来PEP 249的要求是非常开放的.
准备一个数据库操作(查询或命令),然后针对序列seq_of_parameters中的所有参数序列或映射执行它。 模块可以使用对.execute()方法的多次调用来实现该方法,或者使用数组操作让数据库在一个调用中作为一个整体处理整个序列。
https://www.python.org/dev/peps/pep-0249/#executemany
这引发了另一个问题..。pymssql对PEP 249的实现是否用cursor.execute(...)逐一执行?
发布于 2019-07-26 14:00:45
def (self,across,params_seq):self.description =无行号=0用于params_seq: self.execute(操作,params) #支持多个执行行号+= self._rownumber self._rownumber =行号的正确行计数
根据源代码,executemany函数只是迭代给定的序列并调用execute。
https://stackoverflow.com/questions/57221116
复制相似问题