sqlite-fix: Auto-commit on HTTPResponde exceptions (e.g. redirects)

This commit is contained in:
Marcel Hellkamp 2012-02-07 19:07:27 +01:00
parent 31486d5066
commit f0b377857e

9
bottle_sqlite.py Normal file → Executable file
View File

@ -27,14 +27,14 @@ Usage Example::
''' '''
__author__ = "Marcel Hellkamp" __author__ = "Marcel Hellkamp"
__version__ = '0.1.1' __version__ = '0.1.2'
__license__ = 'MIT' __license__ = 'MIT'
### CUT HERE (see setup.py) ### CUT HERE (see setup.py)
import sqlite3 import sqlite3
import inspect import inspect
from bottle import HTTPError from bottle import HTTPResponse, HTTPError
class SQLitePlugin(object): class SQLitePlugin(object):
@ -89,6 +89,11 @@ class SQLitePlugin(object):
except sqlite3.IntegrityError, e: except sqlite3.IntegrityError, e:
db.rollback() db.rollback()
raise HTTPError(500, "Database Error", e) raise HTTPError(500, "Database Error", e)
except HTTPError, e:
raise
except HTTPResponse, e:
if autocommit: db.commit()
raise
finally: finally:
db.close() db.close()
return rv return rv