Fix transaction semantics.

This commit is contained in:
adustman
2001-03-13 15:37:17 +00:00
parent 7986083fad
commit aeae226132

View File

@ -90,6 +90,7 @@ ROWID = _Set()
class Connection: class Connection:
"""This is the connection object for the mySQL database interface.""" """This is the connection object for the mySQL database interface."""
def __init__(self, host, user, passwd, db): def __init__(self, host, user, passwd, db):
from _mysql import CLIENT
kwargs = {} kwargs = {}
kwargs['conv'] = _type_conv kwargs['conv'] = _type_conv
if host: kwargs['host'] = host if host: kwargs['host'] = host
@ -101,10 +102,7 @@ class Connection:
except MySQL.Error, msg: except MySQL.Error, msg:
raise error, msg raise error, msg
self.__curs = Cursor(self.__conn) self.__curs = Cursor(self.__conn)
self.__conn.query("SHOW VARIABLES") self.__transactional = self.__conn.server_capabilities & CLIENT.TRANSACTIONS
self.__vars = {}
for k, v in self.__conn.store_result().fetch_row(0):
self.__vars[k] = v
def __del__(self): def __del__(self):
self.close() self.close()
@ -127,12 +125,12 @@ class Connection:
def commit(self): def commit(self):
"""Commit the current transaction.""" """Commit the current transaction."""
if self.__vars.get('have_bdb', 'NO') == 'YES': if self.__transactional:
self.__conn.query("COMMIT") self.__conn.query("COMMIT")
def rollback(self): def rollback(self):
"""Rollback the current transaction.""" """Rollback the current transaction."""
if self.__vars.get('have_bdb', 'NO') == 'YES': if self.__transactional:
self.__conn.query("ROLLBACK") self.__conn.query("ROLLBACK")
else: raise error, "Not supported by server" else: raise error, "Not supported by server"