private void SetIdFromDb()
{
try
{
instance.WithDatabase(database, (session, dbid) =>
{
using (var details = new Table(session, dbid, "details", OpenTableGrbit.ReadOnly))
{
Api.JetMove(session, details, JET_Move.First, MoveGrbit.None);
var columnids = Api.GetColumnDictionary(session, details);
var column = Api.RetrieveColumn(session, details, columnids["id"]);
Id = new Guid(column);
var schemaVersion = Api.RetrieveColumnAsString(session, details, columnids["schema_version"]);
if (schemaVersion == SchemaCreator.SchemaVersion)
return;
do
{
var updater = Updaters.FirstOrDefault(update => update.Value.FromSchemaVersion == schemaVersion);
if (updater == null)
throw new InvalidOperationException(string.Format("The version on disk ({0}) is different that the version supported by this library: {1}{2}You need to migrate the disk version to the library version, alternatively, if the data isn't important, you can delete the file and it will be re-created (with no data) with the library version.", schemaVersion, SchemaCreator.SchemaVersion, Environment.NewLine));
updater.Value.Init(generator);
updater.Value.Update(session, dbid);
schemaVersion = Api.RetrieveColumnAsString(session, details, columnids["schema_version"]);
} while (schemaVersion != SchemaCreator.SchemaVersion);
}
});
}
catch (Exception e)
{
throw new InvalidOperationException(
"Could not read db details from disk. It is likely that there is a version difference between the library and the db on the disk." +
Environment.NewLine +
"You need to migrate the disk version to the library version, alternatively, if the data isn't important, you can delete the file and it will be re-created (with no data) with the library version.",
e);
}
}