Count number of strings returned from Azure query

守給你的承諾、 提交于 2019-12-12 04:26:13

问题


I am trying to count the number of rows from my azure database table in my android java code. Unfortunately there is no count() method built into the azure library. The closest thing to it is the includeInlineCount() method. I used the following line of code:

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

Which returns the value of the first column for each row. The value of result looks something like this:

[column1_row1_String, column1_row2_String, column1_row3_String] 

How can I extract the number of strings from the value result?


回答1:


According to the source code of Class MobileServiceList, you can try the code below using the method getTotalCount().

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



回答2:


TRY THIS..it will select all the elements of your table and then count it to return integer value.

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

this will definitely give you your required answer.




回答3:


There is no built in count() method which can directly count the number, you can try using includeTotalCount() instead, first query out all result and do the count. Below is an example in C#, hope it could help you make it out in Java:

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

Check this thread for details:How to get the row count from an azure database?



来源:https://stackoverflow.com/questions/35872031/count-number-of-strings-returned-from-azure-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!