【问题标题】:PyPyOdbc Correct use of cursorPyPyOdbc 游标的正确使用
【发布时间】:2017-12-23 21:21:34
【问题描述】:

我使用 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()   

这对吗?

谢谢

【问题讨论】:

标签: python pypyodbc


【解决方案1】:

with 关键字就是您要查找的内容

with sqlite3.connect("db.db") as DB:
    cursor = DB.cursor()
    #...perform sql
# connection automatically closes

【讨论】:

    猜你喜欢
    • 2016-02-01
    • 1970-01-01
    • 2016-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多