Skip to content

Commit 6448ed7

Browse files
dnuzhdinMKleusberg
authored andcommitted
Add assignment of ON CONFLICT clause into GUI
1 parent ef87dc6 commit 6448ed7

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

src/EditTableDialog.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ EditTableDialog::EditTableDialog(DBBrowserDB& db, const sqlb::ObjectIdentifier&
9696
ui->comboSchema->setCurrentText(QString::fromStdString(curTable.schema()));
9797
ui->comboSchema->blockSignals(false);
9898

99+
if(m_table.primaryKey())
100+
{
101+
ui->checkWithoutRowid->blockSignals(true);
102+
ui->comboOnConflict->setCurrentText(QString::fromStdString(m_table.primaryKey()->conflictAction()).toUpper());
103+
ui->checkWithoutRowid->blockSignals(false);
104+
}
105+
99106
populateFields();
100107
populateConstraints();
101108
} else {
@@ -981,6 +988,26 @@ void EditTableDialog::changeSchema(const QString& /*schema*/)
981988
updateSqlText();
982989
}
983990

991+
void EditTableDialog::setOnConflict(const QString& on_conflict)
992+
{
993+
if(m_table.primaryKey())
994+
{
995+
m_table.primaryKey()->setConflictAction(on_conflict.toStdString());
996+
} else {
997+
QMessageBox::information(this, QApplication::applicationName(),
998+
tr("Please add a field which meets the following criteria before setting the on conflict action:\n"
999+
" - Primary key flag set"));
1000+
1001+
ui->comboOnConflict->blockSignals(true);
1002+
ui->comboOnConflict->setCurrentText(QString());
1003+
ui->comboOnConflict->blockSignals(false);
1004+
return;
1005+
}
1006+
1007+
// Update the SQL preview
1008+
updateSqlText();
1009+
}
1010+
9841011
void EditTableDialog::removeConstraint()
9851012
{
9861013
// Is there any item selected to delete?

src/EditTableDialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ private slots:
8585
void changeSchema(const QString& schema);
8686
void removeConstraint();
8787
void addConstraint(sqlb::Constraint::ConstraintTypes type);
88+
void setOnConflict(const QString& on_conflict);
8889

8990
private:
9091
Ui::EditTableDialog* ui;

src/EditTableDialog.ui

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,47 @@
8686
</property>
8787
</widget>
8888
</item>
89+
<item row="2" column="0">
90+
<widget class="QLabel" name="label_2">
91+
<property name="text">
92+
<string>On Conflict</string>
93+
</property>
94+
</widget>
95+
</item>
96+
<item row="2" column="1">
97+
<widget class="QComboBox" name="comboOnConflict">
98+
<item>
99+
<property name="text">
100+
<string notr="true"/>
101+
</property>
102+
</item>
103+
<item>
104+
<property name="text">
105+
<string notr="true">ROLLBACK</string>
106+
</property>
107+
</item>
108+
<item>
109+
<property name="text">
110+
<string notr="true">ABORT</string>
111+
</property>
112+
</item>
113+
<item>
114+
<property name="text">
115+
<string notr="true">FAIL</string>
116+
</property>
117+
</item>
118+
<item>
119+
<property name="text">
120+
<string notr="true">IGNORE</string>
121+
</property>
122+
</item>
123+
<item>
124+
<property name="text">
125+
<string notr="true">REPLACE</string>
126+
</property>
127+
</item>
128+
</widget>
129+
</item>
89130
</layout>
90131
</widget>
91132
</item>
@@ -778,6 +819,22 @@
778819
</hint>
779820
</hints>
780821
</connection>
822+
<connection>
823+
<sender>comboOnConflict</sender>
824+
<signal>currentIndexChanged(QString)</signal>
825+
<receiver>EditTableDialog</receiver>
826+
<slot>setOnConflict(QString)</slot>
827+
<hints>
828+
<hint type="sourcelabel">
829+
<x>371</x>
830+
<y>168</y>
831+
</hint>
832+
<hint type="destinationlabel">
833+
<x>490</x>
834+
<y>211</y>
835+
</hint>
836+
</hints>
837+
</connection>
781838
</connections>
782839
<slots>
783840
<slot>fieldSelectionChanged()</slot>
@@ -793,5 +850,6 @@
793850
<slot>removeConstraint()</slot>
794851
<slot>moveTop()</slot>
795852
<slot>moveBottom()</slot>
853+
<slot>setOnConflict(QString)</slot>
796854
</slots>
797855
</ui>

0 commit comments

Comments
 (0)