开发者

pysqlite, save database, and open it later

开发者 https://www.devze.com 2023-03-26 04:53 出处:网络
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开发者_如何学C created the database, copy and pasted the file.db to another folde

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开发者_如何学C 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

[]


You need something like

c.execute("SELECT * FROM mytable")
for row in c:
    #process row


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消