KKeyTillage
Workflows

Coding workflows · SQLite foreign-key enforcement

03
Built around your work

A concrete starting point

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.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

SQLite foreign-key enforcement

A concrete starting point
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.

AI coding workspace

Your next change starts here.

Get the Windows app ↗