Allow setting the temporary table flag in Edit Table dialog

Add a new option to the Edit Table dialog for creating temporary tables.
This also allows the conversion between temporary and permanent tables.
This commit is contained in:
Martin Kleusberg
2017-01-16 11:15:16 +01:00
parent cd2f14e2dc
commit 6cc850c167
4 changed files with 63 additions and 13 deletions
+21 -1
View File
@@ -40,10 +40,11 @@ EditTableDialog::EditTableDialog(DBBrowserDB& db, const QString& tableName, bool
m_table.setTemporary(obj.isTemporary());
ui->labelEditWarning->setVisible(!parse_result.second);
// Set without rowid checkbox. No need to trigger any events here as we're only loading a table exactly as it is stored by SQLite, so no need
// Set without rowid and temporary checkboxex. No need to trigger any events here as we're only loading a table exactly as it is stored by SQLite, so no need
// for error checking etc.
ui->checkWithoutRowid->blockSignals(true);
ui->checkWithoutRowid->setChecked(m_table.isWithoutRowidTable());
ui->checkTemporary->setChecked(m_table.isTemporary());
ui->checkWithoutRowid->blockSignals(false);
populateFields();
@@ -716,6 +717,25 @@ void EditTableDialog::setWithoutRowid(bool without_rowid)
}
}
void EditTableDialog::setTemporary(bool is_temp)
{
// Set the temporary flag in the table definition
m_table.setTemporary(is_temp);
// Update the SQL preview
updateSqlText();
// Update table if we're editing an existing table
if(!m_bNewTable)
{
if(!pdb.renameColumn(curTable, m_table, QString(), sqlb::FieldPtr(), 0))
{
QMessageBox::warning(this, QApplication::applicationName(),
tr("Setting the temporary flag for the table failed. Error message:\n%1").arg(pdb.lastErrorMessage));
}
}
}
bool EditTableDialog::fieldNameExists(const QString& name)
{
foreach(const sqlb::FieldPtr& ptr, m_table.fields())
+1
View File
@@ -58,6 +58,7 @@ private slots:
void moveUp();
void moveDown();
void setWithoutRowid(bool without_rowid);
void setTemporary(bool is_temp);
private:
Ui::EditTableDialog* ui;
+40 -12
View File
@@ -66,6 +66,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkTemporary">
<property name="toolTip">
<string>Set this to create a temporary table that is deleted when closing the database.</string>
</property>
<property name="text">
<string>Temporary table</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -322,6 +332,7 @@
<tabstop>editTableName</tabstop>
<tabstop>buttonMore</tabstop>
<tabstop>checkWithoutRowid</tabstop>
<tabstop>checkTemporary</tabstop>
<tabstop>addFieldButton</tabstop>
<tabstop>removeFieldButton</tabstop>
<tabstop>buttonMoveUp</tabstop>
@@ -388,8 +399,8 @@
<slot>addField()</slot>
<hints>
<hint type="sourcelabel">
<x>79</x>
<y>203</y>
<x>94</x>
<y>253</y>
</hint>
<hint type="destinationlabel">
<x>79</x>
@@ -404,8 +415,8 @@
<slot>removeField()</slot>
<hints>
<hint type="sourcelabel">
<x>232</x>
<y>203</y>
<x>222</x>
<y>253</y>
</hint>
<hint type="destinationlabel">
<x>249</x>
@@ -436,8 +447,8 @@
<slot>moveUp()</slot>
<hints>
<hint type="sourcelabel">
<x>356</x>
<y>203</y>
<x>343</x>
<y>253</y>
</hint>
<hint type="destinationlabel">
<x>308</x>
@@ -452,8 +463,8 @@
<slot>moveDown()</slot>
<hints>
<hint type="sourcelabel">
<x>497</x>
<y>203</y>
<x>481</x>
<y>253</y>
</hint>
<hint type="destinationlabel">
<x>308</x>
@@ -472,8 +483,8 @@
<y>78</y>
</hint>
<hint type="destinationlabel">
<x>103</x>
<y>98</y>
<x>117</x>
<y>176</y>
</hint>
</hints>
</connection>
@@ -484,8 +495,8 @@
<slot>setWithoutRowid(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>324</x>
<y>113</y>
<x>344</x>
<y>143</y>
</hint>
<hint type="destinationlabel">
<x>324</x>
@@ -509,6 +520,22 @@
</hint>
</hints>
</connection>
<connection>
<sender>checkTemporary</sender>
<signal>toggled(bool)</signal>
<receiver>EditTableDialog</receiver>
<slot>setTemporary(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>186</x>
<y>155</y>
</hint>
<hint type="destinationlabel">
<x>647</x>
<y>157</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>fieldSelectionChanged()</slot>
@@ -520,5 +547,6 @@
<slot>moveUp()</slot>
<slot>moveDown()</slot>
<slot>setWithoutRowid(bool)</slot>
<slot>setTemporary(bool)</slot>
</slots>
</ui>
+1
View File
@@ -1026,6 +1026,7 @@ bool DBBrowserDB::renameColumn(const QString& tablename, const sqlb::Table& tabl
newSchema.setName("sqlitebrowser_rename_column_new_table");
newSchema.setConstraints(table.allConstraints());
newSchema.setRowidColumn(table.rowidColumn());
newSchema.setTemporary(table.isTemporary());
QString select_cols;
if(to.isNull())
{