I would like to show date wise item list in my app. The list will have a header with date and sum of a value of a column.
24.12.2021 | 25 |
---|---|
Book1 | 10 |
Book2 | 05 |
Book3 | 10 |
This is the entity:
@Entity(tableName = "books")
public class Books {
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
private int id;
@ColumnInfo(name = "date")
@TypeConverters({TimestampConverter.class})
private long mDate;
@ColumnInfo(name = "quantity")
private double mQuantity;
@ColumnInfo(name = "name")
private String mName;
I am trying to use nested recyclerview and have created a Parent class :
public class ParentEntry {
private double totalBooks;
private long dateToday;
public List<Books> books;
}
This is the dao:
@Query("SELECT SUM(quantity) as totalBooks, date as dateToday, * FROM books GROUP BY date ORDER
BY date Asc ")
LiveData<List<ParentEntry>> getAllParentEntries();
But I am getting the following errors: error: Cannot figure out how to read this field from a cursor. warning: The query returns some columns [id, date, quantity, name] which are not used. You can use @ColumnInfo annotation on the fields to specify the mapping. You can annotate the method with @RewriteQueriesToDropUnusedColumns to direct Room to rewrite your query to avoid fetching unused columns. ParentEntry has some fields [books] which are not returned by the query. If they are not supposed to be read from the result, you can mark them with @Ignore annotation. You can suppress this warning by annotating the method with @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH). Columns returned by the query:totalBooks, dateToday, id, date, quantity, name. Fields in ParentEntry: totalBooks, dateToday, books. LiveData<List> getAllParentEntries();
How can I query both the list and sum of quantity column and date in a single query ? Any help is highly appreciated.