Data Insert and Update

53 views
Skip to first unread message

Raja Jawahar

unread,
Jan 26, 2016, 9:39:20 AM1/26/16
to greenDAO
Hi,
     I have a table in which I am inserting the rows there. I just want to update the existing data without getting all the list in the TABLE through where condtion.

Instead of doing below..

I have one transid which I am getting from the server. I want to check whether it exists in table, if so need to update the row or insert as a new row. 

ParentProfileDao parentProfileDao = daoSession.getParentProfileDao();
List<ParentProfile> list = parentProfileDao.queryBuilder()
.where(ParentProfileDao.Properties.TransID.eq(accountsClass.getTransID()))
.list();
if (joes == null || joes.size() == 0) {
parentProfileDao.insertOrReplace(accountsClass);
} else {
for (ParentProfile parentitem : joes) {
if (parentitem.getTransID().equals(accountsClass.getTransID())) {
accountsClass.setId(parentitem.getId());
}
parentProfileDao.update(accountsClass);
}
}
Reply all
Reply to author
Forward
0 new messages