Skip to content

Commit

Permalink
* Added the ability to set the transaction isolation level.
Browse files Browse the repository at this point in the history
* Also updated the documentation.
  • Loading branch information
smurfix committed Nov 25, 2011
1 parent 977035b commit 4afecd8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
13 changes: 12 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,23 @@ Moreover,
* How to use a database asynchronously, e.g. via Twisted "deferred" handlers,
is non-obvious and, again, requires too much boilerplate code.

* Retrying an entire transaction (if it fails due to optimism) is difficult.
There's no object representing the transaction.

Using an object-oriented wrapper is out of the question: they work synchronously
and thus are forbidden in asynchronous code.

I don't want to multi-thread my main program. Debugging threaded helpers (file system,
database, possibly other synchronous libraries) is difficult enough.

-----
Usage
-----

Using this module is rather simple.

>>> from sqlmix import Db,NoData
>>> db = Db(database="testdb",username="testuser",password="testpass")
>>> db = Db(database="testdb",username="testuser",password="testpass", isolation='repeatable read')
>>> # db = Db(dbtype="sqlite",database="/tmp/testdb.sqlite")
>>> db.Do("""\
... create table test1 (
Expand All @@ -69,6 +78,8 @@ Using this module is rather simple.
>>> assert n == 3
>>> print "Success."

See "pydoc sqlmix" for further details.

Error Handling
--------------

Expand Down
7 changes: 7 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
python-sqlmix (0.9.20-1) smurf; urgency=low

* Added the ability to set the transaction isolation level.
* Also updated the documentation.

-- Matthias Urlichs <[email protected]> Fri, 25 Nov 2011 12:59:43 +0100

python-sqlmix (0.9.19-1) smurf; urgency=low

* Add prefix for debug output.
Expand Down
6 changes: 6 additions & 0 deletions sqlmix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class Db(object):
_set_ac1 = True
_set_ac2 = True
_set_timeout = True
_set_isolation = True
def __init__(self, cfg=None, **kwargs):
if cfg is not None:
try:
Expand Down Expand Up @@ -232,6 +233,7 @@ def __init__(self, cfg=None, **kwargs):
# self.CArgs = (self.DB.DB.cursors.CursorNW,)
# else:
self.CArgs = ()
self.isolation = kwargs.get("isolation",None)
#

(self.arg_init, self.arg_do, self.arg_done) \
Expand All @@ -258,6 +260,10 @@ def _conn(self, skip=False):
try: r.cursor(*self.CArgs).execute("SET WAIT_TIMEOUT=7200") # 2h
except Exception: self._set_timeout = False

if self._set_isolation and self.isolation:
try: r.cursor(*self.CArgs).execute("SET SESSION TRANSACTION ISOLATION LEVEL "+self.isolation)
except Exception: self._set_isolation = False

# try:
# r.stringformat = self.DB.DB.UNICODE_STRINGFORMAT
# r.encoding = 'utf-8'
Expand Down

0 comments on commit 4afecd8

Please sign in to comment.