@@ -453,7 +453,7 @@ void Table::removeConstraint(std::shared_ptr<CheckConstraint> constraint)
453453void Table::addKeyToConstraint (std::shared_ptr<UniqueConstraint> constraint, const std::string& key)
454454{
455455 // Search for matching constraint
456- for (auto it=m_indexConstraints.begin ();it!=m_indexConstraints.end ();++it )
456+ for (auto it=m_indexConstraints.begin ();it!=m_indexConstraints.end ();)
457457 {
458458 if (it->second == constraint)
459459 {
@@ -464,12 +464,16 @@ void Table::addKeyToConstraint(std::shared_ptr<UniqueConstraint> constraint, con
464464 m_indexConstraints.insert (std::make_pair (new_columns, it->second ));
465465 it = m_indexConstraints.erase (it);
466466 }
467+ else
468+ {
469+ ++it;
470+ }
467471 }
468472}
469473
470474void Table::removeKeyFromConstraint (std::shared_ptr<UniqueConstraint> constraint, const std::string& key)
471475{
472- for (auto it=m_indexConstraints.begin ();it!=m_indexConstraints.end ();++it )
476+ for (auto it=m_indexConstraints.begin ();it!=m_indexConstraints.end ();)
473477 {
474478 if (it->second == constraint)
475479 {
@@ -485,10 +489,8 @@ void Table::removeKeyFromConstraint(std::shared_ptr<UniqueConstraint> constraint
485489 m_indexConstraints.insert (std::make_pair (new_columns, it->second ));
486490 it = m_indexConstraints.erase (it);
487491 }
488-
489- // If container is empty now, return here instead of advancing the iterator
490- if (m_indexConstraints.empty ())
491- return ;
492+ } else {
493+ ++it;
492494 }
493495 }
494496}
@@ -511,17 +513,15 @@ void Table::removeKeyFromAllConstraints(const std::string& key)
511513 container.insert (std::make_pair (new_columns, it->second ));
512514 it = container.erase (it);
513515 }
514-
515- // If container is empty now, return here instead of advancing the iterator
516- if (container.empty ())
517- return ;
516+ } else {
517+ ++it;
518518 }
519519 };
520520
521- for (auto it=m_indexConstraints.begin ();it!=m_indexConstraints.end ();++it )
521+ for (auto it=m_indexConstraints.begin ();it!=m_indexConstraints.end ();)
522522 match_and_remove (m_indexConstraints, it);
523523
524- for (auto it=m_foreignKeys.begin ();it!=m_foreignKeys.end ();++it )
524+ for (auto it=m_foreignKeys.begin ();it!=m_foreignKeys.end ();)
525525 match_and_remove (m_foreignKeys, it);
526526}
527527
@@ -544,10 +544,14 @@ void Table::renameKeyInAllConstraints(const std::string& key, const std::string&
544544 container.insert (std::make_pair (new_columns, it->second ));
545545 it = container.erase (it);
546546 }
547+ else
548+ {
549+ ++it;
550+ }
547551 };
548552
549553 // Update all constraints
550- for (auto it=m_indexConstraints.begin ();it!=m_indexConstraints.end ();++it )
554+ for (auto it=m_indexConstraints.begin ();it!=m_indexConstraints.end ();)
551555 {
552556 match_and_rename (m_indexConstraints, it, [key, to](IndexedColumn c) {
553557 if (c == key)
0 commit comments