Sugar ORM - save()和update()之间的区别

时间:2017-01-31 10:14:30

标签: android-sqlite sugarorm

糖ORM中save()和update()有什么区别?

参考此Sugar ORM in Android: update a saved object in SQLite

保存和更新会得到相同的结果吗?

我想更新现有记录,如果存在怎么做?

这里我想做点什么:

 long count = Lead.count(Lead.class);
                            if (count > 0) {
                                List<Lead> leads = Lead.find(Lead.class, "lead_id = ?", leadItem.leadId);

                                if (leads == null) { // save leadItem
                                    Lead.save(lead);
                                    logFile.writeLog("Home Activity: Lead saved in local DB. Lead Id is: " + leadItem.leadId + " leadItem Name: " + leadItem.name);
                                    Log.d("Lead saved: ", leadItem.toString());
                                } else { // update leadItem
                                    Lead.update(lead);
                                    logFile.writeLog("Home Activity: Lead updated in local DB. Lead Id is: " + leadItem.leadId + " leadItem Name: " + leadItem.name);
                                    Log.d("Lead updated: ", leadItem.toString());
                                }
                            }

这里当我调用update时,它还会更新另一条记录,我用不同的ID保存并添加为新记录而不是更新。

0 个答案:

没有答案