我使用pypyodbc从ms sql服务器读取数据。
我不确定是否应该在任何查询之后关闭游标,或者只在最后一次关闭游标,但我在文档中找不到任何东西。
示例:
curs = con.cursor()
for id in id_list:
curs.execute ('Select * from XXX where id = {}'.format (id))
curs.fetchall ()
# Write the data into the target...
# curs.close() ???
curs.close() 这是正确的吗?
谢谢
发布于 2017-07-19 05:48:33
with关键字就是您要查找的关键字
with sqlite3.connect("db.db") as DB:
cursor = DB.cursor()
#...perform sql
# connection automatically closeshttps://stackoverflow.com/questions/45176409
复制相似问题