开发者

How to check if a row has been updated and not inserted in android sqlite3

I have a database which i am inserting to. Right now I have this code.

 database.insertWithOnConflict(FOO_TABLE, null, values,
            SQLiteDatabase.CONFLICT_REPLACE);

This inserts into my database. Is there an efficient way to 开发者_StackOverflow中文版see if a row has been updated and not inserted with the constraint CONFILCT_REPLACE? Thanks!


You can compare returned _id with previously retrieved max(_id) - if _id > max(id) record was inserted, otherwise replaced. Other way is a bit dumb - try to insert, in case of sql exception make update.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜