Skip to content

Commit a5a3d7f

Browse files
committed
Fix crash when removing the only index constraint from a table
This fixes a possible endless loop when using the Edit Table dialog and removing the only index constraint (i.e. primary key and unique constraints) from the table. See issue #3245.
1 parent e56051c commit a5a3d7f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/sql/sqlitetypes.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,10 @@ void Table::removeKeyFromConstraint(std::shared_ptr<UniqueConstraint> constraint
485485
m_indexConstraints.insert(std::make_pair(new_columns, it->second));
486486
it = m_indexConstraints.erase(it);
487487
}
488+
489+
// If container is empty now, return here instead of advancing the iterator
490+
if(m_indexConstraints.empty())
491+
return;
488492
}
489493
}
490494
}
@@ -507,6 +511,10 @@ void Table::removeKeyFromAllConstraints(const std::string& key)
507511
container.insert(std::make_pair(new_columns, it->second));
508512
it = container.erase(it);
509513
}
514+
515+
// If container is empty now, return here instead of advancing the iterator
516+
if(container.empty())
517+
return;
510518
}
511519
};
512520

0 commit comments

Comments
 (0)