[Tutor] SQLite error messages

Sander Sweers sander.sweers at gmail.com
Wed Mar 10 07:38:50 CET 2010

----- Original message -----
> I am using the sqlite3 module with Python 3.1, and have some code which
> goes something like as follows...
> import sqlite3
> con = sqlite3.connect('MyDatabase.db')
> try:
>        execresult = con.execute('INSERT INTO MyTable (field_name) VALUES
> ("MyValue")')
>        con.commit()
> except:

Here you catch all exceptions. Normally you would catch a specific exception like ValueError.  
>        con.rollback()

Do you know finally? It is run after all the exceptions have been handled and this is where I would put the rollback.


More information about the Tutor mailing list