0

我想从我的android java代码中从我的azure数据库表中计数行数。不幸的是,azure库中没有内置count()方法。最接近它的是includeInlineCount()方法。我使用了以下代码行:计数从Azure查询返回的字符串的数量

final MobileServiceList<Crime> result = mToDoTable.includeInlineCount().execute().get(); 

它返回每行第一列的值。的result值看起来是这样的:

[column1_row1_String, column1_row2_String, column1_row3_String] 

我怎样才能提取值的结果字符串的数量?

回答

-1

有没有内置的count()方法可以直接计数的数量,你可以尝试使用includeTotalCount()来代替,首先查询所有结果并进行计数。下面是在C#中的例子,希望它可以帮助你做它在Java中:

var table = MobileService.GetTable<T>(); 
var query = table.Take(0).IncludeTotalCount(); 
IList<T> results = await query.ToListAsync(); 
long count = ((ITotalCountProvider)results).TotalCount; 

检查此线程的详细信息:How to get the row count from an azure database?

2

根据MobileServiceList类的源代码,你可以尝试代码以下使用method getTotalCount()

final MobileServiceList<Crime> result = mToDoTable.includeInlineCount().execute().get(); 
int count = result.getTotalCount(); 
0

TRY THIS ..它将选择您的表中的所有元素,然后将其计数为返回整数值。

int count = mToDoTable.execute().get().getTotalCount(); 

这一定会给你你需要的答案。