mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
Fix adding primary keys to tables in the Edit Table dialog
Adding a primary key to a table that didn't had a primary key before would have added the column to the sqlb::Table::primaryKey::emptyFieldVector variable (which is static!) instead of actually creating a new primary key. This way the primary key wouldn't be created as a new table constraint. See issue #918.
This commit is contained in:
@@ -273,11 +273,19 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
|
||||
break;
|
||||
case kPrimaryKey:
|
||||
{
|
||||
sqlb::FieldVector& pk = m_table.primaryKeyRef();
|
||||
if(item->checkState(column) == Qt::Checked)
|
||||
pk.push_back(field);
|
||||
else
|
||||
pk.removeAll(field);
|
||||
// Check if there already is a primary key
|
||||
if(m_table.constraint(sqlb::FieldVector(), sqlb::Constraint::PrimaryKeyConstraintType))
|
||||
{
|
||||
// There already is a primary key for this table. So edit that one as there always can only be one primary key anyway.
|
||||
sqlb::FieldVector& pk = m_table.primaryKeyRef();
|
||||
if(item->checkState(column) == Qt::Checked)
|
||||
pk.push_back(field);
|
||||
else
|
||||
pk.removeAll(field);
|
||||
} else if(item->checkState(column) == Qt::Checked) {
|
||||
// There is no primary key in the table yet. This means we need to add a default one.
|
||||
m_table.addConstraint({field}, sqlb::ConstraintPtr(new sqlb::PrimaryKeyConstraint()));
|
||||
}
|
||||
|
||||
if(item->checkState(column) == Qt::Checked)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user