数据库调用or和android,android – createOrUpdate()始终使用ORMLite在数据库中创建一个新条目...

您不应该调用createOrUpdate,除非您的对象已经设置了一个id字段. ORMLite确定它是否存在于数据库中的方式是在其上执行查询.代码:

ID id = extractId(data);

// assume we need to create it if there is no id <<<<<<<<<<<<<<<<<<<<<<<

if (id == null || !idExists(id)) {

int numRows = create(data);

return new CreateOrUpdateStatus(true,false,numRows);

} else {

int numRows = update(data);

return new CreateOrUpdateStatus(false,true,numRows);

}

我将扩大javadocs来解释这个更好.他们在那里很弱.抱歉.我已经将它们更新为:

This is a convenience method for creating an item in the database if it does not exist. The id is extracted from the data argument and a query-by-id is made on the database. If a row in the database with the same id exists then all of the columns in the database will be updated from the fields in the data parameter. If the id is null (or 0 or some other default value) or doesn’t exist in the database then the object will be created in the database. This also means that your data item must have an id field defined.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值