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(); 

這一定會給你你需要的答案。