diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-12-06 12:41:01 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-12-06 12:41:01 -0500 |
commit | bd4c1dd38c503df467e9297dfc6dcfa35b9df9c3 (patch) | |
tree | af9eb805c7eb992240b21a604b00ac1eac4f8764 /lib/sqlalchemy/dialects/sqlite/pysqlite.py | |
parent | c929e70e107caa75dc6988dddb59b57b2f4eeff8 (diff) | |
download | sqlalchemy-bd4c1dd38c503df467e9297dfc6dcfa35b9df9c3.tar.gz |
add BEGIN workaround to pysqlite docs, [ticket:2219]
Diffstat (limited to 'lib/sqlalchemy/dialects/sqlite/pysqlite.py')
-rw-r--r-- | lib/sqlalchemy/dialects/sqlite/pysqlite.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/sqlite/pysqlite.py b/lib/sqlalchemy/dialects/sqlite/pysqlite.py index ad8d5c6f9..63832b8f3 100644 --- a/lib/sqlalchemy/dialects/sqlite/pysqlite.py +++ b/lib/sqlalchemy/dialects/sqlite/pysqlite.py @@ -182,6 +182,31 @@ require unicode, however, so that non-``unicode`` values passed inadvertently will emit a warning. Pysqlite will emit an error if a non-``unicode`` string is passed containing non-ASCII characters. +.. _pysqlite_serializable: + +Serializable Transaction Isolation +---------------------------------- + +The pysqlite DBAPI driver has a long-standing bug in which transactional +state is not begun until the first DML statement, that is INSERT, UPDATE +or DELETE, is emitted. A SELECT statement will not cause transactional +state to begin. While this mode of usage is fine for typical situations +and has the advantage that the SQLite database file is not prematurely +locked, it breaks serializable transaction isolation, which requires +that the database file be locked upon any SQL being emitted. + +To work around this issue, the ``BEGIN`` keyword can be emitted +at the start of each transaction. The following recipe establishes +a :meth:`.ConnectionEvents.begin` handler to achieve this:: + + from sqlalchemy import create_engine, event + + engine = create_engine("sqlite:///myfile.db", isolation_level='SERIALIZABLE') + + @event.listens_for(engine, "begin") + def do_begin(conn): + conn.execute("BEGIN") + """ from sqlalchemy.dialects.sqlite.base import SQLiteDialect, DATETIME, DATE |