如何限制在Android中的SQLite表中的行数行数、Android、SQLite

2023-09-04 06:15:20 作者:?爷的人生就缺你?

我创建一个Android应用程序,有最近通话记录。 我想限制该表为最大50行的大小(根据其插入日期)

I create an Android app that has "recents history". I would like to limit the size of this table to a maximum of 50 rows (according to their insert date).

我看到谈论限制删除的行数的多个线程,但我不知道这功能在Android的SQLite的,即使启用。

I saw several threads that talk about limiting the number of deleted rows, but I'm not sure if this feature is even enabled in Android's SQLite.

谁能帮助吗?

感谢

推荐答案

我觉得SQL不能管理的行数在表,所以你必须自己去管理它。您可以执行数据插入后查询,将降低数据 - 这样的事情应该工作

I think sql can't manage the number of rows in your table so you'll have to manage it by yourself. You can execute query after data insertion that will reduce the data - something like this should work

DELETE FROM table where _id NOT IN (SELECT _id from table ORDER BY insertion_date DESC LIMIT 50)