这是一个创建于 3958 天前的主题,其中的信息可能已经有所发展或是发生改变。
Sqlite数据库,在最后需要关闭数据库。以前也一直使用并以为直接关闭数据库就好了。
但是,
我在看文档的时候,发现官方文档 有些地方 会去关闭游标cursor。为什么需要关闭游标?
--- --- --- --- --- --- 直接关闭数据库 --- --- --- --- --- ---
import sqlite3
conn = sqlite3.connect('example.db')
cur = conn.cursor()
... ...
conn.close()
--- --- --- --- --- --- 关闭连接前,关闭游标cursor --- --- --- --- --- ---
import sqlite3
conn = sqlite3.connect(example'.db')
cur = conn.cursor()
... ...
cur.close()
conn.close()
这个有区别吗?
查了资料,有些说需要,有些说不用。我一直没关闭cursor,目前还没有出什么大问题,有些小问题不知道是不是这个细节引起的
文档:http://docs.python.org/2/library/sqlite3.html
2 条回复 • 2021-02-25 11:40:08 +08:00
|
|
2
imgbed 2021-02-25 11:40:08 +08:00
@ wuqiangroy 会占多少资源?如果占得不多,我觉得没必要关闭,不然可能 bug 更多
|