Update all columns in ormlite database table in Android

android, orm

Solution

I have added some rows to this table and now I want to write a query to update all the columns of a row in this table.

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.

To quote from the docs:

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().

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.

Problem

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; ... } ``` I have added some rows to this table and 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.

Original source