summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/sqlite/pysqlite.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-06-29 00:49:57 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2011-06-29 00:49:57 -0400
commit57b91143ef74f0efb2c9b9b6caa858db7c0de2d5 (patch)
tree73c1989935e72e493ec665e188c38d306b15de20 /lib/sqlalchemy/dialects/sqlite/pysqlite.py
parent668991a7ed3a46e29ab76cd0278b021e5190b103 (diff)
downloadsqlalchemy-57b91143ef74f0efb2c9b9b6caa858db7c0de2d5.tar.gz
- document that pysqlite does not share temporary tables
across multiple connections therefore a non-standard pool should be used [ticket:2203]
Diffstat (limited to 'lib/sqlalchemy/dialects/sqlite/pysqlite.py')
-rw-r--r--lib/sqlalchemy/dialects/sqlite/pysqlite.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/sqlite/pysqlite.py b/lib/sqlalchemy/dialects/sqlite/pysqlite.py
index 128059fa1..07df64712 100644
--- a/lib/sqlalchemy/dialects/sqlite/pysqlite.py
+++ b/lib/sqlalchemy/dialects/sqlite/pysqlite.py
@@ -127,6 +127,9 @@ Modern versions of SQLite no longer have the threading restrictions, and assumin
the sqlite3/pysqlite library was built with SQLite's default threading mode
of "Serialized", even ``:memory:`` databases can be shared among threads.
+Using a Memory Database in Multiple Threads
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
To use a ``:memory:`` database in a multithreaded scenario, the same connection
object must be shared among threads, since the database exists
only within the scope of that connection. The :class:`.StaticPool` implementation
@@ -141,6 +144,32 @@ can be passed to Pysqlite as ``False``::
Note that using a ``:memory:`` database in multiple threads requires a recent
version of SQLite.
+Using Temporary Tables with SQLite
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Due to the way SQLite deals with temporary tables, if you wish to use a temporary table
+in a file-based SQLite database across multiple checkouts from the connection pool, such
+as when using an ORM :class:`.Session` where the temporary table should continue to remain
+after :meth:`.commit` or :meth:`.rollback` is called,
+a pool which maintains a single connection must be used. Use :class:`.SingletonThreadPool`
+if the scope is only needed within the current thread, or :class:`.StaticPool` is scope is
+needed within multiple threads for this case::
+
+ # maintain the same connection per thread
+ from sqlalchemy.pool import SingletonThreadPool
+ engine = create_engine('sqlite:///mydb.db',
+ poolclass=SingletonThreadPool)
+
+
+ # maintain the same connection across all threads
+ from sqlalchemy.pool import StaticPool
+ engine = create_engine('sqlite:///mydb.db',
+ poolclass=StaticPool)
+
+Note that :class:`.SingletonThreadPool` should be configured for the number of threads
+that are to be used; beyond that number, connections will be closed out in a non deterministic
+way.
+
Unicode
-------