Room select expression

Viewed 65

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 ?

3 Answers

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!

just change after WHERE clause like below

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