Search code examples
androidkotlinandroid-roomandroid-architecture-components

Room select expression


I need to create a not so simple Sql select query.

Something like this:

 @Query("$SELECT_FROM  $PRODUCT_TRANSACTION_TABLE WHERE write_status == ($SALE || $AUDIT)")
    fun loadProductSaleTransactions(): LiveData<List<TransactionProductTable>>

the field can be Sale or `Audit

But room return nothing. Can you help me to write correctly ?


Solution

  • I would suggest changing the query to:

     @Query("$SELECT_FROM  $PRODUCT_TRANSACTION_TABLE WHERE write_status IN ($SALE, $AUDIT)")
        fun loadProductSaleTransactions(): LiveData<List<TransactionProductTable>>
    

    Let me know if this fixes the issue. Cheers!