[DB-SIG] Exeception Handling.
Heston James - Cold Beans
heston.james at coldbeans.co.uk
Fri Jul 4 12:34:07 CEST 2008
Good afternoon Chaps,
I'm looking for your advice on the best way to handle exceptions on a query
and commit. Within my application I have a universal database connection
which gets injected into objects which require database access, I then use
this connection to create cursors, run queries and commit the changes to the
database. Does that sounds like a good approach?
Take a look at this query below:
# Create the Cursor for the database.
cursor = self.datasource.cursor()
# Run the insert query to create the entry.
INSERT INTO message (
)""", (self.message_id, self.name,
# Commit the change to the database.
# Close the cursor for the database.
Now to add some exception handling to that query, do I simply wrap the whole
code block up in a try/except, and handle any exceptions? or should I be
doing a nested try/except which only runs the commit method is the execute
runs without exception, and likewise only closes the cursor if it opens
I'd really appreciate your advice on this, I'm relatively new to the world
of db implementation using the dbapi and want to make this as water tight as
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the DB-SIG