开发者

Deleting old records in sqlite database android

Table must always store not more then 25 records.开发者_Go百科 It means when I insert new array of records, I must control total number of records and if it's more then 25, it's necessary to remove some old. (table has integer primary key & text field datetime of inserting). How can I manage it?


I think, you just need the algorithm

  1. Insert your new records
  2. Select all entries ordered by date and check if the result has more than 25 entries
  3. If it has, get the date of the 25th. entryLast
  4. Delete all entries that are older entryLast


for this you can use id to monitor if it crosses 25 then you should delete the rows as per increasedNo - 25. You can add this id to delete the rows from you db.


I disagree with Vineet, just monitoring the id won't work if you don't specifically ask the db to renumber it's entries. It will just grow. I would use a limited db as what is done here and would check its size before deleting the oldest entry.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜