mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-16 12:27:03 +08:00
Make commit and rollback truly functional.
This commit is contained in:
@ -272,6 +272,7 @@ class CursorStoreResultMixIn:
|
|||||||
|
|
||||||
def fetchone(self):
|
def fetchone(self):
|
||||||
"""Fetches a single row from the cursor."""
|
"""Fetches a single row from the cursor."""
|
||||||
|
if self._pos >= len(self._rows): return None
|
||||||
result = self._rows[self._pos]
|
result = self._rows[self._pos]
|
||||||
self._pos = self._pos+1
|
self._pos = self._pos+1
|
||||||
return result
|
return result
|
||||||
@ -441,6 +442,8 @@ class Connection:
|
|||||||
else:
|
else:
|
||||||
self.cursorclass = Cursor
|
self.cursorclass = Cursor
|
||||||
self.db = apply(connect, (), kwargs)
|
self.db = apply(connect, (), kwargs)
|
||||||
|
self._server_info = i = self.db.get_server_info()
|
||||||
|
self._server_version = int(i[0])*10000 + int(i[2:4])*100 + int(i[5:7])
|
||||||
if _threading: self.__lock = _threading.Lock()
|
if _threading: self.__lock = _threading.Lock()
|
||||||
|
|
||||||
if _threading:
|
if _threading:
|
||||||
@ -454,16 +457,14 @@ class Connection:
|
|||||||
"""Close the connection. No further activity possible."""
|
"""Close the connection. No further activity possible."""
|
||||||
self.db.close()
|
self.db.close()
|
||||||
|
|
||||||
if hasattr(_mysql, 'rollback'):
|
def commit(self):
|
||||||
def commit(self):
|
"""Commit the current transaction."""
|
||||||
"""Commit the current transaction."""
|
if self._server_version > 32315: self.db.query("COMMIT")
|
||||||
return self.db.commit()
|
|
||||||
|
|
||||||
def rollback(self):
|
def rollback(self):
|
||||||
"""Rollback the current transaction."""
|
"""Rollback the current transaction."""
|
||||||
self.db.rollback()
|
if self._server_version > 32315: self.db.query("ROLLBACK")
|
||||||
else:
|
else: raise NotSupportedError, "Not supported by server"
|
||||||
def commit(self): """Does nothing as there are no transactions."""
|
|
||||||
|
|
||||||
def cursor(self, cursorclass=None):
|
def cursor(self, cursorclass=None):
|
||||||
"""Create a cursor on which queries may be performed."""
|
"""Create a cursor on which queries may be performed."""
|
||||||
|
Reference in New Issue
Block a user