问题
I am trying to count the number of rows in an Azure database table and display that number on my android app. I have read Azure's documentation on retrieving data from tables here:
https://azure.microsoft.com/en-us/documentation/articles/mobile-services-android-how-to-use-client-library/#querying
But it doesn't mention a built-in COUNT function. Does the Azure library have a COUNT function?
回答1:
As @AlexChen-Wx said, you can use the method includeTotalCount of Object MobileServiceTable on the JavaScript backend of Azure Mobile Service to count the number of records.
If you want to directly count on the Android App, you can try to use the method includeInlineCount of Class MobileServiceTable in Java, please see the source code at https://github.com/Azure/azure-mobile-services/blob/master/sdk/android/src/sdk/src/main/java/com/microsoft/windowsazure/mobileservices/table/MobileServiceTable.java#L349.
回答2:
Yes, There is a method called includeTotalCount which will return the count of all records. For details, pls reference article MobileServiceTable Object
回答3:
boolean loop = true;
int totalrows = 0;
int skipnumber = 0;
int rows=0;
while(loop) {
int count = mToDoTable.select().skip(skipnumber).execute().get().size();
skipnumber = skipnumber+50;
rows = rows+count;
if(rows<skipnumber){
loop=false;
totalrows = rows;
Log.i("count",String.valueOf(totalrows));
}
}
来源:https://stackoverflow.com/questions/35707659/java-count-rows-in-azure-database-table