创建我的表:
cursor.execute("""
CREATE TABLE if not exists intraday_quote (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
symbol VARCHAR(10) NOT NULL,
date DATE,
time DATE,
open FLOAT,
high FLOAT,
low FLOAT,
close FLOAT,
volume INTEGER);
""")
我试着插入这个:
conn = sqlite3.connect('intraday_quote.db')
cursor = conn.cursor()
# Prepare SQL query to INSERT a record into the database.
sql = """INSERT INTO intraday_quote(symbol) VALUES ('Mac123432')"""
cursor.execute(sql)
数据库中没有插入。我错过了什么
您需要执行
conn.commit()
以查看数据库中的更改。引用documentation您需要提交更改,以便它们在数据库中生效。 提交所有数据库操作,如update、insert
执行成功后。您可以返回
cursor.execute
。如果不是None
,那么您可以尝试提交更改,否则请使用rollback
(练习:),这样您就不会在数据库中更新错误的数据相关问题 更多 >
编程相关推荐