简体   繁体   English

Xamarin表单:更新应用程序时如何更新用户数据库

[英]Xamarin form: How to update user's database when updating the application

I am using Sqlite.Net to save data when working on the Xamarin form. 在Xamarin表单上工作时,我正在使用Sqlite.Net保存数据。 I am struggling how to update the tables if I added a new columns to an existing tables. 如果我在现有表中添加了新列,我将竭尽所能。 At the moment, we are required to have the application to reinstall so user will have an updated database unless there is no changes to the database. 目前,我们需要重新安装该应用程序,以便用户将拥有一个更新的数据库,除非对该数据库没有任何更改。

Probably you should maintain database versions. 可能您应该维护数据库版本。 You can use something like 您可以使用类似

    Int32 current_version = 0;
    //increment this when you publish the version containing database changes
    Int32 latest_version = 5; 
    cmd.CommandText = "pragma user_version";
    current_version = (Int32) cmd.ExecuteScalar();
    if(current_version < latest_version) {
       // use alter table statements to add the new columns
    }

... ...

// finally stamp your database as having the latest version
cmd.ExecuteNonQuery("pragma user_version=" + latest_version);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM