获取Android SQLite数据库中非空记录的总数

发布于 2024-10-06 18:22:54 字数 140 浏览 0 评论 0原文

我想从我的 SQLite 数据库中获取 NOT NULL 记录的数量。由于我使用自动增量,最后插入的行不会给我表中的实际记录数,因为即使我删除任何中间记录,它也会插入到比最后插入的记录更高的位置。

插入语句返回最后插入行的编号,但我希望动态获得该值。

I want to get the number of NOT NULL records from my SQLite database. Since I'm using autoincrement, the last inserted row won't give me the real number of records in the table as even if I delete any middle record, it'll insert at the position higher than the last inserted record.

The insert statement returns me the number of last inserted row, but I want this value on the fly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌无敌 2024-10-13 18:22:54

在桌子上之前数一下应该可以。只需使用 NOT NULL 检查来查询 id 列,并在返回的游标上调用 getCount()

只是为了确定:您永远不应该,真的永远不要,操纵自动增量一个高效的数据库。如果您删除一条记录,那么“间隙”应该保留在那里。它对性能或其他任何东西都没有影响。如果在间隙中插入新记录,可能会造成很多麻烦......

Doing a count before on the table should work. Simply query for the id column with the where check of NOT NULL and on the returned cursor just call the getCount()

Just to be sure: You should never ever, really never ever, manipulate the auto increment in a productive database. If you delete a record, than the "gap" should stay there. It has no impact on performance or anything else. If you insert a new record in the gap, you can create a lot of trouble...

说不完的你爱 2024-10-13 18:22:54

所以你只想找到行数? (据我所知,不存在“空记录”这样的东西。)

你能不只做

select count(1) from YourTableName

or 吗

select count(*) from YourTableName

? (有些数据库使用一种或另一种形式更快......我不知道 sqlite。)

So you just want to find the number of rows? (There no such thing as a "null record" as far as I'm aware.)

Can you not just do

select count(1) from YourTableName

or

select count(*) from YourTableName

? (Some databases are faster using one form or other... I don't know about sqlite.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文