Commit 910b2a51 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

ZMySQLDA: support isolation level per connector.

parent 3982aa81
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
<dd> <dd>
The connection string used for Z MySQL Database Connection is of the form: The connection string used for Z MySQL Database Connection is of the form:
<br /> <br />
<code>[%ssl_name] [*lock] [+/-][database][@host[:port]] [user [password [unix_socket]]]</code> <code>[%ssl_name] [*lock] [!isolation-level] [+/-][database][@host[:port]] [user [password [unix_socket]]]</code>
<br /> <br />
or typically: or typically:
<br /> <br />
...@@ -103,6 +103,12 @@ ...@@ -103,6 +103,12 @@
you'll get an error in the logs, and inconsistent data. In this you'll get an error in the logs, and inconsistent data. In this
respect, it's equivalent to transactions turned off. respect, it's equivalent to transactions turned off.
</dd> </dd>
<dd>
!<em>isolation_level</em> at the begining of the connection string
will set the transaction isolation level in each transaction. The
value should be one of REPEATABLE-READ, READ-COMMITTED,
READ-UNCOMMITTED or SERIALIZABLE.
</dd>
<dd> <dd>
Transactions are highly recommended. Using a named lock in Transactions are highly recommended. Using a named lock in
conjunctions with transactions is probably pointless. conjunctions with transactions is probably pointless.
......
...@@ -244,7 +244,7 @@ class DB(TM): ...@@ -244,7 +244,7 @@ class DB(TM):
self._use_TM = transactional or self._mysql_lock self._use_TM = transactional or self._mysql_lock
def _parse_connection_string(self): def _parse_connection_string(self):
self._mysql_lock = self._try_transactions = None self._mysql_lock = self._try_transactions = self._isolation_level = None
self._kw_args = kwargs = {'conv': self.conv} self._kw_args = kwargs = {'conv': self.conv}
items = self._connection.split() items = self._connection.split()
if not items: if not items:
...@@ -262,6 +262,8 @@ class DB(TM): ...@@ -262,6 +262,8 @@ class DB(TM):
del items[0] del items[0]
if items[0][0] == "*": if items[0][0] == "*":
self._mysql_lock = items.pop(0)[1:] self._mysql_lock = items.pop(0)[1:]
if items[0][0] == "!":
self._isolation_level = items.pop(0)[1:]
db = items.pop(0) db = items.pop(0)
if '@' in db: if '@' in db:
db, host = db.split('@', 1) db, host = db.split('@', 1)
...@@ -491,6 +493,8 @@ class DB(TM): ...@@ -491,6 +493,8 @@ class DB(TM):
try: try:
self._transaction_begun = True self._transaction_begun = True
if self._transactions: if self._transactions:
if self._isolation_level:
self._query("SET TRANSACTION ISOLATION LEVEL %s" % self._isolation_level.replace('-', ' '))
self._query("BEGIN", allow_reconnect=True) self._query("BEGIN", allow_reconnect=True)
if self._mysql_lock: if self._mysql_lock:
self._query("SELECT GET_LOCK('%s',0)" % self._mysql_lock, allow_reconnect=not self._transactions) self._query("SELECT GET_LOCK('%s',0)" % self._mysql_lock, allow_reconnect=not self._transactions)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment