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:
Martin Kleusberg
2015-06-21 22:18:48 +02:00
parent 0e18e36aa9
commit 0387999403
+20
View File
@@ -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)