更新在安卓ormlite数据库表中的所有列 [英] Update all columns in ormlite database table in android

查看:643
本文介绍了更新在安卓ormlite数据库表中的所有列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的数据库表的对象:

I have the following database table object:

public class Goal {
    @DatabaseField(generatedId = true)
    private int id;
    @DatabaseField
    private String goal_title;
    @DatabaseField
    private String goal_desc;
    @DatabaseField
    private String goal_why;
    ...
}

我增加了一些行到该表中,现在我想编写一个查询来更新行的所有列在此表中。我见过的ORM文件并不能得到一个想法如何写这个查询。请帮我怎么写这个查询。非常感谢。

I have added some rows to this table an now I want to write a query to update all the columns of a row in this table. I have seen documentation of ORM and could not get an idea how to write this query. Please help me how to write this query. Many thanks.

推荐答案

我想你需要RTFM。我花了很长时间在 ORMLite 的文件,我认为它涵盖了 UpdateBuilder pretty的好。随意问更具体的问题,如果没有,我可以添加更多的细节。

I think you need to RTFM. I've spent a long time on the ORMLite documentation and I think it covers the UpdateBuilder pretty well. Feel free to ask more specific questions and I can add more details if not.

http://ormlite.com/docs/update-builder

要在文档中引用:

在DAO也可用于构建自定义UPDATE和DELETE语句。 UPDATE语句用于更改行的某些字段从匹配WHERE模式的表 - 或更新的所有行,如果没有在那里()。 DELETE语句用来从表中删除匹配WHERE模式的行 - 或删除所有行,如果没有在那里()

The DAO can also be used to construct custom UPDATE and DELETE statements. Update statements are used to change certain fields in rows from the table that match the WHERE pattern - or update all rows if no where(). Delete statements are used to delete rows from the table that match the WHERE pattern - or delete all rows if no where().

要调整的例子code使用你的目标目标:

To tweak the example code to use your Goal object:

UpdateBuilder<Goal, Integer> updateBuilder = goalDao.updateBuilder();
// update the goal_title and goal_why fields
updateBuilder.updateColumnValue("goal_title", "some other title");
updateBuilder.updateColumnValue("goal_why", "some other why");
// but only update the rows where the description is some value
updateBuilder.where().eq("goal_desc", "unknown description");
// actually perform the update
updateBuilder.update();

希望这有助于。

Hope this helps.

这篇关于更新在安卓ormlite数据库表中的所有列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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