1

Dao :

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertProducts(dataUser: List<Products>)

i am inserting list of products in the table at a single time ...i know whether the all data inserted successfully or not

i tried all the ways like return type of Long ( but it is working only for inserting single item )

Also please tell me the viewmodel code ..that how could i receive the success value or failure value..so that i can process the next step easily

2 Answers 2

1

I think you were close. You are inserting multiple items. So it's not going to be Long but List<Long>(or Array not sure right now if Room can convert it automatically) (doc).

0
1

i tried all the ways like return type of Long ( but it is working only for inserting single item ) so

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertProducts(dataUser: List<Products>): LongArray

If inserting from a List then the returned value is an LongArray, an element per insert. Each will either be a value greater than 0 (inserted) or -1 not inserted.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.