From feda8a7db8d1d7c5439aa8f8feef7cc0dd2b59a0 Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Fri, 27 Jul 2018 23:51:12 -0400 Subject: New upstream version 3.2.1+dfsg1 --- .../services/impl/collationmanagerimpl.cpp | 4 +- .../coreSQLiteStudio/services/impl/configimpl.cpp | 311 +++++++++++++++++++-- .../coreSQLiteStudio/services/impl/configimpl.h | 20 +- .../services/impl/dbmanagerimpl.cpp | 13 +- .../coreSQLiteStudio/services/impl/dbmanagerimpl.h | 2 +- .../services/impl/functionmanagerimpl.cpp | 8 +- .../services/impl/pluginmanagerimpl.cpp | 28 +- .../services/impl/sqliteextensionmanagerimpl.cpp | 70 +++++ .../services/impl/sqliteextensionmanagerimpl.h | 23 ++ 9 files changed, 432 insertions(+), 47 deletions(-) create mode 100644 SQLiteStudio3/coreSQLiteStudio/services/impl/sqliteextensionmanagerimpl.cpp create mode 100644 SQLiteStudio3/coreSQLiteStudio/services/impl/sqliteextensionmanagerimpl.h (limited to 'SQLiteStudio3/coreSQLiteStudio/services/impl') diff --git a/SQLiteStudio3/coreSQLiteStudio/services/impl/collationmanagerimpl.cpp b/SQLiteStudio3/coreSQLiteStudio/services/impl/collationmanagerimpl.cpp index 5876021..7d24e47 100644 --- a/SQLiteStudio3/coreSQLiteStudio/services/impl/collationmanagerimpl.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/services/impl/collationmanagerimpl.cpp @@ -27,7 +27,7 @@ QList CollationManagerImpl::getAllCollations() c QList CollationManagerImpl::getCollationsForDatabase(const QString& dbName) const { QList results; - foreach (const CollationPtr& coll, collations) + for (const CollationPtr& coll : collations) { if (coll->allDatabases || coll->databases.contains(dbName, Qt::CaseInsensitive)) results << coll; @@ -120,6 +120,6 @@ void CollationManagerImpl::loadFromConfig() void CollationManagerImpl::refreshCollationsByKey() { collationsByKey.clear(); - foreach (CollationPtr collation, collations) + for (CollationPtr collation : collations) collationsByKey[collation->name] = collation; } diff --git a/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.cpp b/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.cpp index cf8b115..860e828 100644 --- a/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.cpp @@ -4,6 +4,7 @@ #include "services/notifymanager.h" #include "sqlitestudio.h" #include "db/dbsqlite3.h" +#include "common/utils.h" #include #include #include @@ -94,11 +95,7 @@ bool ConfigImpl::isMassSaving() const void ConfigImpl::set(const QString &group, const QString &key, const QVariant &value) { - QByteArray bytes; - QDataStream stream(&bytes, QIODevice::WriteOnly); - stream << value; - - db->exec("INSERT OR REPLACE INTO settings VALUES (?, ?, ?)", {group, key, bytes}); + db->exec("INSERT OR REPLACE INTO settings VALUES (?, ?, ?)", {group, key, serializeToBytes(value)}); } QVariant ConfigImpl::get(const QString &group, const QString &key) @@ -107,6 +104,15 @@ QVariant ConfigImpl::get(const QString &group, const QString &key) return deserializeValue(results->getSingleCell()); } +QVariant ConfigImpl::get(const QString &group, const QString &key, const QVariant &defaultValue) +{ + QVariant value = get(group, key); + if (!value.isValid() || value.isNull()) + return defaultValue; + + return value; +} + QHash ConfigImpl::getAll() { SqlQueryPtr results = db->exec("SELECT [group], [key], value FROM settings"); @@ -225,7 +231,7 @@ void ConfigImpl::storeGroups(const QList& groups) db->begin(); db->exec("DELETE FROM groups"); - foreach (const DbGroupPtr& group, groups) + for (const DbGroupPtr& group : groups) storeGroup(group); db->commit(); @@ -241,7 +247,7 @@ void ConfigImpl::storeGroup(const ConfigImpl::DbGroupPtr &group, qint64 parentId {group->name, group->order, parent, group->open, group->referencedDbName}); qint64 newParentId = results->getRegularInsertRowId(); - foreach (const DbGroupPtr& childGroup, group->childs) + for (const DbGroupPtr& childGroup : group->childs) storeGroup(childGroup, newParentId); } @@ -304,6 +310,11 @@ void ConfigImpl::clearSqlHistory() QtConcurrent::run(this, &ConfigImpl::asyncClearSqlHistory); } +void ConfigImpl::deleteSqlHistory(const QList& ids) +{ + QtConcurrent::run(this, &ConfigImpl::asyncDeleteSqlHistory, ids); +} + QAbstractItemModel* ConfigImpl::getSqlHistoryModel() { if (!sqlHistoryModel) @@ -338,6 +349,122 @@ QStringList ConfigImpl::getCliHistory() const return results->columnAsList("text"); } +void ConfigImpl::addBindParamHistory(const QVector >& params) +{ + QtConcurrent::run(this, &ConfigImpl::asyncAddBindParamHistory, params); +} + +void ConfigImpl::applyBindParamHistoryLimit() +{ + QtConcurrent::run(this, &ConfigImpl::asyncApplyBindParamHistoryLimit); +} + +QVector> ConfigImpl::getBindParamHistory(const QStringList& paramNames) const +{ + static_qstring(directQuery, "SELECT id FROM bind_params WHERE pattern = ? ORDER BY id DESC"); + static_qstring(paramsByIdQuery, "SELECT name, value FROM bind_param_values WHERE bind_params_id = ? ORDER BY position"); + static_qstring(singleParamQuery, "SELECT value FROM bind_param_values WHERE %1 = ? ORDER BY id DESC LIMIT 1;"); + static_qstring(singleParamName, "name"); + static_qstring(singleParamPosition, "position"); + + QVector> bindParams; + bindParams.reserve(paramNames.size()); + + SqlQueryPtr results = db->exec(directQuery, {paramNames.join(",")}); + if (results->isError()) + { + qWarning() << "Error while getting BindParams (1):" << db->getErrorText(); + return bindParams; + } + + // Got an exact match? Extract values and return. + QVariant exactMatch = results->getSingleCell(); + if (!exactMatch.isNull()) + { + results = db->exec(paramsByIdQuery, {exactMatch.toLongLong()}); + if (results->isError()) + { + qWarning() << "Error while getting BindParams (2):" << db->getErrorText(); + } + else + { + for (const SqlResultsRowPtr& row : results->getAll()) + bindParams << QPair(row->value("name").toString(), row->value("value")); + } + return bindParams; + } + + // No exact match. Will look for values one by one using param name and position. + int position = 0; + for (const QString& bindParam : paramNames) + { + if (bindParam == "?") + results = db->exec(singleParamQuery.arg(singleParamPosition), {position}); + else + results = db->exec(singleParamQuery.arg(singleParamName), {bindParam}); + + bindParams << QPair(bindParam, results->getSingleCell()); + position++; + } + return bindParams; +} + +void ConfigImpl::addPopulateHistory(const QString& database, const QString& table, int rows, const QHash >& columnsPluginsConfig) +{ + QtConcurrent::run(this, &ConfigImpl::asyncAddPopulateHistory, database, table, rows, columnsPluginsConfig); +} + +void ConfigImpl::applyPopulateHistoryLimit() +{ + QtConcurrent::run(this, &ConfigImpl::asyncApplyPopulateHistoryLimit); +} + +QHash> ConfigImpl::getPopulateHistory(const QString& database, const QString& table, int& rows) const +{ + static_qstring(initialQuery, "SELECT id, rows FROM populate_history WHERE [database] = ? AND [table] = ? ORDER BY id DESC LIMIT 1"); + static_qstring(columnsQuery, "SELECT column_name, plugin_name, plugin_config FROM populate_column_history WHERE populate_history_id = ?"); + + QHash> historyEntry; + SqlQueryPtr results = db->exec(initialQuery, {database, table}); + if (results->isError()) + { + qWarning() << "Error while getting Populating history entry (1):" << db->getErrorText(); + return historyEntry; + } + + if (!results->hasNext()) + return historyEntry; + + SqlResultsRowPtr row = results->next(); + qint64 historyEntryId = row->value("id").toLongLong(); + rows = row->value("rows").toInt(); + + results = db->exec(columnsQuery, {historyEntryId}); + QVariant value; + while (results->hasNext()) + { + row = results->next(); + value = deserializeValue(row->value("plugin_config")); + historyEntry[row->value("column_name").toString()] = QPair(row->value("plugin_name").toString(), value); + } + + return historyEntry; +} + +QVariant ConfigImpl::getPopulateHistory(const QString& pluginName) const +{ + static_qstring(columnsQuery, "SELECT plugin_config FROM populate_column_history WHERE plugin_name = ? ORDER BY id DESC LiMIT 1"); + + SqlQueryPtr results = db->exec(columnsQuery, {pluginName}); + if (results->isError()) + { + qWarning() << "Error while getting Populating history entry (2):" << db->getErrorText(); + return QVariant(); + } + + return deserializeValue(results->getSingleCell()); +} + void ConfigImpl::addDdlHistory(const QString& queries, const QString& dbName, const QString& dbFile) { QtConcurrent::run(this, &ConfigImpl::asyncAddDdlHistory, queries, dbName, dbFile); @@ -503,9 +630,9 @@ QString ConfigImpl::getPortableConfigPath() if (!file.isDir() || !file.isReadable() || !file.isWritable()) continue; - foreach (file, dir.entryInfoList()) + for (const QFileInfo& entryFile : dir.entryInfoList()) { - if (!file.isReadable() || !file.isWritable()) + if (!entryFile.isReadable() || !entryFile.isWritable()) continue; } @@ -522,8 +649,7 @@ void ConfigImpl::initTables() if (!tables.contains("version")) { - QString table; - foreach (table, tables) + for (const QString& table : tables) db->exec("DROP TABLE "+table); tables.clear(); @@ -554,6 +680,34 @@ void ConfigImpl::initTables() if (!tables.contains("reports_history")) db->exec("CREATE TABLE reports_history (id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp INTEGER, feature_request BOOLEAN, title TEXT, url TEXT)"); + + if (!tables.contains("bind_params")) + { + db->exec("CREATE TABLE bind_params (id INTEGER PRIMARY KEY AUTOINCREMENT, pattern TEXT NOT NULL)"); + db->exec("CREATE INDEX bind_params_patt_idx ON bind_params (pattern);"); + } + + if (!tables.contains("bind_param_values")) + { + db->exec("CREATE TABLE bind_param_values (id INTEGER PRIMARY KEY AUTOINCREMENT, bind_params_id INTEGER REFERENCES bind_params (id) " + "ON DELETE CASCADE ON UPDATE CASCADE NOT NULL, position INTEGER NOT NULL, name TEXT NOT NULL, value)"); + db->exec("CREATE INDEX bind_param_values_fk_idx ON bind_param_values (bind_params_id);"); + } + + if (!tables.contains("populate_history")) + { + db->exec("CREATE TABLE populate_history (id INTEGER PRIMARY KEY AUTOINCREMENT, [database] TEXT NOT NULL, [table] TEXT NOT NULL, rows INTEGER NOT NULL)"); + } + + if (!tables.contains("populate_column_history")) + { + db->exec("CREATE TABLE populate_column_history (id INTEGER PRIMARY KEY AUTOINCREMENT, populate_history_id INTEGER REFERENCES populate_history (id) " + "ON DELETE CASCADE ON UPDATE CASCADE NOT NULL, column_name TEXT NOT NULL, plugin_name TEXT NOT NULL, plugin_config BLOB)"); + db->exec("CREATE INDEX populate_plugin_history_idx ON populate_column_history (plugin_name)"); + } + + if (!tables.contains("reports_history")) + db->exec("CREATE TABLE reports_history (id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp INTEGER, feature_request BOOLEAN, title TEXT, url TEXT)"); } void ConfigImpl::initDbFile() @@ -646,19 +800,13 @@ bool ConfigImpl::tryInitDbFile(const QPair &dbPath) return true; } -QVariant ConfigImpl::deserializeValue(const QVariant &value) +QVariant ConfigImpl::deserializeValue(const QVariant &value) const { if (!value.isValid()) return QVariant(); QByteArray bytes = value.toByteArray(); - if (bytes.isNull()) - return QVariant(); - - QVariant deserializedValue; - QDataStream stream(bytes); - stream >> deserializedValue; - return deserializedValue; + return deserializeFromBytes(bytes); } void ConfigImpl::asyncAddSqlHistory(qint64 id, const QString& sql, const QString& dbName, int timeSpentMillis, int rowsAffected) @@ -709,6 +857,23 @@ void ConfigImpl::asyncClearSqlHistory() emit sqlHistoryRefreshNeeded(); } +void ConfigImpl::asyncDeleteSqlHistory(const QList& ids) +{ + if (!db->begin()) { + NOTIFY_MANAGER->warn(tr("Could not start database transaction for deleting SQL history, therefore it's not deleted.")); + return; + } + for (const qint64& id : ids) + db->exec("DELETE FROM sqleditor_history WHERE id = ?", id); + + if (!db->commit()) { + NOTIFY_MANAGER->warn(tr("Could not commit database transaction for deleting SQL history, therefore it's not deleted.")); + db->rollback(); + return; + } + emit sqlHistoryRefreshNeeded(); +} + void ConfigImpl::asyncAddCliHistory(const QString& text) { static_qstring(insertQuery, "INSERT INTO cli_history (text) VALUES (?)"); @@ -722,7 +887,7 @@ void ConfigImpl::asyncAddCliHistory(const QString& text) void ConfigImpl::asyncApplyCliHistoryLimit() { - static_qstring(limitQuery, "DELETE FROM cli_history WHERE id >= (SELECT id FROM cli_history ORDER BY id LIMIT 1 OFFSET %1)"); + static_qstring(limitQuery, "DELETE FROM cli_history WHERE id <= (SELECT id FROM cli_history ORDER BY id DESC LIMIT 1 OFFSET %1)"); SqlQueryPtr results = db->exec(limitQuery.arg(CFG_CORE.Console.HistorySize.get())); if (results->isError()) @@ -738,6 +903,105 @@ void ConfigImpl::asyncClearCliHistory() qWarning() << "Error while clearing CLI history:" << db->getErrorText(); } +void ConfigImpl::asyncAddBindParamHistory(const QVector >& params) +{ + static_qstring(insertParamsQuery, "INSERT INTO bind_params (pattern) VALUES (?)"); + static_qstring(insertValuesQuery, "INSERT INTO bind_param_values (bind_params_id, position, name, value) VALUES (?, ?, ?, ?)"); + + if (!db->begin()) + { + qWarning() << "Failed to store BindParam cache, because could not begin SQL transaction. Details:" << db->getErrorText(); + return; + } + + QStringList paramNames; + for (const QPair& paramPair : params) + paramNames << paramPair.first; + + SqlQueryPtr results = db->exec(insertParamsQuery, {paramNames.join(",")}); + RowId rowId = results->getInsertRowId(); + qint64 bindParamsId = rowId["ROWID"].toLongLong(); + + int position = 0; + for (const QPair& paramPair : params) + { + results = db->exec(insertValuesQuery, {bindParamsId, position++, paramPair.first, paramPair.second}); + if (results->isError()) + { + qWarning() << "Failed to store BindParam cache, due to SQL error:" << db->getErrorText(); + db->rollback(); + return; + } + } + + if (!db->commit()) + { + qWarning() << "Failed to store BindParam cache, because could not commit SQL transaction. Details:" << db->getErrorText(); + db->rollback(); + } + + asyncApplyBindParamHistoryLimit(); +} + +void ConfigImpl::asyncApplyBindParamHistoryLimit() +{ + static_qstring(findBindParamIdQuery, "SELECT bind_params_id FROM bind_param_values ORDER BY id DESC LIMIT 1 OFFSET %1"); + static_qstring(limitBindParamsQuery, "DELETE FROM bind_params WHERE id <= ?"); // will cascade with FK to bind_param_values + + SqlQueryPtr results = db->exec(findBindParamIdQuery.arg(CFG_CORE.General.BindParamsCacheSize.get())); + if (results->isError()) + qWarning() << "Error while limiting BindParam history (step 1):" << db->getErrorText(); + + qint64 bindParamId = results->getSingleCell().toLongLong(); + results = db->exec(limitBindParamsQuery, {bindParamId}); + if (results->isError()) + qWarning() << "Error while limiting BindParam history (step 2):" << db->getErrorText(); +} + +void ConfigImpl::asyncAddPopulateHistory(const QString& database, const QString& table, int rows, const QHash>& columnsPluginsConfig) +{ + static_qstring(insertQuery, "INSERT INTO populate_history ([database], [table], rows) VALUES (?, ?, ?)"); + static_qstring(insertColumnQuery, "INSERT INTO populate_column_history (populate_history_id, column_name, plugin_name, plugin_config) VALUES (?, ?, ?, ?)"); + + if (!db->begin()) + { + qWarning() << "Failed to store Populating history entry, because could not begin SQL transaction. Details:" << db->getErrorText(); + return; + } + + SqlQueryPtr results = db->exec(insertQuery, {database, table, rows}); + RowId rowId = results->getInsertRowId(); + qint64 populateHistoryId = rowId["ROWID"].toLongLong(); + + for (QHash>::const_iterator colIt = columnsPluginsConfig.begin(); colIt != columnsPluginsConfig.end(); colIt++) + { + results = db->exec(insertColumnQuery, {populateHistoryId, colIt.key(), colIt.value().first, serializeToBytes(colIt.value().second)}); + if (results->isError()) + { + qWarning() << "Failed to store Populating history entry, due to SQL error:" << db->getErrorText(); + db->rollback(); + return; + } + } + + if (!db->commit()) + { + qWarning() << "Failed to store Populating history entry, because could not commit SQL transaction. Details:" << db->getErrorText(); + db->rollback(); + } + + asyncApplyPopulateHistoryLimit(); +} + +void ConfigImpl::asyncApplyPopulateHistoryLimit() +{ + static_qstring(limitQuery, "DELETE FROM populate_history WHERE id <= (SELECT id FROM populate_history ORDER BY id DESC LIMIT 1 OFFSET %1)"); + + SqlQueryPtr results = db->exec(limitQuery.arg(CFG_CORE.General.PopulateHistorySize.get())); + if (results->isError()) + qWarning() << "Error while limiting Populating history:" << db->getErrorText(); +} + void ConfigImpl::asyncAddDdlHistory(const QString& queries, const QString& dbName, const QString& dbFile) { static_qstring(insert, "INSERT INTO ddl_history (dbname, file, timestamp, queries) VALUES (?, ?, ?, ?)"); @@ -799,7 +1063,12 @@ void ConfigImpl::mergeMasterConfig() if (masterConfigFile.isEmpty()) return; - qInfo() << "Updating settings from master configuration file: " << masterConfigFile; +#if QT_VERSION >= 0x050500 + qInfo() +#else + qDebug() +#endif + << "Updating settings from master configuration file: " << masterConfigFile; Db* masterDb = new DbSqlite3("SQLiteStudio master settings", masterConfigFile, {{DB_PURE_INIT, true}}); if (!masterDb->open()) diff --git a/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.h b/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.h index 08bcec7..561aab4 100644 --- a/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.h +++ b/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.h @@ -29,6 +29,7 @@ class API_EXPORT ConfigImpl : public Config bool isMassSaving() const; void set(const QString& group, const QString& key, const QVariant& value); QVariant get(const QString& group, const QString& key); + QVariant get(const QString& group, const QString& key, const QVariant& defaultValue); QHash getAll(); bool addDb(const QString& name, const QString& path, const QHash &options); @@ -56,6 +57,7 @@ class API_EXPORT ConfigImpl : public Config qint64 addSqlHistory(const QString& sql, const QString& dbName, int timeSpentMillis, int rowsAffected); void updateSqlHistory(qint64 id, const QString& sql, const QString& dbName, int timeSpentMillis, int rowsAffected); void clearSqlHistory(); + void deleteSqlHistory(const QList& ids); QAbstractItemModel* getSqlHistoryModel(); void addCliHistory(const QString& text); @@ -63,6 +65,15 @@ class API_EXPORT ConfigImpl : public Config void clearCliHistory(); QStringList getCliHistory() const; + void addBindParamHistory(const QVector>& params); + void applyBindParamHistoryLimit(); + QVector> getBindParamHistory(const QStringList& paramNames) const; + + void addPopulateHistory(const QString& database, const QString& table, int rows, const QHash>& columnsPluginsConfig); + void applyPopulateHistoryLimit(); + QHash> getPopulateHistory(const QString& database, const QString& table, int& rows) const; + QVariant getPopulateHistory(const QString& pluginName) const; + void addDdlHistory(const QString& queries, const QString& dbName, const QString& dbFile); QList getDdlHistoryFor(const QString& dbName, const QString& dbFile, const QDate& date); DdlHistoryModel* getDdlHistoryModel(); @@ -94,16 +105,23 @@ class API_EXPORT ConfigImpl : public Config void initTables(); void initDbFile(); bool tryInitDbFile(const QPair& dbPath); - QVariant deserializeValue(const QVariant& value); + QVariant deserializeValue(const QVariant& value) const; void asyncAddSqlHistory(qint64 id, const QString& sql, const QString& dbName, int timeSpentMillis, int rowsAffected); void asyncUpdateSqlHistory(qint64 id, const QString& sql, const QString& dbName, int timeSpentMillis, int rowsAffected); void asyncClearSqlHistory(); + void asyncDeleteSqlHistory(const QList &ids); void asyncAddCliHistory(const QString& text); void asyncApplyCliHistoryLimit(); void asyncClearCliHistory(); + void asyncAddBindParamHistory(const QVector>& params); + void asyncApplyBindParamHistoryLimit(); + + void asyncAddPopulateHistory(const QString& database, const QString& table, int rows, const QHash>& columnsPluginsConfig); + void asyncApplyPopulateHistoryLimit(); + void asyncAddDdlHistory(const QString& queries, const QString& dbName, const QString& dbFile); void asyncClearDdlHistory(); diff --git a/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.cpp b/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.cpp index 74f482f..217c2b7 100644 --- a/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.cpp @@ -23,7 +23,8 @@ DbManagerImpl::DbManagerImpl(QObject *parent) : DbManagerImpl::~DbManagerImpl() { - foreach (Db* db, dbList) +// qDebug() << "DbManagerImpl::~DbManagerImpl()"; + for (Db* db : dbList) { disconnect(db, SIGNAL(disconnected()), this, SLOT(dbDisconnectedSlot())); disconnect(db, SIGNAL(aboutToDisconnect(bool&)), this, SLOT(dbAboutToDisconnect(bool&))); @@ -261,12 +262,16 @@ Db* DbManagerImpl::getByPath(const QString &path) return pathToDb.value(pathDir.absolutePath()); } -Db* DbManagerImpl::createInMemDb() +Db* DbManagerImpl::createInMemDb(bool pureInit) { if (!inMemDbCreatorPlugin) return nullptr; - return inMemDbCreatorPlugin->getInstance("", ":memory:", {}); + QHash opts; + if (pureInit) + opts[DB_PURE_INIT] = true; + + return inMemDbCreatorPlugin->getInstance("", ":memory:", opts); } bool DbManagerImpl::isTemporary(Db* db) @@ -341,7 +346,7 @@ void DbManagerImpl::loadInitialDbList() { QUrl url; InvalidDb* db = nullptr; - foreach (const Config::CfgDbPtr& cfgDb, CFG->dbList()) + for (const Config::CfgDbPtr& cfgDb : CFG->dbList()) { db = new InvalidDb(cfgDb->name, cfgDb->path, cfgDb->options); diff --git a/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.h b/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.h index 2e3630a..5f99f86 100644 --- a/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.h +++ b/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.h @@ -42,7 +42,7 @@ class API_EXPORT DbManagerImpl : public DbManager QStringList getDbNames(); Db* getByName(const QString& name, Qt::CaseSensitivity cs = Qt::CaseInsensitive); Db* getByPath(const QString& path); - Db* createInMemDb(); + Db* createInMemDb(bool pureInit = false); bool isTemporary(Db* db); QString quickAddDb(const QString &path, const QHash &options); DbPlugin* getPluginForDbFile(const QString& filePath); diff --git a/SQLiteStudio3/coreSQLiteStudio/services/impl/functionmanagerimpl.cpp b/SQLiteStudio3/coreSQLiteStudio/services/impl/functionmanagerimpl.cpp index 826b34b..2fcc689 100644 --- a/SQLiteStudio3/coreSQLiteStudio/services/impl/functionmanagerimpl.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/services/impl/functionmanagerimpl.cpp @@ -40,7 +40,7 @@ QList FunctionManagerImpl::getAllScriptFunctio QList FunctionManagerImpl::getScriptFunctionsForDatabase(const QString& dbName) const { QList results; - foreach (ScriptFunction* func, functions) + for (ScriptFunction* func : functions) { if (func->allDatabases || func->databases.contains(dbName, Qt::CaseInsensitive)) results << func; @@ -280,10 +280,10 @@ void FunctionManagerImpl::initNativeFunctions() void FunctionManagerImpl::refreshFunctionsByKey() { functionsByKey.clear(); - foreach (ScriptFunction* func, functions) + for (ScriptFunction* func : functions) functionsByKey[Key(func)] = func; - foreach (NativeFunction* func, nativeFunctions) + for (NativeFunction* func : nativeFunctions) nativeFunctionsByKey[Key(func)] = func; } @@ -291,7 +291,7 @@ void FunctionManagerImpl::storeInConfig() { QVariantList list; QHash fnHash; - foreach (ScriptFunction* func, functions) + for (ScriptFunction* func : functions) { fnHash["name"] = func->name; fnHash["lang"] = func->lang; diff --git a/SQLiteStudio3/coreSQLiteStudio/services/impl/pluginmanagerimpl.cpp b/SQLiteStudio3/coreSQLiteStudio/services/impl/pluginmanagerimpl.cpp index 9fe21de..c67156c 100644 --- a/SQLiteStudio3/coreSQLiteStudio/services/impl/pluginmanagerimpl.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/services/impl/pluginmanagerimpl.cpp @@ -50,7 +50,7 @@ void PluginManagerImpl::deinit() emit aboutToQuit(); // Plugin containers and their plugins - foreach (PluginContainer* container, pluginContainer.values()) + for (PluginContainer* container : pluginContainer.values()) { if (container->builtIn) { @@ -61,13 +61,13 @@ void PluginManagerImpl::deinit() unload(container->name); } - foreach (PluginContainer* container, pluginContainer.values()) + for (PluginContainer* container : pluginContainer.values()) delete container; pluginContainer.clear(); // Types - foreach (PluginType* type, registeredPluginTypes) + for (PluginType* type : registeredPluginTypes) delete type; registeredPluginTypes.clear(); @@ -113,10 +113,10 @@ void PluginManagerImpl::scanPlugins() nameFilters << "*.so" << "*.dll" << "*.dylib"; QPluginLoader* loader = nullptr; - foreach (QString pluginDirPath, pluginDirs) + for (QString pluginDirPath : pluginDirs) { QDir pluginDir(pluginDirPath); - foreach (QString fileName, pluginDir.entryList(nameFilters, QDir::Files)) + for (QString fileName : pluginDir.entryList(nameFilters, QDir::Files)) { fileName = pluginDir.absoluteFilePath(fileName); loader = new QPluginLoader(fileName); @@ -158,7 +158,7 @@ bool PluginManagerImpl::initPlugin(QPluginLoader* loader, const QString& fileNam QJsonObject pluginMetaData = loader->metaData(); QString pluginTypeName = pluginMetaData.value("MetaData").toObject().value("type").toString(); PluginType* pluginType = nullptr; - foreach (PluginType* type, registeredPluginTypes) + for (PluginType* type : registeredPluginTypes) { if (type->getName() == pluginTypeName) { @@ -169,7 +169,7 @@ bool PluginManagerImpl::initPlugin(QPluginLoader* loader, const QString& fileNam if (!pluginType) { - qWarning() << "Could not load plugin" + fileName + "because its type was not recognized:" << pluginTypeName; + qWarning() << "Could not load plugin" << fileName << "because its type was not recognized:" << pluginTypeName; return false; } @@ -305,7 +305,7 @@ bool PluginManagerImpl::initPlugin(Plugin* plugin) { QString pluginName = plugin->getName(); PluginType* pluginType = nullptr; - foreach (PluginType* type, registeredPluginTypes) + for (PluginType* type : registeredPluginTypes) { if (type->test(plugin)) { @@ -316,7 +316,7 @@ bool PluginManagerImpl::initPlugin(Plugin* plugin) if (!pluginType) { - qWarning() << "Could not load built-in plugin" + pluginName + "because its type was not recognized."; + qWarning() << "Could not load built-in plugin" << pluginName << "because its type was not recognized."; return false; } @@ -363,7 +363,7 @@ QStringList PluginManagerImpl::getAllPluginNames(PluginType* type) const if (!pluginCategories.contains(type)) return names; - foreach (PluginContainer* container, pluginCategories[type]) + for (PluginContainer* container : pluginCategories[type]) names << container->name; return names; @@ -685,7 +685,7 @@ QList PluginManagerImpl::getLoadedPlugins(PluginType* type) const if (!pluginCategories.contains(type)) return list; - foreach (PluginContainer* container, pluginCategories[type]) + for (PluginContainer* container : pluginCategories[type]) { if (container->loaded) list << container->plugin; @@ -769,7 +769,7 @@ bool PluginManagerImpl::arePluginsInitiallyLoaded() const QList PluginManagerImpl::getLoadedPlugins() const { QList plugins; - foreach (PluginContainer* container, pluginContainer.values()) + for (PluginContainer* container : pluginContainer.values()) { if (container->loaded) plugins << container->plugin; @@ -780,7 +780,7 @@ QList PluginManagerImpl::getLoadedPlugins() const QStringList PluginManagerImpl::getLoadedPluginNames() const { QStringList names; - foreach (PluginContainer* container, pluginContainer.values()) + for (PluginContainer* container : pluginContainer.values()) { if (container->loaded) names << container->name; @@ -792,7 +792,7 @@ QList PluginManagerImpl::getAllPluginDetails() con { QList results; PluginManager::PluginDetails details; - foreach (PluginContainer* container, pluginContainer.values()) + for (PluginContainer* container : pluginContainer.values()) { details.name = container->name; details.title = container->title; diff --git a/SQLiteStudio3/coreSQLiteStudio/services/impl/sqliteextensionmanagerimpl.cpp b/SQLiteStudio3/coreSQLiteStudio/services/impl/sqliteextensionmanagerimpl.cpp new file mode 100644 index 0000000..63dbaf6 --- /dev/null +++ b/SQLiteStudio3/coreSQLiteStudio/services/impl/sqliteextensionmanagerimpl.cpp @@ -0,0 +1,70 @@ +#include "sqliteextensionmanagerimpl.h" +#include "services/notifymanager.h" +#include "services/dbmanager.h" + +SqliteExtensionManagerImpl::SqliteExtensionManagerImpl() +{ + init(); +} + +void SqliteExtensionManagerImpl::setExtensions(const QList& newExtensions) +{ + extensions = newExtensions; + storeInConfig(); + emit extensionListChanged(); +} + +QList SqliteExtensionManagerImpl::getAllExtensions() const +{ + return extensions; +} + +QList SqliteExtensionManagerImpl::getExtensionForDatabase(const QString& dbName) const +{ + QList results; + for (const ExtensionPtr& ext : extensions) + { + if (ext->allDatabases || ext->databases.contains(dbName, Qt::CaseInsensitive)) + results << ext; + } + return results; +} + +void SqliteExtensionManagerImpl::init() +{ + loadFromConfig(); +} + +void SqliteExtensionManagerImpl::storeInConfig() +{ + QVariantList list; + QHash extHash; + for (ExtensionPtr ext : extensions) + { + extHash["filePath"] = ext->filePath; + extHash["initFunc"] = ext->initFunc; + extHash["allDatabases"] = ext->allDatabases; + extHash["databases"] =common(DBLIST->getDbNames(), ext->databases); + list << extHash; + } + CFG_CORE.Internal.Extensions.set(list); +} + +void SqliteExtensionManagerImpl::loadFromConfig() +{ + extensions.clear(); + + QVariantList list = CFG_CORE.Internal.Extensions.get(); + QHash extHash; + ExtensionPtr ext; + for (const QVariant& var : list) + { + extHash = var.toHash(); + ext = ExtensionPtr::create(); + ext->filePath = extHash["filePath"].toString(); + ext->initFunc = extHash["initFunc"].toString(); + ext->databases = extHash["databases"].toStringList(); + ext->allDatabases = extHash["allDatabases"].toBool(); + extensions << ext; + } +} diff --git a/SQLiteStudio3/coreSQLiteStudio/services/impl/sqliteextensionmanagerimpl.h b/SQLiteStudio3/coreSQLiteStudio/services/impl/sqliteextensionmanagerimpl.h new file mode 100644 index 0000000..6fd7f46 --- /dev/null +++ b/SQLiteStudio3/coreSQLiteStudio/services/impl/sqliteextensionmanagerimpl.h @@ -0,0 +1,23 @@ +#ifndef SQLITEEXTENSIONMANAGERIMPL_H +#define SQLITEEXTENSIONMANAGERIMPL_H + +#include "services/sqliteextensionmanager.h" + +class SqliteExtensionManagerImpl : public SqliteExtensionManager +{ + public: + SqliteExtensionManagerImpl(); + + void setExtensions(const QList& newExtensions); + QList getAllExtensions() const; + QList getExtensionForDatabase(const QString& dbName) const; + + private: + void init(); + void storeInConfig(); + void loadFromConfig(); + + QList extensions; +}; + +#endif // SQLITEEXTENSIONMANAGERIMPL_H -- cgit v1.2.3