Strange sqlite3 library behavior

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Sat Feb 2 06:19:22 EST 2008


Victor Lin schreef:
> Now I am now developing a program that base on sqlite3 in python.
> But there is a strange problem.
> That is, all data I insert into sqlite database do not goes into file
> in disk.
> It is really strange....
> Why do these data just keep in memory and discarded?

sqlite3 works according to PEP 249, which means among other things that 
transactions are by default not auto-committed.

There are two possible solutions:
- manually commit the transaction when it's finished with db.commit() 
(perhaps the cursor object also has a commit() method; I'm not sure 
about that)
- enable auto-commit.

For more info, see the sqlite3 docs (especially the section on 
controlling transactions: 
http://docs.python.org/lib/sqlite3-Controlling-Transactions.html) and 
PEP 249 (http://www.python.org/dev/peps/pep-0249/)

-- 
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
   -- Isaac Asimov

Roel Schroeven



More information about the Python-list mailing list