如何限制在Android中的SQLite表中的行数 [英] How can I limit the number of rows in Android SQLite table

查看:930
本文介绍了如何限制在Android中的SQLite表中的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个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)

这篇关于如何限制在Android中的SQLite表中的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆