I coded a patch. See if this looks okay to you:
Code:
(sp)gturnquist-mbp:spring-python gturnquist$ git diff
diff --git a/src/springpython/database/factory.py b/src/springpython/database/factory.py
index 53e5aff..6e171bc 100644
--- a/src/springpython/database/factory.py
+++ b/src/springpython/database/factory.py
@@ -92,20 +92,21 @@ class PgdbConnectionFactory(ConnectionFactory):
return types.LongType
class Sqlite3ConnectionFactory(ConnectionFactory):
- def __init__(self, db = None):
+ def __init__(self, db = None, check_same_thread=True):
ConnectionFactory.__init__(self, [types.TupleType])
self.db = db
+ self.check_same_thread = check_same_thread
self.using_sqlite3 = True
def connect(self):
"""The import statement is delayed so the library is loaded ONLY if this factory is really used."""
try:
import sqlite3
- return sqlite3.connect(self.db)
+ return sqlite3.connect(self.db, check_same_thread=self.check_same_thread)
except:
import sqlite
self.using_sqlite3 = False
- return sqlite.connect(self.db)
+ return sqlite.connect(self.db, check_same_thread=self.check_same_thread)
def in_transaction(self):
return True
diff --git a/test/springpythontest/databaseCoreTestCases.py b/test/springpythontest/databaseCoreTestCases.py
index 66a309a..c27c25d 100644
--- a/test/springpythontest/databaseCoreTestCases.py
+++ b/test/springpythontest/databaseCoreTestCases.py
@@ -62,6 +62,15 @@ class ConnectionFactoryTestCase(MockTestCase):
del(sys.modules["sqlite3"])
+ def testConnectingToSqliteWithSpecialCheck(self):
+ sys.modules["sqlite3"] = self.mock()
+ sys.modules["sqlite3"].expects(once()).method("connect")
+
+ connection_factory = factory.Sqlite3ConnectionFactory(db="/tmp/foobar", check_same_thread=False)
+ #connection_factory = factory.Sqlite3ConnectionFactory(db="/tmp/foobar")
+ connection = connection_factory.connect()
+
+ del(sys.modules["sqlite3"])
def testConnectingToOracle(self):
sys.modules["cx_Oracle"] = self.mock()