mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Add menu item to allow attaching other databases
Add a new menu option which allows attaching other databases. Doing so by running the SQL code by yourself using the Execute SQL tab won't work because the SQL tab creates a restorepoint and attaching databases while being in a transaction is not allowed. Note that this commit misses quite a few features: In case of name conflicts the UI may break, there is no way to tell which databases have been attached and the attached databases are not stored in the project files. See issue #100.
This commit is contained in:
@@ -822,6 +822,7 @@ void MainWindow::dbState( bool dirty )
|
||||
{
|
||||
ui->fileSaveAction->setEnabled(dirty);
|
||||
ui->fileRevertAction->setEnabled(dirty);
|
||||
ui->fileAttachAction->setEnabled(!dirty);
|
||||
}
|
||||
|
||||
void MainWindow::fileSave()
|
||||
@@ -1932,3 +1933,26 @@ void MainWindow::saveProject()
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::fileAttach()
|
||||
{
|
||||
// Get file name of database to attach
|
||||
QString file = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
tr("Choose a database file"),
|
||||
PreferencesDialog::getSettingsValue("db", "defaultlocation").toString());
|
||||
if(!QFile::exists(file))
|
||||
return;
|
||||
|
||||
// Ask for name to be given to the attached database
|
||||
QString attachAs = QInputDialog::getText(this,
|
||||
qApp->applicationName(),
|
||||
tr("Please specify the database name under which you want to access the attached database")
|
||||
).trimmed();
|
||||
if(attachAs.isEmpty())
|
||||
return;
|
||||
|
||||
// Attach database
|
||||
if(!db.executeSQL(QString("ATTACH '%1' AS `%2`").arg(file).arg(attachAs), false))
|
||||
QMessageBox::warning(this, qApp->applicationName(), db.lastErrorMessage);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user