Re: Best Coding Practices

Gerhard Häring <[email protected]>
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Rich Shepard wrote:
>    I understand that sqlite3 runs actions under implicit transactions if a
> transaction is not explicitly declared. So, is it good coding practice to
> issue 'self.con.commit' after each 'self.cur.execute("insert into ...);"',
> or is that not necessary for a disk-hosted database file?

You should commit whenever you reached a consistent state of your data -
this rule is obviously only relevant when there are different entities in
your database (different tables).

The reason for this is that if an error happens you can roll back to the
"last known good configuration" ;-)

Doing COMMITs when they're not really necessary will decrease performance
as each COMMIT implies a sync operation of the OS, so you're waiting on
buffers being flushed to disk here. This is important if you're doing mass
operations with loads of data. The usual procedure here is to commit after
every few hundred or thousand records that you insert during bulk loads.

- -- Gerhard
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFP7bIdIO4ozGCH14RAntzAJ4rilfNalxfDUUg3GDkgThMFw1yQwCgjjt6
/27zP5V4prYtj5bpvYnZg9E=
=7Qmo
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.