gpt4 book ai didi

python - Firefox 和 Python 上的 SQLite 管理器

转载 作者:太空宇宙 更新时间:2023-11-03 17:28:58 25 4
gpt4 key购买 nike

我使用 SQLite 和 Python 3.3 编写了一个小型测试应用程序:

import sqlite3

MDB = sqlite3.connect('D:\MDB.db') # create the db object
cursor = MDB.cursor() # assign a cursor

cursor.execute('''CREATE TABLE IF NOT EXISTS section (
Code INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
Description TEXT )
''')

cursor.execute('''DELETE FROM section''') # delete contents for reruns

cursor.execute('''INSERT INTO section
(Description)
VALUES (?)
''', ('Abdul, Paula',))

cursor.execute('''INSERT INTO section
(Description)
VALUES (?)
''', ('ABWH',))


print('Results:\n')
cursor.execute('''SELECT * FROM section''')
selection = cursor.fetchall()
for row in selection:
print('\t', row)

SELECT 语句显示了预期的结果(似乎表明该行存在),但是如果我使用 SQLite-Manager 连接到数据库,该表存在但为空,并且如果我尝试使用连接的另一个脚本进行相同的查询到数据库,没有返回任何内容。谁能解释一下我做错了什么?

最佳答案

您没有保存更改(调用 MDB.commit)。

关于python - Firefox 和 Python 上的 SQLite 管理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32173029/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com