Skip to content

Commit

Permalink
feat: Add option to auto-load 'sqlean' extension (#3357)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucydodo committed Dec 29, 2023
1 parent 0038f0f commit 83649a3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/PreferencesDialog.cpp
Expand Up @@ -42,6 +42,10 @@ PreferencesDialog::PreferencesDialog(QWidget* parent, Tabs tab)
ui->checkUpdates->setVisible(false);
#endif

#ifndef Q_OS_MACX
ui->checkSqleanExtensionAutoload->setVisible(false);
#endif

loadSettings();

connect(ui->appStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(adjustColorsToStyle(int)));
Expand Down Expand Up @@ -208,6 +212,9 @@ void PreferencesDialog::loadSettings()
ui->listExtensions->addItems(Settings::getValue("extensions", "list").toStringList());
ui->checkRegexDisabled->setChecked(Settings::getValue("extensions", "disableregex").toBool());
ui->checkAllowLoadExtension->setChecked(Settings::getValue("extensions", "enable_load_extension").toBool());
#ifdef Q_OS_MACX
ui->checkSqleanExtensionAutoload->setChecked(Settings::getValue("extensions", "autoload_sqlean_extension").toBool());
#endif
fillLanguageBox();
ui->appStyleCombo->setCurrentIndex(Settings::getValue("General", "appStyle").toInt());
ui->toolbarStyleComboMain->setCurrentIndex(Settings::getValue("General", "toolbarStyle").toInt());
Expand Down Expand Up @@ -280,6 +287,9 @@ void PreferencesDialog::saveSettings(bool accept)
Settings::setValue("extensions", "list", extList);
Settings::setValue("extensions", "disableregex", ui->checkRegexDisabled->isChecked());
Settings::setValue("extensions", "enable_load_extension", ui->checkAllowLoadExtension->isChecked());
#ifdef Q_OS_MACX
Settings::setValue("extensions", "autoload_sqlean_extension", ui->checkSqleanExtensionAutoload->isChecked());
#endif

// Save remote settings
Settings::setValue("remote", "active", ui->checkUseRemotes->isChecked());
Expand Down
14 changes: 12 additions & 2 deletions src/PreferencesDialog.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>756</width>
<height>625</height>
<height>666</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -20,7 +20,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>4</number>
</property>
<widget class="QWidget" name="tab_4">
<attribute name="title">
Expand Down Expand Up @@ -1866,6 +1866,16 @@ Can be set to 0 for disabling completion.</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkSqleanExtensionAutoload">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Automatically load the 'nalgeon/sqlean' extension at program startup.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Automatically load the 'sqlean' extension</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabRemote">
Expand Down
9 changes: 9 additions & 0 deletions src/sqlitedb.cpp
Expand Up @@ -2170,6 +2170,15 @@ void DBBrowserDB::loadExtensionsFromSettings()
if(loadExtension(ext) == false)
QMessageBox::warning(nullptr, QApplication::applicationName(), tr("Error loading extension: %1").arg(lastError()));
}

if (Settings::getValue("extensions", "autoload_sqlean_extension").toBool())
{
const QString sqleanExtensionPath = qApp->applicationDirPath() + "/../Extensions/sqlean.dylib";
if (loadExtension(sqleanExtensionPath) == false) {
QMessageBox::warning(nullptr, QApplication::applicationName(), tr("Error loading 'sqlean' extension. Option is disabled."));
Settings::setValue("extensions", "autoload_sqlean_extension", false);
}
}
}

std::vector<std::pair<std::string, std::string>> DBBrowserDB::queryColumnInformation(const std::string& schema_name, const std::string& object_name) const
Expand Down

0 comments on commit 83649a3

Please sign in to comment.