在应用程序中的SQLite文件版本的兼容性 [英] SQLite File version compatibility within an application

查看:449
本文介绍了在应用程序中的SQLite文件版本的兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在其中用户输入数据和处理的信息是使用JSON序列化和EF保存到SQLite的文件中的C#.NET应用程序(一种复杂的计算应用程序)。同样可以在需要时被装载到我们的应用程序

I have a C# .NET application (kind of complex calculation app) in which the user inputs data and the processed information is saved into SQLite file using JSON serialization and EF. The same can be loaded into our application when required.

的应用经历很多变化发展期间和类也修改。所以在SQLite的文件中先前保存的序列化对象不同于更新之一。

The application undergoes lot of changes during development and the classes are also modified. So the previously saved serialized objects in SQLite file differs from the newer one.

我想为旧的文件提供一个相容性,以便它可以在新的应用程序打开

i want to provide a compatibilty for the old files so that it can be opened in the new application.

在简单,一个.NET类级XYZ有一个成员使用JSON序列化,并在一个SQLite文件保存为BLOB布尔。后来在应用程序的新版本,阶级XYZ的布尔成员体改为int。如何与布尔类型以前保存的文件反序列化到新的应用程序?

In simple, a .NET class "class XYZ" with bool as a member is serialized using JSON and saved as BLOB in a SQLite file. Later in the newer version of app, the bool member of the "class XYZ" is modifed as int. how to deserialize the previously saved file with bool type into the new app?

有在SQLite的表结构的变化,以及在整个版。如何在.NET实现这一目标?

There are changes in the SQLite table structure as well across the version. how to achieve this in .NET?

推荐答案

这是一个很常见的问题,而不是绑定到C#语言,我认为。 It've看到实现这种版本的方法有两种:

This is a pretty common problem, not bound to C# language I think. It've seen two methods of achieving such a versioning:


  1. 只有一个 INTEGER创建一个表列其中包含只有一行(从而模拟数据库变量)包含数据库和结构模式两种版本。每个模式更改你增加与之相关联的版本。对于每一个新版本,你写的升级语句和函数获取原始的JSON对象(不转换成类实例,因为他们将不兼容),更新,删除和创建改变结构域。然后,你写的转换结构升级的架构。我已经做到了多次,当然,这相当乏味,你必须要细致,但是这几乎是这样做(即我所知道的)的唯一可靠方法。

  2. 使用库如协议缓冲区已对结构的变化支持(有限,当然) 。这样的库可以帮助您在结构上的变化,而不是在数据库架构的变化 - 无论哪种方式,你可能要保持提到的单细胞表架构版本,每当一个较低的数字被认为是升级
  3. $ B $。 b
  1. Create a table with only one INTEGER column which holds only one row (thus simulating a database variable) containing version of both the database and structure schema. With each schema change you increase the version associated with it. For each new version you write upgrade statements and functions fetching raw JSON objects (not converted to class instances since they won't be compatible), updating, deleting and creating changed structure fields. Then you write converted structures to the upgraded schema. I've done it multiple times and sure, it quite tedious and you have to be meticulous, but that's pretty much the only reliable way of doing that (that I'm aware of).
  2. Use a library such as Protocol Buffer which has support for structure changes (limited, of course). Such a library can assist you in structure changes, but not in database schema changes - either way you will probably have to maintain mentioned one-cell table with schema version and upgrade it whenever a lower number is seen.

这篇关于在应用程序中的SQLite文件版本的兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆