I am trying to create the following Query using SupportSQLiteQueryBuilder
:
SELECT * FROM tablename WHERE favorite=1 ORDER BY col1
I used the following code to build this query:
public static SupportSQLiteQuery getSortedQuery(String sortByColname, boolean fav){
SupportSQLiteQueryBuilder builder=
SupportSQLiteQueryBuilder
.builder(DbUtils.Names.TABLE_NAME)
.columns(new String[]{Names.COL1,Names.COL2,Names.COL3,Names.COL4,Names.COL5,Names.COL_FAVORITE})
.orderBy(sortByColname) ;
if(fav){
builder.selection(Names.COL_FAVORITE,new String[]{"1"} );
}
SupportSQLiteQuery query= builder.create();
//Log.e("DB_UTILS", "getSortedQuery:query="+query.getSql());
return query;
}
But on checking the unit test , i found that following is the sql query that this method is generating :
SELECT col1,col2,col3,col4,col5 favorite FROM tablename WHERE favorite ORDER BY col1
Why The arguement is not getting passed into this statement? why only
favourite
got generated andfavourite=1
?Is There a way to generate
*
in the query? writing all the colnames instead of*
is painful