diff options
author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2024-01-12 09:50:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-12 09:50:37 (GMT) |
commit | de777e490fb356d7bcc7c907141c20a5135d97df (patch) | |
tree | e9297e40aec54d80e0d4871714a4ebe1d4eb6480 /Lib/sqlite3 | |
parent | fcb4c8d31a4b1c60ed9990db3eacd1db9cac4df2 (diff) | |
download | cpython-de777e490fb356d7bcc7c907141c20a5135d97df.zip cpython-de777e490fb356d7bcc7c907141c20a5135d97df.tar.gz cpython-de777e490fb356d7bcc7c907141c20a5135d97df.tar.bz2 |
gh-108364: In sqlite3, disable foreign keys before dumping SQL schema (#113957)
sqlite3.Connection.iterdump now ensures that foreign key support is
disabled before dumping the database schema, if there is any foreign key
violation.
Co-authored-by: Erlend E. Aasland <erlend@python.org>
Diffstat (limited to 'Lib/sqlite3')
-rw-r--r-- | Lib/sqlite3/dump.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/sqlite3/dump.py b/Lib/sqlite3/dump.py index ead3360..719dfc8 100644 --- a/Lib/sqlite3/dump.py +++ b/Lib/sqlite3/dump.py @@ -26,6 +26,10 @@ def _iterdump(connection): writeable_schema = False cu = connection.cursor() + # Disable foreign key constraints, if there is any foreign key violation. + violations = cu.execute("PRAGMA foreign_key_check").fetchall() + if violations: + yield('PRAGMA foreign_keys=OFF;') yield('BEGIN TRANSACTION;') # sqlite_master table contains the SQL CREATE statements for the database. |