Skip to content

Fix foreign keys being skipped when renaming a column - #4226

Open
deepsidhu1313 wants to merge 1 commit into
sqlitebrowser:masterfrom
deepsidhu1313:fix/rename-foreign-key-iterator
Open

deepsidhu1313 wants to merge 1 commit into
sqlitebrowser:masterfrom
deepsidhu1313:fix/rename-foreign-key-iterator

Conversation

@deepsidhu1313

Copy link
Copy Markdown
Contributor

Table::renameKeyInAllConstraints() looped over m_foreignKeys with for(...; ++it) while the match_and_rename helper already advances the iterator (it = container.erase(it)). After a rename the loop skipped the next foreign key, leaving it on the old column name, and when the renamed entry was the last one it incremented end(), which is undefined behaviour.

Let the helper advance the iterator, like the index constraint loop above.

Add tests for renaming keys in foreign keys and index constraints, and a regression test for moving an AUTOINCREMENT primary key (#3953).

Likely fixes #3994

Table::renameKeyInAllConstraints() looped over m_foreignKeys with
for(...; ++it) while the match_and_rename helper already advances the
iterator (it = container.erase(it)). After a rename the loop skipped the
next foreign key, leaving it on the old column name, and when the renamed
entry was the last one it incremented end(), which is undefined behaviour.

Let the helper advance the iterator, like the index constraint loop above.

Add tests for renaming keys in foreign keys and index constraints, and a
regression test for moving an AUTOINCREMENT primary key (sqlitebrowser#3953).

Likely fixes sqlitebrowser#3994

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Crash when changing primary key in Modify Table window

2 participants