summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/pool.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-09-23 20:18:41 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-09-23 20:18:41 +0000
commit68e893d21af31edd2bbc6dec608c95457eaffde6 (patch)
treec3e9e0cfecf478df582db46cf4f8bb21e293677a /lib/sqlalchemy/pool.py
parent372a8d76a61649e7952ec9a465c731aa00352363 (diff)
downloadsqlalchemy-68e893d21af31edd2bbc6dec608c95457eaffde6.tar.gz
- connection pool tracks open cursors and raises an error if connection
is returned to pool with cursors still opened. fixes issues with MySQL, others
Diffstat (limited to 'lib/sqlalchemy/pool.py')
-rw-r--r--lib/sqlalchemy/pool.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py
index de987278d..9eb9cd2ff 100644
--- a/lib/sqlalchemy/pool.py
+++ b/lib/sqlalchemy/pool.py
@@ -168,6 +168,7 @@ class _ConnectionFairy(object):
"""proxies a DBAPI connection object and provides return-on-dereference support"""
def __init__(self, pool):
self._threadfairy = _ThreadFairy(self)
+ self.cursors = weakref.WeakKeyDictionary()
self.__pool = pool
self.__counter = 0
try:
@@ -182,6 +183,7 @@ class _ConnectionFairy(object):
def invalidate(self):
self._connection_record.invalidate()
self.connection = None
+ self.cursors = None
self._close()
def cursor(self, *args, **kwargs):
try:
@@ -196,6 +198,9 @@ class _ConnectionFairy(object):
raise "this connection is closed"
self.__counter +=1
return self
+ def close_open_cursors(self):
+ for c in list(self.cursors):
+ c.close()
def close(self):
self.__counter -=1
if self.__counter == 0:
@@ -203,6 +208,8 @@ class _ConnectionFairy(object):
def __del__(self):
self._close()
def _close(self):
+ if self.cursors is not None and len(self.cursors):
+ raise exceptions.InvalidRequestError("This connection still has %d open cursors" % len(self.cursors))
if self.connection is not None:
try:
self.connection.rollback()
@@ -219,7 +226,12 @@ class _ConnectionFairy(object):
class _CursorFairy(object):
def __init__(self, parent, cursor):
self.__parent = parent
+ self.__parent.cursors[self]=True
self.cursor = cursor
+ def close(self):
+ if self in self.__parent.cursors:
+ del self.__parent.cursors[self]
+ self.cursor.close()
def __getattr__(self, key):
return getattr(self.cursor, key)