Repository navigation
Fix matching a foreign key reference to a unique key with a different case - #534
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
… case When looking for the unique constraint that a foreign key references, the referenced column names were compared to the index columns case-sensitively. MySQL column names are case-insensitive, so a reference like "REFERENCES t1 (ID)" to a column "id" found no unique constraint, and UNIQUE_CONSTRAINT_NAME in information_schema.referential_constraints was NULL. Compare the column names case-insensitively. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Compare the column names with strcasecmp() instead of lowercasing both. Extend the test to cover a single-column PRIMARY KEY, a composite UNIQUE key, and a foreign key added with ALTER TABLE.
e3a7785 to
bffd503
Compare
|
Thanks again, @Nandan108! I rebased the branch on the latest trunk and pushed one commit on top with small improvements ( |
Summary
Follow-up to #523.
When a foreign key references columns with a different letter case than the referenced table declares them, the referenced unique constraint is not found:
MySQL column names are case-insensitive, but the lookup compared the referenced column names to the index columns with
!==. The foreign key itself works, since SQLite also matches column names case-insensitively; only the information schema entry is wrong.Fix
The names are compared case-insensitively with
strcasecmp(), which compares them directly, without creating lowercased copies first. Identifiers are restricted to ASCII in this driver, so this is sufficient.Tests
testInformationSchemaForeignKeysReferencingColumnsInDifferentLetterCasereferences a single-column primary key, a composite unique key, and a unique key in a foreign key added withALTER TABLE, all with differently cased column names, and checksUNIQUE_CONSTRAINT_NAME. It fails ontrunkwithNULLfor all three.Use of AI
This change was prepared with Claude Code (Claude Fable 5.1). I reviewed the code, the tests, and this description, and I take responsibility for the change.
🤖 Generated with Claude Code
Summary by CodeRabbit