Repository navigation
(Fix) Handle nullability of SQLite rowid alias columns - #4088
Conversation
|
The explain.rs changes look reasonable to me. But I haven't touched sqlx in a long time, so I won't try to guess whether returning None from handle.rs column_nullable could lead to surprises. I initially assumed that the handle.rs is not needed for the macro magic to work. But I vaguely remember some portion of the query type describe mechanism executed select queries to sniff the results... so maybe that is what forced the handle.rs changes? |
|
The requested extra test makes sense. Will add. |
Tests the nullability of explicitly referring to the rowid column (not through an alias).
sqlite3_table_column_metadata() leaves its declared-type out-param NULL for a column declared without a type, e.g. `CREATE TABLE foo (bar PRIMARY KEY)`. column_nullable() passed that pointer straight to CStr::from_ptr(), so describing such a column segfaulted the process, and rustc itself, since the query!() macros describe a live database at expansion time. A column with no declared type is not declared INTEGER and so cannot be a rowid alias; treat it as a normal column and fall through to the NOT NULL flag. Regression introduced in 69ee0df (transact-rs#4088), released in 0.9.0.
#4374) * fix(sqlite): don't dereference a NULL declared type in column_nullable sqlite3_table_column_metadata() leaves its declared-type out-param NULL for a column declared without a type, e.g. `CREATE TABLE foo (bar PRIMARY KEY)`. column_nullable() passed that pointer straight to CStr::from_ptr(), so describing such a column segfaulted the process, and rustc itself, since the query!() macros describe a live database at expansion time. A column with no declared type is not declared INTEGER and so cannot be a rowid alias; treat it as a normal column and fall through to the NOT NULL flag. Regression introduced in 69ee0df (#4088), released in 0.9.0. * fix(sqlite): only check the declared type for primary key columns --------- Co-authored-by: Scott Driggers <[email protected]>
Does your PR solve an issue?
fixes #3967
Is this a breaking change?
This is a breaking change.
Previously an
INTEGER PRIMARY KEYcolumn was wrongly inferred to be nullable, so code usingquery!will break, as the result will now be ani64instead of anOption<i64>.query_as!should be fine though becauseOption<i64>implementsFrom<i64>This will apply anywhere someone has used an
INTEGER PRIMARY KEYand not overridden the nullability of that column in their queries.