SQLite query macros don't reject INSERTs that omit NOT NULL columns without defaults

Aperta
#4,206 1 commento 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 4 giorni

Nessuno ha ancora preso questa issue.

  • #4260 di @Zelys-DFKH — chiusa senza merge

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
rust, sql, sqlite
Ambito
databases

Direzione di ricerca

The report is about compile-time sqlx::query! INSERT checking for SQLite: omitted NOT NULL columns without DEFAULT still compile and fail at runtime. Start from how SQLite describe currently exposes bind counts and result-column metadata but not write completeness for the target table. A closed unmerged PR (#4260) already exists, so read that thread and the 0.8.6 describe path before changing macros. Done means the given INSERT fails at compile time (or docs state the SQLite limit).

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

With sqlx 0.8.6 and SQLite, a compile-time checked sqlx::query! INSERT that omits a NOT NULL / no-DEFAULT column still compiles. SQLite then rejects it only at runtime with NOT NULL constraint failed.

Reproduction

Repo: https://github.com/pascalporedda/sqlx-sqlite-not-null-repro

Schema:

CREATE TABLE session_group (
    prop_a TEXT NOT NULL,
    prop_b INTEGER NOT NULL,
    prop_c TEXT NOT NULL
);

Query that compiles:

sqlx::query!(
    r#"
    INSERT INTO session_group (prop_a, prop_b)
    VALUES (?, ?)
    "#,
    "test1",
    123_i64,
)

Commands:

cargo check
cargo run --quiet

Observed runtime output:

full insert rows_affected = 1
partial insert runtime result = Err(
    Database(
        SqliteError {
            code: 1299,
            message: "NOT NULL constraint failed: session_group.prop_c",
        },
    ),
)
persisted rows = [
    "ok:1:present",
]
row count = 1

Expected

I expected the compile-time checked query macro to reject the INSERT because prop_c is omitted and is NOT NULL with no default.

Actual

The query compiles and only fails when executed.

Notes

I looked through the 0.8.6 sources locally and it appears the SQLite describe path provides bind parameter count and result-column metadata, but not target-table write completeness. If this is the intended limit of checking for SQLite, a documentation note would help. If not, this looks like a missing compile-time verification case.

Lingua principale
Rust
Stelle
17.5k
Fork
1.7k
Merge medio
1g 17h
PR unite (30g)
7

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di transact-rs/sqlx

Tutte le issue di transact-rs/sqlx

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.