From: Mike Bayer Date: Wed, 29 Jun 2011 04:49:57 +0000 (-0400) Subject: - document that pysqlite does not share temporary tables X-Git-Tag: rel_0_7_2~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57b91143ef74f0efb2c9b9b6caa858db7c0de2d5;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - document that pysqlite does not share temporary tables across multiple connections therefore a non-standard pool should be used [ticket:2203] --- diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py index e349092f4b..3817e60872 100644 --- a/lib/sqlalchemy/dialects/mssql/base.py +++ b/lib/sqlalchemy/dialects/mssql/base.py @@ -766,6 +766,9 @@ class MSSQLCompiler(compiler.SQLCompiler): return s return compiler.SQLCompiler.get_select_precolumns(self, select) + def get_from_hint_text(self, text): + return text + def limit_clause(self, select): # Limit in mssql is after the select keyword return "" diff --git a/lib/sqlalchemy/dialects/sqlite/pysqlite.py b/lib/sqlalchemy/dialects/sqlite/pysqlite.py index 128059fa18..07df64712e 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 -------