data: Fixed version check when opening older db

This commit is contained in:
Eberhard Graether
2016-01-08 14:51:11 +01:00
parent ffca8841ea
commit b8faa5506d
7 changed files with 42 additions and 15 deletions
+22 -3
View File
@@ -11,7 +11,6 @@
SqliteStorage::SqliteStorage(const std::string& dbFilePath)
{
m_database.open(dbFilePath.c_str());
setup();
}
SqliteStorage::~SqliteStorage()
@@ -19,6 +18,26 @@ SqliteStorage::~SqliteStorage()
m_database.close();
}
bool SqliteStorage::init()
{
Version version = getVersion();
if (version.isEmpty())
{
setup();
return false;
}
else if (version.isOlderStorageVersionThan(Version::getApplicationVersion()))
{
clear();
return false;
}
else
{
return true;
}
}
void SqliteStorage::setup()
{
m_database.execDML("PRAGMA foreign_keys=ON;");
@@ -688,8 +707,8 @@ void SqliteStorage::setupTables()
"defined INTEGER NOT NULL, "
"PRIMARY KEY(id), "
"FOREIGN KEY(id) REFERENCES element(id) ON DELETE CASCADE);"
);
);
m_database.execDML(
"CREATE INDEX IF NOT EXISTS node_serializedName_index ON node(serializedName);"
);