Enhancement #1435: pragmas invoked from Tools menu

Pragmas integrity_check, quick_check, foreign_key_check and optimize are
integrated in the Tools menu. The actions open a confirmation dialog
(with Help button that opens the corresponding reference page in
sqlite.org) and, after confirmation, opens a new SQL editor tab and runs
there the pragma, showing the possible results.

Sender in executeQuery is null in this case, so a check is added.

Added accelerator to Tools menu entry, which lacked one.
This commit is contained in:
mgr
2018-09-16 18:54:25 +02:00
parent 9ca387886b
commit 18f0ef60ba
3 changed files with 93 additions and 2 deletions

View File

@@ -354,6 +354,20 @@ void MainWindow::init()
populateTable();
});
// Connect tool pragmas
connect(ui->actionIntegrityCheck, &QAction::triggered, [this]() {
runSqlNewTab("PRAGMA integrity_check;", ui->actionIntegrityCheck->text());
});
connect(ui->actionQuickCheck, &QAction::triggered, [this]() {
runSqlNewTab("PRAGMA quick_check;", ui->actionQuickCheck->text());
});
connect(ui->actionForeignKeyCheck, &QAction::triggered, [this]() {
runSqlNewTab("PRAGMA foreign_key_check;", ui->actionForeignKeyCheck->text());
});
connect(ui->actionOptimize, &QAction::triggered, [this]() {
runSqlNewTab("PRAGMA optimize;", ui->actionOptimize->text());
});
// Set other window settings
setAcceptDrops(true);
setWindowTitle(QApplication::applicationName());
@@ -1168,7 +1182,7 @@ void MainWindow::executeQuery()
Line
};
executionMode mode;
if(sender()->objectName() == "actionSqlExecuteLine")
if(sender() && sender()->objectName() == "actionSqlExecuteLine")
mode = Line;
else if(!sqlWidget->getSelectedSql().isEmpty())
mode = Selection;
@@ -1858,6 +1872,10 @@ void MainWindow::activateFields(bool enable)
ui->actionSqlExecuteLine->setEnabled(enable);
ui->actionSaveProject->setEnabled(enable && !tempDb);
ui->actionEncryption->setEnabled(enable && write && !tempDb);
ui->actionIntegrityCheck->setEnabled(enable);
ui->actionQuickCheck->setEnabled(enable);
ui->actionForeignKeyCheck->setEnabled(enable);
ui->actionOptimize->setEnabled(enable);
ui->buttonClearFilters->setEnabled(enable);
ui->buttonSaveFilterAsPopup->setEnabled(enable);
ui->dockEdit->setEnabled(enable);
@@ -3359,3 +3377,32 @@ void MainWindow::updateInsertDeleteRecordButton()
else
ui->buttonDeleteRecord->setText(tr("Delete Record"));
}
void MainWindow::runSqlNewTab(const QString& query, const QString& title)
{
QString message = tr("This action will open a new SQL tab for running:") +
QString("<br/><tt>%1</tt><p/>").arg(query) +
tr("Press Help for opening the corresponding SQLite reference page.");
QString windowTitle = title;
windowTitle.remove('&');
switch (QMessageBox::information(this, windowTitle, message, QMessageBox::Ok | QMessageBox::Default, QMessageBox::Cancel | QMessageBox::Escape, QMessageBox::Help))
{
case QMessageBox::Ok: {
ui->mainTab->setCurrentIndex(ExecuteTab);
unsigned int index = openSqlTab();
ui->tabSqlAreas->setTabText(index, title);
qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas->widget(index))->getEditor()->setText(query);
executeQuery();
break;
}
case QMessageBox::Help: {
QString anchor = query.toLower();
anchor.replace(" ", "_").chop(1);
QDesktopServices::openUrl(QUrl(QString("https://www.sqlite.org/pragma.html#") + anchor));
break;
}
default:
return;
}
}

View File

@@ -299,6 +299,7 @@ private slots:
void saveFilterAsView();
void exportFilteredTable();
void updateInsertDeleteRecordButton();
void runSqlNewTab(const QString& query, const QString& title);
};
#endif

View File

@@ -1029,12 +1029,17 @@ You can drag SQL statements from an object row and drop them into other applicat
</widget>
<widget class="QMenu" name="menuTools">
<property name="title">
<string>Tools</string>
<string>&amp;Tools</string>
</property>
<addaction name="fileCompactAction"/>
<addaction name="actionEncryption"/>
<addaction name="separator"/>
<addaction name="actionLoadExtension"/>
<addaction name="separator"/>
<addaction name="actionIntegrityCheck"/>
<addaction name="actionQuickCheck"/>
<addaction name="actionForeignKeyCheck"/>
<addaction name="actionOptimize"/>
</widget>
<addaction name="fileMenu"/>
<addaction name="editMenu"/>
@@ -2251,6 +2256,44 @@ You can drag SQL statements from the Schema column and drop them into the SQL ed
<string>Use escaped identifiers (e.g. &quot;Table1&quot;) when dragging the objects and dropping them into the editor </string>
</property>
</action>
<action name="actionIntegrityCheck">
<property name="text">
<string>&amp;Integrity Check</string>
</property>
<property name="whatsThis">
<string>Runs the integrity_check pragma over the opened database and returns the results in the Execute SQL tab. This pragma does an integrity check of the entire database.</string>
</property>
</action>
<action name="actionForeignKeyCheck">
<property name="text">
<string>&amp;Foreign-Key Check</string>
</property>
<property name="whatsThis">
<string>Runs the foreign_key_check pragma over the opened database and returns the results in the Execute SQL tab</string>
</property>
</action>
<action name="actionQuickCheck">
<property name="text">
<string>&amp;Quick Integrity Check</string>
</property>
<property name="toolTip">
<string>Run a quick integrity check over the open DB</string>
</property>
<property name="whatsThis">
<string>Runs the quick_check pragma over the opened database and returns the results in the Execute SQL tab. This command does most of the checking of PRAGMA integrity_check but runs much faster.</string>
</property>
</action>
<action name="actionOptimize">
<property name="text">
<string>&amp;Optimize</string>
</property>
<property name="toolTip">
<string>Attempt to optimize the database</string>
</property>
<property name="whatsThis">
<string>Runs the optimize pragma over the opened database. This pragma might perform optimizations that will improve the performance of future queries.</string>
</property>
</action>
<action name="actionSqlPrint">
<property name="icon">
<iconset resource="icons/icons.qrc">