mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Load SQLite extensions earlier
In the Preferences dialog we allow the user to configure a list of SQLite extensions which should be loaded whenever a new database file is create or an existing database file is loaded. This commit changes the order of actions after creating or opening a file so that the extensions are loaded significantly earlier. This way they are already loaded for most of the time during the process. This fixes some subtle bugs. One of the more prominent ones was triggered when there is a view which uses some function which is defined in such an extension. After loading the file, parsing would fail and you couldn't see the fields of the view. Browsing it would work but trying to edit the display format crashed the application.
This commit is contained in:
@@ -401,7 +401,6 @@ bool MainWindow::fileOpen(const QString& fileName, bool dontAddToRecentFiles, bo
|
||||
if(!dontAddToRecentFiles)
|
||||
addToRecentFilesMenu(wFile);
|
||||
openSqlTab(true);
|
||||
loadExtensionsFromSettings();
|
||||
if(ui->mainTab->currentIndex() == BrowseTab)
|
||||
populateTable();
|
||||
else if(ui->mainTab->currentIndex() == PragmaTab)
|
||||
@@ -432,7 +431,6 @@ void MainWindow::fileNew()
|
||||
statusEncodingLabel->setText(db.getPragma("encoding"));
|
||||
statusEncryptionLabel->setVisible(false);
|
||||
statusReadOnlyLabel->setVisible(false);
|
||||
loadExtensionsFromSettings();
|
||||
populateTable();
|
||||
openSqlTab(true);
|
||||
createTable();
|
||||
@@ -446,7 +444,6 @@ void MainWindow::fileNewInMemoryDatabase()
|
||||
statusEncodingLabel->setText(db.getPragma("encoding"));
|
||||
statusEncryptionLabel->setVisible(false);
|
||||
statusReadOnlyLabel->setVisible(false);
|
||||
loadExtensionsFromSettings();
|
||||
populateTable();
|
||||
openSqlTab(true);
|
||||
createTable();
|
||||
@@ -1597,7 +1594,6 @@ void MainWindow::importDatabaseFromSQL()
|
||||
}
|
||||
|
||||
db.create(newDbFile);
|
||||
loadExtensionsFromSettings();
|
||||
}
|
||||
|
||||
// Defer foreign keys. Just deferring them instead of disabling them should work fine because in the import we only expect CREATE and INSERT
|
||||
@@ -2125,19 +2121,6 @@ void MainWindow::loadExtension()
|
||||
QMessageBox::warning(this, QApplication::applicationName(), tr("Error loading extension: %1").arg(db.lastError()));
|
||||
}
|
||||
|
||||
void MainWindow::loadExtensionsFromSettings()
|
||||
{
|
||||
if(!db.isOpen())
|
||||
return;
|
||||
|
||||
QStringList list = Settings::getValue("extensions", "list").toStringList();
|
||||
for(const QString& ext : list)
|
||||
{
|
||||
if(db.loadExtension(ext) == false)
|
||||
QMessageBox::warning(this, QApplication::applicationName(), tr("Error loading extension: %1").arg(db.lastError()));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::reloadSettings()
|
||||
{
|
||||
// Set data browser font
|
||||
@@ -2163,7 +2146,7 @@ void MainWindow::reloadSettings()
|
||||
editDock->reloadSettings();
|
||||
|
||||
// Load extensions
|
||||
loadExtensionsFromSettings();
|
||||
db.loadExtensionsFromSettings();
|
||||
|
||||
// Refresh view
|
||||
dbStructureModel->reloadData();
|
||||
|
||||
@@ -184,7 +184,6 @@ private:
|
||||
void addToRecentFilesMenu(const QString& filename);
|
||||
void activateFields(bool enable = true);
|
||||
void enableEditing(bool enable_edit);
|
||||
void loadExtensionsFromSettings();
|
||||
void saveAsView(QString query);
|
||||
void duplicateRecord(int currentRow);
|
||||
void selectTableLine(int lineToSelect);
|
||||
|
||||
@@ -156,6 +156,9 @@ bool DBBrowserDB::open(const QString& db, bool readOnly)
|
||||
QFileInfo fid(fi.absoluteDir().absolutePath());
|
||||
isReadOnly = readOnly || !fi.isWritable() || !fid.isWritable();
|
||||
|
||||
// Load extensions
|
||||
loadExtensionsFromSettings();
|
||||
|
||||
// Execute default SQL
|
||||
if(!isReadOnly)
|
||||
{
|
||||
@@ -532,6 +535,9 @@ bool DBBrowserDB::create ( const QString & db)
|
||||
executeSQL("DROP TABLE notempty;", false, false);
|
||||
}
|
||||
|
||||
// Load extensions
|
||||
loadExtensionsFromSettings();
|
||||
|
||||
// Execute default SQL
|
||||
QString default_sql = Settings::getValue("db", "defaultsqltext").toString();
|
||||
if(!default_sql.isEmpty())
|
||||
@@ -1808,6 +1814,20 @@ bool DBBrowserDB::loadExtension(const QString& filePath)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DBBrowserDB::loadExtensionsFromSettings()
|
||||
{
|
||||
if(!_db)
|
||||
return;
|
||||
|
||||
QStringList list = Settings::getValue("extensions", "list").toStringList();
|
||||
for(const QString& ext : list)
|
||||
{
|
||||
if(loadExtension(ext) == false)
|
||||
QMessageBox::warning(nullptr, QApplication::applicationName(), tr("Error loading extension: %1").arg(lastError()));
|
||||
}
|
||||
}
|
||||
|
||||
QVector<QPair<QString, QString>> DBBrowserDB::queryColumnInformation(const QString& schema_name, const QString& object_name)
|
||||
{
|
||||
waitForDbRelease();
|
||||
|
||||
@@ -171,6 +171,7 @@ public:
|
||||
bool setPragma(const QString& pragma, int value, int& originalvalue);
|
||||
|
||||
bool loadExtension(const QString& filename);
|
||||
void loadExtensionsFromSettings();
|
||||
|
||||
private:
|
||||
QVector<QPair<QString, QString>> queryColumnInformation(const QString& schema_name, const QString& object_name);
|
||||
|
||||
Reference in New Issue
Block a user