Android 如何使用 ORMLite 查询生成器获取表中的总记录数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12260781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 10:14:33  来源:igfitidea点击:

How to use the ORMLite query builder to get the total records in a table

androidormlitequery-builder

提问by Sourabh Saldi

Similar to

相似

select count(*) from tablename;

what should be query in ORMLITE

在 ORMLITE 中应该查询什么

i tried something like

我试过类似的东西

int total = dao.queryBuilder().("select count(*)");

回答by Gray

How to use the ORMLite query builder to get the total records in a table

如何使用 ORMLite 查询生成器获取表中的总记录数

ORMLitehas a Dao.countOf()method that returns the total number of rows in a table:

ORMLite有一个Dao.countOf()方法可以返回表中的总行数:

long numRows = dao.countOf();

You can also count the number of rows in a custom queryby calling the countOf()method on the Whereor QueryBuilderobject.

您还可以通过调用or对象上的方法来计算自定义查询中的行数countOf()WhereQueryBuilder

// count the number of lines in this custom query
long numRows = dao.queryBuilder().where().eq("name", "Joe Smith").countOf();

回答by PoeHaH

for package 5: you can use countOf()

对于包 5:您可以使用 countOf()

From the docs:

从文档:

Returns the value returned from a SELECT COUNT(*) query which is the number of rows in the table. Depending on the database and the size of the table, this could be expensive.

返回从 SELECT COUNT(*) 查询返回的值,即表中的行数。根据数据库和表的大小,这可能很昂贵。