开发者

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

开发者 https://www.devze.com 2023-03-19 21:02 出处:网络
I have a database which i am inserting to.Right now I have this code. database.insertWithOnConflict(FOO_TABLE, null, values,

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

精彩评论

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

关注公众号