@Override public Cursor query(Uri uri,String[] projection,String selection,String[] selectionArgs,String sortOrder){
  if (uri == null) {
    LogUtils.log(this,Log.WARN,NULL_URI_FORMAT_STRING);
    return null;
  }
  final SQLiteQueryBuilder queryBuilder=new SQLiteQueryBuilder();
  queryBuilder.setTables(LabelsTable.TABLE_NAME);
  String groupBy=null;
switch (sUriMatcher.match(uri)) {
case LABELS:
    if (TextUtils.isEmpty(sortOrder)) {
      sortOrder=LabelsTable.KEY_ID;
    }
  break;
case LABELS_ID:
final String labelIdString=uri.getLastPathSegment();
final int labelId;
try {
labelId=Integer.parseInt(labelIdString);
}
 catch (NumberFormatException e) {
LogUtils.log(this,Log.WARN,UNKNOWN_URI_FORMAT_STRING,uri);
return null;
}
final String where=String.format("%s = %d",LabelsTable.KEY_ID,labelId);
queryBuilder.appendWhere(where);
break;
case PACKAGE_SUMMARY:
projection=new String[]{LabelsTable.KEY_PACKAGE_NAME,"COUNT(*)"};
groupBy=LabelsTable.KEY_PACKAGE_NAME;
sortOrder=LabelsTable.KEY_PACKAGE_NAME;
break;
default :
LogUtils.log(this,Log.WARN,UNKNOWN_URI_FORMAT_STRING,uri);
return null;
}
initializeDatabaseIfNull();
return queryBuilder.query(mDatabase,projection,selection,selectionArgs,groupBy,null,sortOrder);
}

@ Override public Cursor query ( Uri uri , String [ ] projection , String selection , String [ ] selectionArgs , String sortOrder ) { if ( uri == null ) { LogUtils . log ( this , Log . WARN , NULL_URI_FORMAT_STRING ) ; return null ; } final SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder ( ) ; queryBuilder . setTables ( LabelsTable . TABLE_NAME ) ; String groupBy = null ; switch ( sUriMatcher . match ( uri ) ) { case LABELS : if ( TextUtils . isEmpty ( sortOrder ) ) { sortOrder = LabelsTable . KEY_ID ; } break ; case LABELS_ID : final String labelIdString = uri . getLastPathSegment ( ) ; final int labelId ; try { labelId = Integer . parseInt ( labelIdString ) ; } catch ( NumberFormatException e ) { LogUtils . log ( this , Log . WARN , UNKNOWN_URI_FORMAT_STRING , uri ) ; return null ; } final String where = String . format ( "%s = %d" , LabelsTable . KEY_ID , labelId ) ; queryBuilder . appendWhere ( where ) ; break ; case PACKAGE_SUMMARY : projection = new String [ ] { LabelsTable . KEY_PACKAGE_NAME , "COUNT(*)" } ; groupBy = LabelsTable . KEY_PACKAGE_NAME ; sortOrder = LabelsTable . KEY_PACKAGE_NAME ; break ; default : LogUtils . log ( this , Log . WARN , UNKNOWN_URI_FORMAT_STRING , uri ) ; return null ; } initializeDatabaseIfNull ( ) ; return queryBuilder . query ( mDatabase , projection , selection , selectionArgs , groupBy , null , sortOrder ) ; }
queries for a label or multiple labels in the labels database .
