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
- Insert your new records
- Select all entries ordered by date and check if the result has more than 25 entries
- If it has, get the date of the 25th. entryLast
- 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.
精彩评论