D
D
dikutenz2019-06-11 18:43:15
Android
dikutenz, 2019-06-11 18:43:15

How to make a general Query through Room?

I have a class Garment with such fields.
@Entity(tableName = GarmentTable.NAME)
public class Garment {
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = GarmentTable.Cols.ID)
private long mId;
@ColumnInfo(name = GarmentTable.Cols.TITLE)
private String mTitle;
@ColumnInfo(name = GarmentTable.Cols.ARCHIVE)
private boolean mArchive;
@ColumnInfo(name = GarmentTable.Cols.SUMMER)
private boolean mSummer;
@ColumnInfo(name = GarmentTable.Cols.AUTUMN)
private boolean mAutumn;
@ColumnInfo(name = GarmentTable.Cols.WINTER)
private boolean mWinter;
@ColumnInfo(name = GarmentTable.Cols.SPRING)
private boolean mSpring;
Depending on the button pressed, I should have a certain list of Garment displayed, as if by a filter. (for example, only summer, only winter, only archive, etc.). I'm trying to do it in Dao like this
@Query("SELECT * FROM " + GarmentTable.NAME + " WHERE :clause")
List getByClauseList(String clause);
And in the code write
garments = mGarmentDao.getByClauseList(GarmentTable.Cols.SUMMER + " = 1 ")
As a result, I get an empty list.
If I make requests individually, then everything is displayed correctly, for example
@Query("SELECT * FROM " + GarmentTable.NAME + " WHERE " + GarmentTable.Cols.SUMMER + " = :
List getSummer(int isSummer);
@Query("SELECT * FROM " + GarmentTable.NAME + " WHERE " + GarmentTable.Cols.AUTUMN + " = :isAutumn")
List getAutumn(int isAutumn);
Of course, I can paint each request for each parameter, but it will turn out to be too much code. Is it possible to somehow create a general request?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question