Open the context
Choose the project folder and name the files or behavior involved.
Enable SQLite foreign keys outside an active transaction and report existing violations. Check a rejected invalid insertion and an old orphan, returning audit rows without repairing data.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
import sqlite3
def enable_foreign_keys(db):
if not isinstance(db, sqlite3.Connection) or db.in_transaction:
raise ValueError("foreign_keys.connection")
db.execute("PRAGMA foreign_keys = ON")
if db.execute("PRAGMA foreign_keys").fetchone() != (1,):
raise RuntimeError("foreign_keys.unavailable")
return db.execute("PRAGMA foreign_key_check").fetchall()The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.