mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-16 03:50:43 +08:00
Update for new transaction semantics
This commit is contained in:
@ -100,9 +100,9 @@ manage_addZMySQLConnectionForm=HTMLFile('connectionAdd',globals())
|
||||
|
||||
def manage_addZMySQLConnection(self, id, title,
|
||||
connection_string,
|
||||
check=None, transactions=None, REQUEST=None):
|
||||
check=None, REQUEST=None):
|
||||
"""Add a DB connection to a folder"""
|
||||
self._setObject(id, Connection(id, title, connection_string, check, transactions))
|
||||
self._setObject(id, Connection(id, title, connection_string, check))
|
||||
if REQUEST is not None: return self.manage_main(self,REQUEST)
|
||||
|
||||
class Connection(DABase.Connection):
|
||||
@ -115,37 +115,15 @@ class Connection(DABase.Connection):
|
||||
manage_properties=HTMLFile('connectionEdit', globals())
|
||||
manage_main=HTMLFile('connectionStatus', globals())
|
||||
|
||||
def __init__(self, id, title, connection_string, check=None, transactions=None):
|
||||
self.id=str(id)
|
||||
self.edit(title, connection_string, check, transactions)
|
||||
|
||||
def factory(self): return DB
|
||||
|
||||
def edit(self, title, connection_string, check=1, transactions=None):
|
||||
self.title=title
|
||||
self.connection_string=connection_string
|
||||
self.transactions = transactions
|
||||
if check: self.connect(connection_string)
|
||||
|
||||
def manage_edit(self, title, connection_string, check=None, transactions=None, REQUEST=None):
|
||||
"""Change connection
|
||||
"""
|
||||
self.edit(title, connection_string, check, transactions)
|
||||
if REQUEST is not None:
|
||||
return MessageDialog(
|
||||
title='Edited',
|
||||
message='<strong>%s</strong> has been edited.' % self.id,
|
||||
action ='./manage_main',
|
||||
)
|
||||
|
||||
def connect(self,s):
|
||||
try: self._v_database_connection.close()
|
||||
except: pass
|
||||
self._v_connected=''
|
||||
if not hasattr(self, 'transactions'): self.transactions = None
|
||||
DB=self.factory()
|
||||
## No try. DO.
|
||||
self._v_database_connection=DB(s, self.transactions)
|
||||
self._v_database_connection=DB(s)
|
||||
self._v_connected=DateTime()
|
||||
|
||||
return self
|
||||
|
@ -34,12 +34,6 @@
|
||||
<input name="check" type="CHECKBOX" value="YES" CHECKED>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th align="LEFT" valign="TOP">Use transactions</th>
|
||||
<td align="LEFT" valign="TOP">
|
||||
<input name="transactions" type="CHECKBOX" value="YES">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td><br><input type="SUBMIT" value="Add"></td>
|
||||
|
@ -35,13 +35,6 @@
|
||||
<input name="check" type="CHECKBOX" value="YES" CHECKED>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th align="LEFT" valign="TOP">Use transactions</th>
|
||||
<td align="LEFT" valign="TOP">
|
||||
<input name="transactions" type="CHECKBOX" value="YES"
|
||||
value="<dtml-var transactions>">
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td></td>
|
||||
|
@ -140,19 +140,11 @@ class DB(TM):
|
||||
|
||||
_p_oid=_p_changed=_registered=None
|
||||
|
||||
def __init__(self,connection,transactions=None):
|
||||
def __init__(self,connection):
|
||||
self.connection=connection
|
||||
self.kwargs = kwargs = self._parse_connection_string(connection)
|
||||
self.db=apply(self.Database_Connection, (), kwargs)
|
||||
self.transactions = transactions
|
||||
if not transactions: return
|
||||
self.db.query("SHOW VARIABLES")
|
||||
r = self.db.store_result()
|
||||
for row in r.fetch_row(250):
|
||||
if row == ('have_bdb', 'YES'):
|
||||
return
|
||||
raise _mysql.OperationalError, \
|
||||
"server does not support transactions (have_bdb != 'YES')"
|
||||
self.transactions = self.db.server_capabilities & CLIENT.TRANSACTIONS
|
||||
|
||||
def _parse_connection_string(self, connection):
|
||||
kwargs = {'conv': self.conv}
|
||||
|
Reference in New Issue
Block a user