Support deleting table constraints in Edit Table dialog · anandsanto/sqlitebrowser@3f60142 · GitHub
Skip to content

Commit 3f60142

Browse files
committed
Support deleting table constraints in Edit Table dialog
This adds support for deleting table constraints in the Edit Table dialog.
1 parent 48a8481 commit 3f60142

5 files changed

Lines changed: 61 additions & 3 deletions

File tree

‎src/EditTableDialog.cpp‎

Lines changed: 27 additions & 2 deletions

‎src/EditTableDialog.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ private slots:
7272
void moveDown();
7373
void setWithoutRowid(bool without_rowid);
7474
void changeSchema(const QString& schema);
75+
void removeConstraint();
7576

7677
private:
7778
Ui::EditTableDialog* ui;

‎src/EditTableDialog.ui‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,22 @@
618618
</hint>
619619
</hints>
620620
</connection>
621+
<connection>
622+
<sender>buttonRemoveConstraint</sender>
623+
<signal>clicked()</signal>
624+
<receiver>EditTableDialog</receiver>
625+
<slot>removeConstraint()</slot>
626+
<hints>
627+
<hint type="sourcelabel">
628+
<x>186</x>
629+
<y>155</y>
630+
</hint>
631+
<hint type="destinationlabel">
632+
<x>647</x>
633+
<y>157</y>
634+
</hint>
635+
</hints>
636+
</connection>
621637
</connections>
622638
<slots>
623639
<slot>fieldSelectionChanged()</slot>
@@ -630,5 +646,6 @@
630646
<slot>moveDown()</slot>
631647
<slot>setWithoutRowid(bool)</slot>
632648
<slot>changeSchema(QString)</slot>
649+
<slot>removeConstraint()</slot>
633650
</slots>
634651
</ui>

‎src/sql/sqlitetypes.cpp‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,20 @@ void Table::setConstraint(const StringVector& vStrFields, ConstraintPtr constrai
509509
addConstraint(vStrFields, constraint);
510510
}
511511

512+
void Table::removeConstraint(const StringVector& vStrFields, ConstraintPtr constraint)
513+
{
514+
for(auto it = m_constraints.begin();it!=m_constraints.end();++it)
515+
{
516+
if(it->first == vStrFields && it->second->toSql(vStrFields) == constraint->toSql(vStrFields))
517+
{
518+
m_constraints.erase(it);
519+
520+
// Only remove the first constraint matching these criteria
521+
return;
522+
}
523+
}
524+
}
525+
512526
void Table::removeConstraints(const StringVector& vStrFields, Constraint::ConstraintTypes type)
513527
{
514528
for(auto it = m_constraints.begin();it!=m_constraints.end();)

‎src/sql/sqlitetypes.h‎

Lines changed: 2 additions & 1 deletion

0 commit comments

Comments
 (0)