Sqlitebrowser: Cannot create table with foreign key constraint when parent table name is prefix of new table name

Created on 10 Feb 2019  路  3Comments  路  Source: sqlitebrowser/sqlitebrowser

Details for the issue

What did you do?

  1. Create some table with a column you can reference as a foreign key. (Example: Route table, RouteId column.)
  2. Create another table whose name has the first table's name as a prefix. (Example: RouteDestination.)
  3. While creating the second table, attempt to add a foreign key reference to the first table. (Example: RouteDestination.RouteId pointing to Route.RouteId.)

What did you expect to see?

You can select the parent table from the dropdown as usual.

What did you see instead?

The parent table does not appear among the dropdown options.

Useful extra information

_Workaround:_ You can still add the constraint in the GUI by creating the table without the constraint, and then editing it.

What operating system are you using?

  • [x] Windows: ( _version:_10 Pro___ )
  • [ ] Linux: ( _distro:_ ___ )
  • [ ] Mac OS: ( _version:_ ___ )
  • [ ] Other: ___

Did you also

bug

All 3 comments

Thanks @noahplusplus, that sounds very bug-like. :innocent:

I've found the problem, but not yet a solution. Each keystroke in the table name text field triggers EditTableDialog::checkInput, which overwrites the old table name from the foreign key combo-box with the new table name using this call:

https://github.com/sqlitebrowser/sqlitebrowser/blob/4a728bd4f955dcfe6bb0cd500e1794649d541ec1/src/EditTableDialog.cpp#L209

When the new table name begins as an existing table, when the entered name is exactly equal to the existing table, this one is removed here:

https://github.com/sqlitebrowser/sqlitebrowser/blob/4a728bd4f955dcfe6bb0cd500e1794649d541ec1/src/ForeignKeyEditorDelegate.cpp#L182

We shouldn't do this update until the table name is definitive, but simply changing textChanged signal by editingFinished makes the application crash. So more changes are needed.

Maybe this is enough for someone to think a solution.

... makes the application crash.

Did you get a backtrace of the crash? It might be that's the thing which needs solving for this to work? :smile:

Was this page helpful?
0 / 5 - 0 ratings