OrmLite - 保存表升级之前的数据 [英] OrmLite - save data before table upgrade

查看:344
本文介绍了OrmLite - 保存表升级之前的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以从表中数据保存我的模型更改数据库之前?

例如我重命名列,也不会丢失数据。所以,即我要来从C1列的所有数据,我列重命名为C2和所有的数据写回。


解决方案

  

我要来从C1列的所有数据,我列重命名为C2和所有的数据写回。


SQLite不支持的列改名所以这不会Android的下工作。你当然可以但是添加一个附加列。有下的Andr​​oid / ORMLite架构更改一些好的文档。看到这个页面:


  

http://ormlite.com/docs/upgrade-schema


例如,你可以做以下架构更新:

  dao.executeRaw(
    ALTER TABLE`account` ADD COLUMN hasDog布尔值默认值0;);
dao.updateRaw(更新`account` SET hasDog = 1 WHERE dogCount大于0;);

It is possible to save the data from a table before my model changes the database?

For example i rename a column and will not lose the data. So i.e. i want to fetch all data from column c1, rename my column to c2 and write all data back.

解决方案

i want to fetch all data from column c1, rename my column to c2 and write all data back.

Sqlite does not support the renaming of columns so this will not work under Android. You can certainly add an additional column however. There is some good documentation on schema changes under Android/ORMLite. See this page:

http://ormlite.com/docs/upgrade-schema

For example, you can do the following schema updates:

dao.executeRaw(
    "ALTER TABLE `account` ADD COLUMN hasDog BOOLEAN DEFAULT 0;");
dao.updateRaw("UPDATE `account` SET hasDog = 1 WHERE dogCount > 0;");

这篇关于OrmLite - 保存表升级之前的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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