summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/sqlalchemy/engine/threadlocal.py14
-rw-r--r--test/parseconnect.py4
-rw-r--r--test/testbase.py2
-rw-r--r--test/transaction.py7
4 files changed, 22 insertions, 5 deletions
diff --git a/lib/sqlalchemy/engine/threadlocal.py b/lib/sqlalchemy/engine/threadlocal.py
index d909cbeda..84e5a7dc4 100644
--- a/lib/sqlalchemy/engine/threadlocal.py
+++ b/lib/sqlalchemy/engine/threadlocal.py
@@ -14,7 +14,12 @@ class TLSession(object):
try:
return self.__transaction
except AttributeError:
- return base.Connection(self.engine, close_with_result=close_with_result)
+ return TLConnection(self, close_with_result=close_with_result)
+ def set_transaction(self, tlconnection, trans):
+ if self.__tcount == 0:
+ self.__transaction = tlconnection
+ self.__trans = trans
+ self.__tcount += 1
def begin(self):
if self.__tcount == 0:
self.__transaction = self.get_connection()
@@ -41,7 +46,12 @@ class TLSession(object):
def is_begun(self):
return self.__tcount > 0
-
+class TLConnection(base.Connection):
+ def __init__(self, session, close_with_result):
+ base.Connection.__init__(self, session.engine, close_with_result=close_with_result)
+ self.__session = session
+ # TODO: get begin() to communicate with the Session to maintain the same transactional state
+
class TLEngine(base.ComposedSQLEngine):
"""a ComposedSQLEngine that includes support for thread-local managed transactions. This engine
is better suited to be used with threadlocal Pool object."""
diff --git a/test/parseconnect.py b/test/parseconnect.py
index e1f50e8c9..97061a683 100644
--- a/test/parseconnect.py
+++ b/test/parseconnect.py
@@ -17,10 +17,12 @@ class ParseConnectTest(PersistTest):
'dbtype:///:memory:',
'dbtype:///foo/bar/im/a/file',
'dbtype:///E:/work/src/LEM/db/hello.db',
- 'dbtype://'
+ 'dbtype://',
+ 'dbtype://username:password@/db'
):
u = url.make_url(text)
print u, text
+ print u.username, u.password, u.database
assert str(u) == text
diff --git a/test/testbase.py b/test/testbase.py
index 17e42906b..57fcb58c3 100644
--- a/test/testbase.py
+++ b/test/testbase.py
@@ -157,8 +157,6 @@ class MockPool(pool.Pool):
raise "Invalid"
def do_get(self):
- if getattr(self, 'breakpoint', False):
- raise "breakpoint"
assert self.connection is not None
c = self.connection
self.connection = None
diff --git a/test/transaction.py b/test/transaction.py
index a009c447c..42baff46d 100644
--- a/test/transaction.py
+++ b/test/transaction.py
@@ -143,6 +143,13 @@ class TLTransactionTest(testbase.PersistTest):
self.assert_(external_connection.scalar("select count(1) from query_users") == 0)
finally:
external_connection.close()
+
+ def testconnections(self):
+ """tests that contextual_connect is threadlocal"""
+ c1 = tlengine.contextual_connect()
+ c2 = tlengine.contextual_connect()
+ assert c1.connection is c2.connection
+ c1.close()
if __name__ == "__main__":
testbase.main()