mirror of https://github.com/stella-emu/stella.git
Add a migration for an old settings DB (R77 style).
This commit is contained in:
parent
2e25d20554
commit
e06b58efaf
|
@ -25,7 +25,7 @@
|
|||
#include "repository/CompositeKVRJsonAdapter.hxx"
|
||||
#include "repository/KeyValueRepositoryConfigfile.hxx"
|
||||
#include "KeyValueRepositorySqlite.hxx"
|
||||
#include "SqliteTransaction.hxx"
|
||||
#include "SqliteStatement.hxx"
|
||||
#include "FSNode.hxx"
|
||||
|
||||
namespace {
|
||||
|
@ -75,8 +75,6 @@ void SettingsDb::initialize()
|
|||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void SettingsDb::initializeDb() {
|
||||
SqliteTransaction tx{*myDb};
|
||||
|
||||
FilesystemNode legacyConfigFile{myDatabaseDirectory};
|
||||
legacyConfigFile /= "stellarc";
|
||||
|
||||
|
@ -88,10 +86,26 @@ void SettingsDb::initializeDb() {
|
|||
|
||||
mySettingsRepository->save(KeyValueRepositoryConfigfile{legacyConfigFile}.load());
|
||||
}
|
||||
else if (legacyConfigDatabase.exists() && legacyConfigDatabase.isFile()) {
|
||||
Logger::info("importing old settings from " + legacyConfigDatabase.getPath());
|
||||
|
||||
try {
|
||||
SqliteStatement(
|
||||
*myDb,
|
||||
"ATTACH DATABASE ? AS old_db"
|
||||
)
|
||||
.bind(1, legacyConfigDatabase.getPath())
|
||||
.step();
|
||||
|
||||
myDb->exec("INSERT INTO `settings` SELECT * FROM `old_db`.`settings`");
|
||||
myDb->exec("DETACH DATABASE `old_db`");
|
||||
}
|
||||
catch (const SqliteError& err) {
|
||||
Logger::error(err.what());
|
||||
}
|
||||
}
|
||||
|
||||
myDb->setUserVersion(CURRENT_VERSION);
|
||||
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -97,7 +97,6 @@ void SqliteDatabase::exec(const string& sql) const
|
|||
Int32 SqliteDatabase::getUserVersion() const
|
||||
{
|
||||
SqliteStatement stmt(*this, "PRAGMA user_version");
|
||||
stmt.reset();
|
||||
|
||||
if (!stmt.step())
|
||||
throw SqliteError("failed to get user_version");
|
||||
|
@ -108,8 +107,6 @@ Int32 SqliteDatabase::getUserVersion() const
|
|||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void SqliteDatabase::setUserVersion(Int32 version) const
|
||||
{
|
||||
SqliteStatement stmt(*this, "PRAGMA user_version = %i", static_cast<int>(version));
|
||||
stmt.reset();
|
||||
|
||||
stmt.step();
|
||||
SqliteStatement(*this, "PRAGMA user_version = %i", static_cast<int>(version))
|
||||
.step();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue