mirror of
https://github.com/tnodir/fort
synced 2024-11-15 08:46:03 +00:00
UI: SQLite: Refactor default flags.
This commit is contained in:
parent
994e5fe67c
commit
5f4236f672
11
src/ui/3rdparty/sqlite/sqlitedb.cpp
vendored
11
src/ui/3rdparty/sqlite/sqlitedb.cpp
vendored
@ -58,15 +58,8 @@ SqliteDb::~SqliteDb()
|
||||
sqlite3_shutdown();
|
||||
}
|
||||
|
||||
bool SqliteDb::open(const QString &filePath, quint32 openFlags)
|
||||
bool SqliteDb::open()
|
||||
{
|
||||
if (!filePath.isEmpty()) {
|
||||
m_filePath = filePath;
|
||||
}
|
||||
if (openFlags != OpenVoid) {
|
||||
m_openFlags = openFlags;
|
||||
}
|
||||
|
||||
const auto filePathUtf8 = m_filePath.toUtf8();
|
||||
|
||||
return sqlite3_open_v2(filePathUtf8.data(), &m_db, m_openFlags, nullptr) == SQLITE_OK;
|
||||
@ -314,7 +307,7 @@ bool SqliteDb::migrate(const QString &sqlDir, const char *sqlPragmas, int versio
|
||||
|
||||
tempFilePath = m_filePath + ".temp";
|
||||
|
||||
if (!(renameDbFile(m_filePath, tempFilePath) && open(m_filePath))) {
|
||||
if (!(renameDbFile(m_filePath, tempFilePath) && open())) {
|
||||
dbWarning() << "Cannot re-create the DB" << m_filePath;
|
||||
renameDbFile(tempFilePath, m_filePath);
|
||||
return false;
|
||||
|
10
src/ui/3rdparty/sqlite/sqlitedb.h
vendored
10
src/ui/3rdparty/sqlite/sqlitedb.h
vendored
@ -17,8 +17,6 @@ class SqliteDb
|
||||
{
|
||||
public:
|
||||
enum OpenFlag {
|
||||
OpenVoid = -1,
|
||||
OpenDefault = 0,
|
||||
OpenReadOnly = 0x00000001, // SQLITE_OPEN_READONLY
|
||||
OpenReadWrite = 0x00000002, // SQLITE_OPEN_READWRITE
|
||||
OpenCreate = 0x00000004, // SQLITE_OPEN_CREATE
|
||||
@ -29,6 +27,7 @@ public:
|
||||
OpenSharedCache = 0x00020000, // SQLITE_OPEN_SHAREDCACHE
|
||||
OpenPrivateCache = 0x00040000, // SQLITE_OPEN_PRIVATECACHE
|
||||
OpenNoFollow = 0x01000000, // SQLITE_OPEN_NOFOLLOW
|
||||
OpenDefault = (OpenReadWrite | OpenCreate | OpenNoMutex)
|
||||
};
|
||||
|
||||
explicit SqliteDb(const QString &filePath = QString(), quint32 openFlags = OpenDefault);
|
||||
@ -38,9 +37,12 @@ public:
|
||||
struct sqlite3 *db() const { return m_db; }
|
||||
|
||||
quint32 openFlags() const { return m_openFlags; }
|
||||
QString filePath() const { return m_filePath; }
|
||||
void setOpenFlags(quint32 v) { m_openFlags = v; }
|
||||
|
||||
bool open(const QString &filePath = QString(), quint32 openFlags = OpenVoid);
|
||||
QString filePath() const { return m_filePath; }
|
||||
void setFilePath(const QString &v) { m_filePath = v; }
|
||||
|
||||
bool open();
|
||||
void close();
|
||||
|
||||
bool attach(const QString &schemaName, const QString &filePath = QString());
|
||||
|
@ -307,7 +307,7 @@ bool saveAppGroup(SqliteDb *db, AppGroup *appGroup, int orderIndex)
|
||||
ConfManager::ConfManager(const QString &filePath, FortManager *fortManager, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_fortManager(fortManager),
|
||||
m_sqliteDb(new SqliteDb(filePath, SqliteDb::OpenNoMutex)),
|
||||
m_sqliteDb(new SqliteDb(filePath)),
|
||||
m_conf(new FirewallConf(this))
|
||||
{
|
||||
m_appEndTimer.setInterval(5 * 60 * 1000); // 5 minutes
|
||||
|
@ -54,7 +54,7 @@ StatManager::StatManager(const QString &filePath, QuotaManager *quotaManager, QO
|
||||
m_isActivePeriodSet(false),
|
||||
m_isActivePeriod(false),
|
||||
m_quotaManager(quotaManager),
|
||||
m_sqliteDb(new SqliteDb(filePath, SqliteDb::OpenNoMutex))
|
||||
m_sqliteDb(new SqliteDb(filePath))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,8 @@ AppInfoManager::~AppInfoManager()
|
||||
|
||||
void AppInfoManager::setupDb(const QString &filePath)
|
||||
{
|
||||
if (!m_sqliteDb->open(filePath, SqliteDb::OpenNoMutex)) {
|
||||
m_sqliteDb->setFilePath(filePath);
|
||||
if (!m_sqliteDb->open()) {
|
||||
logCritical() << "File open error:" << filePath << m_sqliteDb->errorMessage();
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user