data: Saving application version to storage and refresh when version changes

The version string of the application is stored on every parse. The utility class Version is used to parse the version
string and compare application and stored string. The third number in the version string is now the storage refresh
number, the project will be refreshed when it changes. (0.2.1 -> 0.2.2)
This commit is contained in:
Eberhard Graether
2015-11-02 10:14:03 +01:00
parent 1ad2dbe86e
commit 42ab36fbad
12 changed files with 256 additions and 12 deletions
+64
View File
@@ -6,6 +6,7 @@
#include "utility/text/TextAccess.h"
#include "utility/utility.h"
#include "utility/utilityString.h"
#include "utility/Version.h"
SqliteStorage::SqliteStorage(const std::string& dbFilePath)
{
@@ -47,6 +48,23 @@ void SqliteStorage::rollbackTransaction()
m_database.execDML("ROLLBACK TRANSACTION;");
}
Version SqliteStorage::getVersion() const
{
std::string versionStr = getMetaValue("version");
if (versionStr.size())
{
return Version::fromString(versionStr);
}
return Version();
}
void SqliteStorage::setVersion(const Version& version)
{
insertOrUpdateMetaValue("version", version.toString());
}
Id SqliteStorage::addEdge(int type, Id sourceNodeId, Id targetNodeId)
{
m_database.execDML(
@@ -708,10 +726,19 @@ void SqliteStorage::clearTables()
m_database.execDML("DROP TABLE IF EXISTS main.node;");
m_database.execDML("DROP TABLE IF EXISTS main.edge;");
m_database.execDML("DROP TABLE IF EXISTS main.element;");
m_database.execDML("DROP TABLE IF EXISTS main.meta;");
}
void SqliteStorage::setupTables()
{
m_database.execDML(
"CREATE TABLE IF NOT EXISTS meta("
"id INTEGER, "
"key TEXT, "
"value TEXT, "
"PRIMARY KEY(id));"
);
m_database.execDML(
"CREATE TABLE IF NOT EXISTS element("
"id INTEGER, "
@@ -793,6 +820,43 @@ void SqliteStorage::setupTables()
);
}
bool SqliteStorage::hasTable(const std::string& tableName) const
{
CppSQLite3Query q = m_database.execQuery((
"SELECT name FROM sqlite_master WHERE type='table' AND name='" + tableName + "';"
).c_str());
if (!q.eof())
{
return q.getStringField(0, "") == tableName;
}
return false;
}
std::string SqliteStorage::getMetaValue(const std::string& key) const
{
if (hasTable("meta"))
{
CppSQLite3Query q = m_database.execQuery(("SELECT value FROM meta WHERE key = '" + key + "';").c_str());
if (!q.eof())
{
return q.getStringField(0, "");
}
}
return "";
}
void SqliteStorage::insertOrUpdateMetaValue(const std::string& key, const std::string& value)
{
m_database.execDML((
"INSERT OR REPLACE INTO meta(id, key, value) "
"VALUES( (SELECT id FROM meta WHERE key = '" + key + "'), '" + key + "', '" + value + "');"
).c_str());
}
StorageFile SqliteStorage::getFirstFile(const std::string& query) const
{
CppSQLite3Query q = m_database.execQuery(query.c_str());