Closed vishalkharat123 closed 10 years ago
Updates are only done using entities. If you do stuff outside of entities directly in the DB, you can either refresh entities or clear the session.
Thanks for the quick reply.
Whatever you are saying is okay in the case in which I know which entity to update. My scenario is like: I have Person table: I want to update record of person with id = 10. This i can do with "UPDATE PERSON SET NAME = 'VISHAL' WHERE ID = 10";
To achieve this with GreenDao i will have to first fetch record of person with id 10, and then update entity. This will require 2 queries to execute.
How can we achieve this?
Works as designed. It's object based, not property based.
"Updates are only done using entities. If you do stuff outside of entities directly in the DB, you can either refresh entities or clear the session."
Even if i refresh entities i.e getAllData from dao for that entity (using list and listLazyUncached()) i still get old data not the updated one. Am i missing something ?
This is not a support site, this an issue tracker. Please use stackoverflow. Thanks
Google search point to this page with no answer, so I will make a small one here for others
String updateQuery = "update "+PersonDao.TABLENAME
mDaoMaster.getDatabase().execSQL(updateQuery, new Object[] {"VISHAL", 10});
Donnot forget to refresh your entity: personDao.refresh(person10)
IMO, GreenDao is a good helper for most database tasks, but it is not a silver bullet, you should always master your database and all the query yourself,
How to update a Row in a table by it value not by Id
How to update a Row in a table by it value not by Id?
how to update by id
How to update a Row in a table by it value not by Id?
Read about how to update an entity in the new docs.
To get an entity, you can query for it or get it by its key using dao.load(key)
. Check the methods on your DAO class for additional ways to get a hold of an entity.
-ut
How to update a Row in a table by it value not by Id?
As we can execute an "Update " statement on database with where condition, but those changes are not reflected in corresponding Dao.