[Tutor] SQLite error messages
Sander Sweers
sander.sweers at gmail.com
Wed Mar 10 21:37:20 CET 2010
On 10 March 2010 21:02, Alan Harris-Reid <aharrisreid at googlemail.com> wrote:
> Maybe I have misunderstood you, but I always thought that the 'finally'
> section was run even if the 'try' section is successful, in which case I
> would not want a rollback.
I was thinking something like this.
import sqlite3
con = sqlite3.connect('MyDatabase.db')
execresult = None
try:
execresult = con.execute('INSERT INTO MyTable (field_name) VALUES
("MyValue")')
con.commit()
finally:
if not execresult:
print 'Rollback'
con.rollback()
This way you can have a rollback and still see an exception.
Greets
Sander
More information about the Tutor
mailing list