Skip to content


Don't allow selection of tables/indices in VACUUM dialog
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MKleusberg committed Sep 3, 2017
1 parent 829e310 commit c616b39
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
34 changes: 12 additions & 22 deletions src/VacuumDialog.cpp
Expand Up @@ -16,19 +16,16 @@ VacuumDialog::VacuumDialog(DBBrowserDB* _db, QWidget* parent) :

// Populate list of objects to compact. We just support vacuuming the main schema here.
QList<sqlb::ObjectPtr> objects = db->schemata["main"].values("table");
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()))));
QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeDatabases);
item->setText(0, it.key());
item->setIcon(0, QIcon(QString(":icons/database")));

// Sort objects and select them all
ui->treeSelectedObjects->sortByColumn(0, Qt::AscendingOrder);
// Select the first item which should always be the main schema

Expand All @@ -38,25 +35,18 @@ VacuumDialog::~VacuumDialog()

void VacuumDialog::accept()
if(ui->treeSelectedObjects->selectedItems().count() == 0)
if(ui->treeDatabases->selectedItems().count() == 0)
return QDialog::reject();


// Commit all changes first

// 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);

Expand Down
8 changes: 4 additions & 4 deletions src/VacuumDialog.ui
Expand Up @@ -36,15 +36,15 @@
<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 name="buddy">
<widget class="QTreeWidget" name="treeSelectedObjects">
<widget class="QTreeWidget" name="treeDatabases">
<property name="editTriggers">
Expand Down Expand Up @@ -86,7 +86,7 @@
Expand Down

0 comments on commit c616b39

Please sign in to comment.