如何将Python安装附带的sqlite3版本与web.py一起使用?
我正在浏览 web.py 0.3 教程,一旦我得到这里我导入sqlite3
并设置 dbn='sqlite3'
但它不起作用。以前有人这样做过吗?
编辑-我想通了。我使用了约翰发布的链接中的代码并制作了以下脚本:
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()
I'm going through the web.py 0.3 tutorials and once I get here I import sqlite3
and set dbn='sqlite3'
but it won't work. Has anyone done this before?
Edit - I figured it out. I used the code in the link posted by John and made the following script:
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
难道不应该只是
dbn='sqlite'
吗?Shouldn't it be just
dbn='sqlite'
?谷歌是你的朋友。看看这个。
Google is your friend. Look at this.