问题
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