如何在web.py中使用随Python安装的sqlite3版本?

1 投票
2 回答
950 浏览
提问于 2025-04-16 12:09

我正在学习 web.py 0.3 的教程,当我看到 这里 时,我使用了 import sqlite3 并设置了 dbn='sqlite3',但是它不工作。有没有人之前做过这个?

编辑 - 我搞定了。我用了 John 发的链接里的代码,写了以下脚本:

import sqlite3

conn = sqlite3.connect('c:\users\user\py\database')
c = conn.cursor()

c.execute('''
CREATE TABLE todo (id integer primary key, title text, created date, done boolean default 'f');
''')
c.execute('''
CREATE TRIGGER insert_todo_created after insert on todo
begin
update todo set created = datetime('now')
where rowid = new.rowid;
end;
''')

c.execute('''
insert into todo (title) values ('Learn web.py');
''')

conn.commit()
c.close()

2 个回答

2

难道不应该只是写 dbn='sqlite' 吗?

1

谷歌是你的好帮手。可以看看这个链接

撰写回答