diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-09-23 12:24:24 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-09-23 12:24:24 -0400 |
| commit | b7554b0e2d1536c17f060b421a35c677f88fdb1f (patch) | |
| tree | 71314f4a62b921d9df828d051c1db09e8e54639c /lib/sqlalchemy/dialects/sqlite | |
| parent | c7ab095fdbb13d045376df3f997a30058d7c82dd (diff) | |
| download | sqlalchemy-b7554b0e2d1536c17f060b421a35c677f88fdb1f.tar.gz | |
- improve docs for MySQL/SQLite foreign key/ON UPDATE|DELETE instructions,
[ticket:2514]
Diffstat (limited to 'lib/sqlalchemy/dialects/sqlite')
| -rw-r--r-- | lib/sqlalchemy/dialects/sqlite/base.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index 837f1adcd..75c2924a3 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -85,6 +85,42 @@ For more information on SQLite's lack of concurrency by design, please see `Situations Where Another RDBMS May Work Better - High Concurrency <http://www.sqlite.org/whentouse.html>`_ near the bottom of the page. +.. _sqlite_foreign_keys: + +Foreign Key Support +------------------- + +SQLite supports FOREIGN KEY syntax when emitting CREATE statements for tables, +however by default these constraints have no effect on the operation +of the table. + +Constraint checking on SQLite has three prerequisites: + +* At least version 3.6.19 of SQLite must be in use +* The SQLite libary must be compiled *without* the SQLITE_OMIT_FOREIGN_KEY + or SQLITE_OMIT_TRIGGER symbols enabled. +* The ``PRAGMA foreign_keys = ON`` statement must be emitted on all connections + before use. + +SQLAlchemy allows for the ``PRAGMA`` statement to be emitted automatically +for new connections through the usage of events:: + + from sqlalchemy.engine import Engine + from sqlalchemy import event + + @event.listens_for(Engine, "connect") + def set_sqlite_pragma(dbapi_connection, connection_record): + cursor = dbapi_connection.cursor() + cursor.execute("PRAGMA foreign_keys=ON") + cursor.close() + +.. seealso:: + + `SQLite Foreign Key Support <http://www.sqlite.org/foreignkeys.html>`_ - + on the SQLite web site. + + :ref:`event_toplevel` - SQLAlchemy event API. + """ import datetime, re |
