mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-04-26 06:28:24 -05:00
EditTableDialog: Print error when trying to edit a column referenced in a FK
In the EditTableDialog, when trying to edit a column which is referenced in a foreign key of some other column (and thus cannot be changed without errors ocurring during the rename process) print an error message instead of just going on. See issue #362.
This commit is contained in:
@@ -216,6 +216,26 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
|
||||
switch(column)
|
||||
{
|
||||
case kName:
|
||||
// When editing an exiting table, check if any foreign keys would cause trouble in case this name is edited
|
||||
if(!m_bNewTable)
|
||||
{
|
||||
foreach(const DBBrowserObject& fkobj, pdb->getBrowsableObjects())
|
||||
{
|
||||
foreach(const sqlb::FieldPtr& fkfield, fkobj.table.fields())
|
||||
{
|
||||
if(fkfield->foreignKey().table() == m_table.name())
|
||||
{
|
||||
if(fkfield->foreignKey().columns().contains(field->name()) || field->primaryKey())
|
||||
{
|
||||
QMessageBox::warning(this, qApp->applicationName(), tr("This column is referenced in a foreign key in table %1, column %2 and thus "
|
||||
"its name cannot be changed.").arg(fkobj.getname()).arg(fkfield->name()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
field->setName(item->text(column));
|
||||
qobject_cast<QComboBox*>(ui->treeWidget->itemWidget(item, kType))->setProperty("column", item->text(column));
|
||||
if(!m_bNewTable)
|
||||
|
||||
Reference in New Issue
Block a user