pysqlite,保存数据库,稍后打开
sql 和 sqlite 新手。
我正在尝试保存数据库,然后将 file.db 复制到另一个文件夹并打开它。到目前为止,我创建了数据库,将 file.db 复制并粘贴到另一个文件夹,但是当我尝试访问数据库时,输出显示它是空的。
到目前为止我已经
from pysqlite2 import dbapi2 as sqlite
conn = sqlite.connect('db1Thu_04_Aug_2011_14_20_15.db')
c = conn.cursor()
print c.fetchall()
并且输出是
[]
Newbie to sql and sqlite.
I'm trying to save a database, then copy the file.db to another folder and open it. So far I created the database, copy and pasted the file.db to another folder but when I try to access the database the output says that it is empty.
So far I have
from pysqlite2 import dbapi2 as sqlite
conn = sqlite.connect('db1Thu_04_Aug_2011_14_20_15.db')
c = conn.cursor()
print c.fetchall()
and the output is
[]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你需要类似的东西
You need something like
我将回应 Mat 并指出这不是有效的语法。除此之外,您的示例中不包含任何选择请求(或其他 sql 命令)。如果您的代码中实际上没有 select 语句,并且您在新创建的游标上运行 fetchall,则您可能会得到一个空列表,这似乎就是您所拥有的。
最后,请确保您从正确的目录打开文件。如果你告诉 sqlite 打开一个不存在的文件,它会很乐意为你创建一个新的空文件。
I will echo Mat and point out that is not valid syntax. More than that, you do not include any select request (or other sql command) in your example. If you actually do not have a select statement in your code, and you run fetchall on a newly created cursor, you can expect to get an empty list, which seems to be what you have.
Finally, do make sure that you are opening the file from the right directory. If you tell sqlite to open a nonexistent file, it will happily create a new, empty one for you.