sqlite3 db update extremely slow

coldpizza vriolk at gmail.com
Mon Jul 16 19:09:16 EDT 2007


Thanks a lot, Roel, adding a single commit() at the end did solve the
speed problem.

Another question is do I have to explicitly close the DB connection,
or is it automatically garbage collected? Is it Ok to no have any
cleanup code?

Another question would be how to define the encoding for newly added
records?
And how do set the encoding for the retrieved records? Is it always
utf-8 by default?

On Jul 16, 11:21 pm, Roel Schroeven <rschroev_nospam... at fastmail.fm>
wrote:
> coldpizza schreef:
>
> > I am trying to fill a sqlite3 database with records, and to this end I
> > have written a class that creates the db, the table and adds rows to
> > the table.
>
> > The problem is that the updating process is *extremely* slow, and
> > occasionally I get the message "database locked".
>
> > I tried removing "self.con.commit()" in the add_record method, but
> > then nothing is saved in the db. I don't know whether this has
> > anything to do with it, but I have found no option to enable
> > autocommit.
>
> Remove self.con.commit() from add_record(), and do it once after all
> records are added.
>
> The reason that the process is slow with a commit after every INSERT is
> that sqlite syncs the inserted data to disk before it continues.
>
> --
> If I have been able to see further, it was only because I stood
> on the shoulders of giants.  -- Isaac Newton
>
> Roel Schroeven





More information about the Python-list mailing list