mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Merge pull request #1246 from sqlitebrowser/save_filter_as_view
Save current filter, sort column and display formats as a new view
This commit is contained in:
@@ -1861,7 +1861,7 @@ void MainWindow::saveSqlResultsAsCsv()
|
||||
|
||||
void MainWindow::saveSqlResultsAsView()
|
||||
{
|
||||
qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas->currentWidget())->saveAsView();
|
||||
saveAsView(qobject_cast<SqlExecutionArea*>(ui->tabSqlAreas->currentWidget())->getModel()->query());
|
||||
}
|
||||
|
||||
void MainWindow::loadExtension()
|
||||
@@ -2719,3 +2719,35 @@ void MainWindow::openFindReplaceDialog()
|
||||
findReplaceDialog->show();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::saveAsView(QString query)
|
||||
{
|
||||
// Let the user select a name for the new view and make sure it doesn't already exist
|
||||
QString name;
|
||||
while(true)
|
||||
{
|
||||
name = QInputDialog::getText(this, qApp->applicationName(), tr("Please specify the view name")).trimmed();
|
||||
if(name.isNull())
|
||||
return;
|
||||
if(db.getObjectByName(sqlb::ObjectIdentifier("main", name)) != nullptr)
|
||||
QMessageBox::warning(this, qApp->applicationName(), tr("There is already an object with that name. Please choose a different name."));
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
// Create the view
|
||||
if(db.executeSQL(QString("CREATE VIEW %1 AS %2;").arg(sqlb::escapeIdentifier(name)).arg(query)))
|
||||
QMessageBox::information(this, qApp->applicationName(), tr("View successfully created."));
|
||||
else
|
||||
QMessageBox::warning(this, qApp->applicationName(), tr("Error creating view: %1").arg(db.lastError()));
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::saveFilterAsView()
|
||||
{
|
||||
if (m_browseTableModel->filterCount() > 0)
|
||||
// Save as view a custom query without rowid
|
||||
saveAsView(m_browseTableModel->customQuery(false));
|
||||
else
|
||||
QMessageBox::information(this, qApp->applicationName(), tr("There is no filter set for this table. View will not be created."));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user