mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 19:11:39 -06:00
Fix editing of foreign keys in Edit Table dialog
Fix a bug when removing a foreign key from a table. Fix a bug when editing an existing foreign key on a table. See issue #918.
This commit is contained in:
@@ -440,9 +440,16 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
|
||||
callRenameColumn = true;
|
||||
break;
|
||||
case kForeignKey:
|
||||
sqlb::ForeignKeyClause* fk = new sqlb::ForeignKeyClause;
|
||||
fk->setFromString(item->text(column));
|
||||
m_table.addConstraint({field}, sqlb::ConstraintPtr(fk));
|
||||
if(item->text(column).trimmed().isEmpty())
|
||||
{
|
||||
// Remove the foreign key
|
||||
m_table.removeConstraints({field}, sqlb::Constraint::ConstraintTypes::ForeignKeyConstraintType);
|
||||
} else {
|
||||
// Set the foreign key
|
||||
sqlb::ForeignKeyClause* fk = new sqlb::ForeignKeyClause;
|
||||
fk->setFromString(item->text(column));
|
||||
m_table.setConstraint({field}, sqlb::ConstraintPtr(fk));
|
||||
}
|
||||
if(!m_bNewTable)
|
||||
callRenameColumn = true;
|
||||
break;
|
||||
|
||||
@@ -317,6 +317,15 @@ void Table::addConstraint(FieldVector fields, ConstraintPtr constraint)
|
||||
m_constraints.insert(fields, constraint);
|
||||
}
|
||||
|
||||
void Table::setConstraint(FieldVector fields, ConstraintPtr constraint)
|
||||
{
|
||||
// Delete any old constraints of this type for these fields
|
||||
removeConstraints(fields, constraint->type());
|
||||
|
||||
// Add the new constraint to the table, effectively overwriting all old constraints for that fields/type combination
|
||||
addConstraint(fields, constraint);
|
||||
}
|
||||
|
||||
void Table::removeConstraints(FieldVector fields, Constraint::ConstraintTypes type)
|
||||
{
|
||||
QList<ConstraintPtr> list = constraints(fields, type);
|
||||
|
||||
@@ -188,6 +188,7 @@ public:
|
||||
void clear();
|
||||
|
||||
void addConstraint(FieldVector fields, ConstraintPtr constraint);
|
||||
void setConstraint(FieldVector fields, ConstraintPtr constraint);
|
||||
void removeConstraints(FieldVector fields = FieldVector(), Constraint::ConstraintTypes type = Constraint::NoType); //! Only removes the first constraint, if any
|
||||
ConstraintPtr constraint(FieldVector fields = FieldVector(), Constraint::ConstraintTypes type = Constraint::NoType) const; //! Only returns the first constraint, if any
|
||||
QList<ConstraintPtr> constraints(FieldVector fields = FieldVector(), Constraint::ConstraintTypes type = Constraint::NoType) const;
|
||||
|
||||
Reference in New Issue
Block a user