小编Bob*_*Bob的帖子

SQLite不在使用之间保存数据

我制作了一个包含以下内容的模块:

import sqlite3 as sq
connection = sq.connect("test.db")
cursor = connection.cursor()
cursor.execute("DROP TABLE IF EXISTS test")
cursor.execute("CREATE TABLE test (st TEXT)")
cursor.execute("INSERT INTO test VALUES ('testing')")
cursor.execute("SELECT * FROM test")
print(cursor.fetchall())
cursor.close()
connection.close()
connection2 = sq.connect("test.db")
cursor2 = connection2.cursor()
cursor2.execute("SELECT * FROM test")
print(cursor2.fetchall())
Run Code Online (Sandbox Code Playgroud)

但当我运行它时,它打印了以下内容:

[('testing',)]
[]
Run Code Online (Sandbox Code Playgroud)

它应该打印:

[('testing',)]
[('testing',)]
Run Code Online (Sandbox Code Playgroud)

怎么了?

python sqlite python-3.x

5
推荐指数
1
解决办法
3813
查看次数

标签 统计

python ×1

python-3.x ×1

sqlite ×1