You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(DataMapper,ddl2cpp): address code-review findings on composite FKs and relation generation
Ten findings from a review of the composite-foreign-key and ddl2cpp relation work.
Correctness:
- QuerySingle(primaryKeys...) and one FirstImpl() overload each had an early
`return std::nullopt;` ahead of their final `return record;`. Verified with
standalone repros that this defeats NRVO in both GCC and Clang, moving the
record to a new address on return while the composite-FK lazy loader
installed on it still held a pointer to the old one - a use-after-free.
Restructured both to a single return statement.
- ddl2cpp's join-table cardinality check used the *far* key's uniqueness
instead of the *owner* key's - the far key always references exactly one
row, so that check was trivially always true. Fixed, and corrected the test
that had locked in the backwards expectation, plus the doc wording.
- The `PrimaryKey::AutoAssign` collision counter only recognized
`value + 1`-style keys, so two auto-assigned SqlGuid keys bypassed the
static_assert meant to reject multi-column auto-assignment.
- CompositeForeignKey had no operator==/<=>, so it was neither
equality_comparable nor (owing to its private members) an aggregate -
Reflection::CollectDifferences hard-errors on any record holding one.
Added comparison operators, matching HasMany/HasOneThrough/HasManyThrough.
- GetPrimaryKeyField() kept overwriting its result for every matching-type
primary key member, silently returning the last one instead of the first.
Cleanup:
- Deduplicated the eager (LoadCompositeForeignKey) and lazy
(ConfigureRelationAutoLoading) composite-FK load paths into one
LoadCompositeForeignKeyRecord() helper.
- Merged the near-identical HasOneThrough/HasManyThrough codegen branches in
CxxModelPrinter, driven by the template name string.
- Replaced two C-style index loops in CompositeForeignKey with views::iota.
- Rebuilt GetPrimaryKeyFields() on the same compile-time tuple_cat machinery
RecordPrimaryKeyTupleHelper already uses, dropping an O(K^2) runtime scan.
- Replaced byName()'s linear table scan in PlanRelations with a hash map.
Also fixed, unrelated to the review but required for a local build under this
toolchain: two dependent-name lookups needing an explicit `template` keyword,
and a spurious unused-lambda-capture warning-as-error.
Verified: clang-debug (ASan/UBSan) against SQLite3 - 1341/1342 test cases,
13431/13431 assertions passed (1 pre-existing SQLite-unsupported skip).
GCC/MSSQL/PostgreSQL legs not available in this environment.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
0 commit comments