获取Android SQLite数据库中非空记录的总数
我想从我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在桌子上之前数一下应该可以。只需使用 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...
所以你只想找到行数? (据我所知,不存在“空记录”这样的东西。)
你能不只做
or 吗
? (有些数据库使用一种或另一种形式更快......我不知道 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
or
? (Some databases are faster using one form or other... I don't know about sqlite.)