diff options
Diffstat (limited to 'SQLiteStudio3/coreSQLiteStudio/services/impl')
4 files changed, 70 insertions, 25 deletions
diff --git a/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.cpp b/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.cpp index bbfec32..046993f 100644 --- a/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.cpp @@ -13,6 +13,7 @@ #include <QRegExp> #include <QDateTime> #include <QSysInfo> +#include <QCoreApplication> #include <QtConcurrent/QtConcurrentRun> static_qstring(DB_FILE_NAME, "settings3"); @@ -28,6 +29,8 @@ void ConfigImpl::init() initDbFile(); initTables(); + sqlite3Version = db->exec("SELECT sqlite_version()")->getSingleCell().toString(); + connect(this, SIGNAL(sqlHistoryRefreshNeeded()), this, SLOT(refreshSqlHistory())); connect(this, SIGNAL(ddlHistoryRefreshNeeded()), this, SLOT(refreshDdlHistory())); } @@ -175,6 +178,11 @@ QString ConfigImpl::getLastErrorString() const return msg; } +QString ConfigImpl::getSqlite3Version() const +{ + return sqlite3Version; +} + QList<ConfigImpl::CfgDbPtr> ConfigImpl::dbList() { QList<CfgDbPtr> entries; @@ -467,23 +475,42 @@ QString ConfigImpl::getConfigPath() QString ConfigImpl::getPortableConfigPath() { + QStringList paths = QStringList({"./sqlitestudio-cfg", qApp->applicationDirPath() + "/sqlitestudio-cfg"}); + QSet<QString> pathSet; + QDir dir; + for (const QString& path : paths) + { + dir = QDir(path); + pathSet << dir.absolutePath(); + } + + QString potentialPath; QFileInfo file; - QDir dir("./sqlitestudio-cfg"); + for (const QString& path : pathSet) + { + dir = QDir(path); + file = QFileInfo(dir.absolutePath()); + if (!file.exists()) + { + if (potentialPath.isNull()) + potentialPath = dir.absolutePath(); - file = QFileInfo(dir.absolutePath()); - if (!file.exists()) - return dir.absolutePath(); + continue; + } - if (!file.isDir() || !file.isReadable() || !file.isWritable()) - return QString::null; + if (!file.isDir() || !file.isReadable() || !file.isWritable()) + continue; - foreach (file, dir.entryInfoList()) - { - if (!file.isReadable() || !file.isWritable()) - return QString::null; + foreach (file, dir.entryInfoList()) + { + if (!file.isReadable() || !file.isWritable()) + continue; + } + + return dir.absolutePath(); } - return dir.absolutePath(); + return potentialPath; } void ConfigImpl::initTables() diff --git a/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.h b/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.h index 63d1e1f..3bdb7a5 100644 --- a/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.h +++ b/SQLiteStudio3/coreSQLiteStudio/services/impl/configimpl.h @@ -36,6 +36,7 @@ class API_EXPORT ConfigImpl : public Config bool removeDb(const QString& name); bool isDbInConfig(const QString& name); QString getLastErrorString() const; + QString getSqlite3Version() const; /** * @brief Provides list of all registered databases. @@ -120,6 +121,7 @@ class API_EXPORT ConfigImpl : public Config SqlHistoryModel* sqlHistoryModel = nullptr; DdlHistoryModel* ddlHistoryModel = nullptr; QMutex sqlHistoryMutex; + QString sqlite3Version; public slots: void refreshDdlHistory(); diff --git a/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.cpp b/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.cpp index 43fc953..70aa568 100644 --- a/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/services/impl/dbmanagerimpl.cpp @@ -12,6 +12,7 @@ #include <QPluginLoader> #include <QDebug> #include <QUrl> +#include <QDir> #include <db/invaliddb.h> DbManagerImpl::DbManagerImpl(QObject *parent) : @@ -46,7 +47,13 @@ bool DbManagerImpl::addDb(const QString &name, const QString &path, const QHash< if (getByName(name)) { qWarning() << "Tried to add database with name that was already on the list:" << name; - return false; // db with this name exists + return false; + } + + if (getByPath(path)) + { + qWarning() << "Tried to add database with path that was already on the list:" << path; + return false; } QString errorMessage; @@ -74,24 +81,27 @@ bool DbManagerImpl::updateDb(Db* db, const QString &name, const QString &path, c return false; } + QDir pathDir(path); + QString normalizedPath = pathDir.absolutePath(); + listLock.lockForWrite(); nameToDb.remove(db->getName(), Qt::CaseInsensitive); pathToDb.remove(db->getPath()); - bool pathDifferent = db->getPath() != path; + bool pathDifferent = db->getPath() != normalizedPath; QString oldName = db->getName(); db->setName(name); - db->setPath(path); + db->setPath(normalizedPath); db->setConnectionOptions(options); bool result = false; if (permanent) { if (CFG->isDbInConfig(oldName)) - result = CFG->updateDb(oldName, name, path, options); + result = CFG->updateDb(oldName, name, normalizedPath, options); else - result = CFG->addDb(name, path, options); + result = CFG->addDb(name, normalizedPath, options); } else if (CFG->isDbInConfig(name)) // switched "permanent" off? result = CFG->removeDb(name); @@ -105,7 +115,7 @@ bool DbManagerImpl::updateDb(Db* db, const QString &name, const QString &path, c db = reloadedDb; nameToDb[name] = db; - pathToDb[path] = db; + pathToDb[normalizedPath] = db; listLock.unlock(); @@ -138,14 +148,17 @@ void DbManagerImpl::removeDbByName(const QString &name, Qt::CaseSensitivity cs) void DbManagerImpl::removeDbByPath(const QString &path) { + // Using QDir to normalize separator + QDir pathDir(path); + listLock.lockForRead(); - bool contains = pathToDb.contains(path); + bool contains = pathToDb.contains(pathDir.absolutePath()); listLock.unlock(); if (!contains) return; listLock.lockForWrite(); - Db* db = pathToDb[path]; + Db* db = pathToDb[pathDir.absolutePath()]; removeDbInternal(db); listLock.unlock(); @@ -230,7 +243,9 @@ Db* DbManagerImpl::getByName(const QString &name, Qt::CaseSensitivity cs) Db* DbManagerImpl::getByPath(const QString &path) { - return pathToDb.value(path); + // Using QDir to normalize separator + QDir pathDir(path); + return pathToDb.value(pathDir.absolutePath()); } Db* DbManagerImpl::createInMemDb() @@ -369,12 +384,13 @@ Db* DbManagerImpl::createDb(const QString &name, const QString &path, const QHas Db* db = nullptr; QStringList messages; QString message; + QDir pathDir(path); // Using QDir to normalize separator foreach (dbPlugin, dbPlugins) { if (options.contains("plugin") && options["plugin"] != dbPlugin->getName()) continue; - db = dbPlugin->getInstance(name, path, options, &message); + db = dbPlugin->getInstance(name, pathDir.absolutePath(), options, &message); if (!db) { messages << message; diff --git a/SQLiteStudio3/coreSQLiteStudio/services/impl/functionmanagerimpl.cpp b/SQLiteStudio3/coreSQLiteStudio/services/impl/functionmanagerimpl.cpp index c94e4c2..da732bd 100644 --- a/SQLiteStudio3/coreSQLiteStudio/services/impl/functionmanagerimpl.cpp +++ b/SQLiteStudio3/coreSQLiteStudio/services/impl/functionmanagerimpl.cpp @@ -147,9 +147,9 @@ void FunctionManagerImpl::evaluateScriptAggregateInitial(ScriptFunction* func, D aggregateStorage["context"] = QVariant::fromValue(ctx); if (dbAwarePlugin) - dbAwarePlugin->evaluate(ctx, func->code, {}, db, false); + dbAwarePlugin->evaluate(ctx, func->initCode, {}, db, false); else - plugin->evaluate(ctx, func->code, {}); + plugin->evaluate(ctx, func->initCode, {}); if (plugin->hasError(ctx)) { @@ -203,9 +203,9 @@ QVariant FunctionManagerImpl::evaluateScriptAggregateFinal(ScriptFunction* func, QVariant result; if (dbAwarePlugin) - result = dbAwarePlugin->evaluate(ctx, func->code, {}, db, false); + result = dbAwarePlugin->evaluate(ctx, func->finalCode, {}, db, false); else - result = plugin->evaluate(ctx, func->code, {}); + result = plugin->evaluate(ctx, func->finalCode, {}); if (plugin->hasError(ctx)) { |
