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 ( |
## Release `3.1.1` Version bump and changelog update for release `3.1.1`. **Changelog draft:** * Support date arithmetic with `INTERVAL` operators ([#539](#539)) * Fix `ROLLBACK` as the first transaction of a connection ([#537](#537)) * Fix matching a foreign key reference to a unique key with a different case ([#534](#534)) * Fix `FOUND_ROWS()` without `SQL_CALC_FOUND_ROWS` ([#533](#533)) * Fix unique keys and foreign key restore without stringified fetches ([#532](#532)) * Fix `CREATE TEMPORARY TABLE IF NOT EXISTS` and `DROP TEMPORARY TABLE` as the first temporary table ([#524](#524)) * Fix a warning for a foreign key referencing a table with a shorter unique key ([#523](#523)) * Fix temporary table lookup without stringified fetches and with a different case ([#522](#522)) **Full changelog:** v3.1.0...release/v3.1.1 ## Next steps 1. **Review** the changes in this pull request. 2. **Push** any additional edits to this branch (`release/v3.1.1`). 3. **Merge** this pull request to complete the release. Merging will automatically build the plugin ZIP, create a [GitHub release](https://github.com/WordPress/sqlite-database-integration/releases), and deploy to [WordPress.org](https://wordpress.org/plugins/sqlite-database-integration/).
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