Simple sqlite3 question

Jerry Hill malaclypse2 at gmail.com
Tue Apr 24 14:03:39 EDT 2007


On 24 Apr 2007 10:03:45 -0700, cjl <cjlesh at gmail.com> wrote:
> When I run the script and there is no file named optiondata, one is
> created and the correct data is added to it.  If I run the script
> again then the data from the first run seems to be replaced with the
> data from the second run. I expected that the data from the second run
> would be appended to the database file, not replace it.

It sounds like you're not calling conn.commit() before you close the
database.  By default sqlite (and any other DBAPI 2.0 compliant sql
wrapper) will start in transactional mode.  You need to commit() your
transactions or they will be rolled back when you close the database
connection.  If you don't want to call commit on your own, you can
switch the database into autocommit mode by setting the isolation
level to None when you open the connection, like this:

conn = sqlite3.connect('.\optiondata', isolation_level=None)

-- 
Jerry



More information about the Python-list mailing list