首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pymssql的cursor.executemany()

pymssql的cursor.executemany()
EN

Stack Overflow用户
提问于 2019-07-26 13:30:37
回答 1查看 248关注 0票数 0

cursor.executemany(...)pymssql模块有一个有保证的执行顺序吗?

代码语言:javascript
复制
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(...)逐一执行?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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://github.com/pymssql/pymssql/blob/891b20e29e4e247c17b202e8e34e5c739b6090ef/src/pymssql.pyx#L472

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57221116

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档