【发布时间】:2021-06-20 05:57:18
【问题描述】:
我想查询我的数据库,从一列中获取所有数据。
此信息是一个字符串,例如“19,96 €”(如果需要,我当然可以删除 €)
我需要一个函数来将此列的数据转换为双精度并返回总和以供我在另一个视图中显示。 我想我已经有查询了,但我不确定。
我现在该怎么做?如何将列变成双精度并从中获取总和?
这是项目类:
@Entity(tableName = "receipt_table")
@Parcelize
data class Receipts(
@ColumnInfo(name = "total") var total: String,
@ColumnInfo(name = "date") var date: String,
@ColumnInfo(name = "store") var store: String,
@PrimaryKey(autoGenerate = true) val id: Int= 0) : Parcelable
还有道:
@Dao
interface ReceiptDao {
@Query("SELECT * FROM receipt_table")
fun getAllReceipts(): Flow<List<Receipts>>
@Query("SELECT total FROM receipt_table")
fun getAllReceiptsTotal(): Flow<List<Int>>
///@Query("SELECT date FROM receipt_table")
///fun getDate(): Flow<List<Receipts>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(receipts: Receipts)
@Update
suspend fun update(receipts: Receipts)
@Delete
suspend fun delete(receipts: Receipts)
}
【问题讨论】:
标签: android kotlin android-room