Don't allow selection of tables/indices in VACUUM dialog

Remove the feature to select individual tables and indices to vacuum in
the vacuum dialog. Turns out SQLite doesn't support this (and apparently
never has). If you didn't select all tables at once, it would just print
errors to the console output. I have no idea why we ever implemented it
this way. However, the dialog could be reused to allow selection of
database schemata to compact - and this actually does work.
This commit is contained in:
Martin Kleusberg
2017-09-03 21:25:29 +02:00
parent 829e3107e5
commit c616b39478
2 changed files with 16 additions and 26 deletions

View File

@@ -16,19 +16,16 @@ VacuumDialog::VacuumDialog(DBBrowserDB* _db, QWidget* parent) :
ui->labelSavepointWarning->setVisible(db->getDirty());
// Populate list of objects to compact. We just support vacuuming the main schema here.
QList<sqlb::ObjectPtr> objects = db->schemata["main"].values("table");
objects.append(db->schemata["main"].values("index"));
for(QList<sqlb::ObjectPtr>::const_iterator i=objects.constBegin();i!=objects.constEnd();++i)
for(auto it=db->schemata.constBegin();it!=db->schemata.constEnd();++it)
{
QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeSelectedObjects);
item->setText(0, (*i)->name());
item->setIcon(0, QIcon(QString(":icons/%1").arg(sqlb::Object::typeToString((*i)->type()))));
ui->treeSelectedObjects->addTopLevelItem(item);
QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeDatabases);
item->setText(0, it.key());
item->setIcon(0, QIcon(QString(":icons/database")));
ui->treeDatabases->addTopLevelItem(item);
}
// Sort objects and select them all
ui->treeSelectedObjects->sortByColumn(0, Qt::AscendingOrder);
ui->treeSelectedObjects->selectAll();
// Select the first item which should always be the main schema
ui->treeDatabases->setCurrentItem(ui->treeDatabases->topLevelItem(0));
}
VacuumDialog::~VacuumDialog()
@@ -38,7 +35,7 @@ VacuumDialog::~VacuumDialog()
void VacuumDialog::accept()
{
if(ui->treeSelectedObjects->selectedItems().count() == 0)
if(ui->treeDatabases->selectedItems().count() == 0)
return QDialog::reject();
QApplication::setOverrideCursor(Qt::WaitCursor);
@@ -46,17 +43,10 @@ void VacuumDialog::accept()
// Commit all changes first
db->releaseAllSavepoints();
// All items selected?
if(ui->treeSelectedObjects->selectedItems().count() == ui->treeSelectedObjects->topLevelItemCount())
{
// Yes, so just execute a simple vacuum command for all objects
db->executeSQL("VACUUM;", false);
} else {
// No, so execute a vacuum command for each selected object individually
QList<QTreeWidgetItem*> selection = ui->treeSelectedObjects->selectedItems();
foreach(QTreeWidgetItem* item, selection)
db->executeSQL(QString("VACUUM %1;").arg(sqlb::escapeIdentifier(item->text(0))), false);
}
// Loop through all selected databases and vacuum them individually
QList<QTreeWidgetItem*> selection = ui->treeDatabases->selectedItems();
foreach(QTreeWidgetItem* item, selection)
db->executeSQL(QString("VACUUM %1;").arg(sqlb::escapeIdentifier(item->text(0))), false);
QApplication::restoreOverrideCursor();
QDialog::accept();

View File

@@ -36,15 +36,15 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Please select the objects to compact:</string>
<string>Please select the databases to co&amp;mpact:</string>
</property>
<property name="buddy">
<cstring>treeSelectedObjects</cstring>
<cstring>treeDatabases</cstring>
</property>
</widget>
</item>
<item>
<widget class="QTreeWidget" name="treeSelectedObjects">
<widget class="QTreeWidget" name="treeDatabases">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
@@ -86,7 +86,7 @@
</layout>
</widget>
<tabstops>
<tabstop>treeSelectedObjects</tabstop>
<tabstop>treeDatabases</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>