简体   繁体   English

会议室数据库更新问题

[英]Room Database update issue

Update multiple fields of an entity in android Room. 更新android Room中实体的多个字段。

I am using android room persistence library for my new project. 我正在为新项目使用android房间持久性库。 I want to update multiple fields of the table. 我想更新表的多个字段。 I have tried like in my Dao - 我曾尝试过像我的道

@Query(" UPDATE " + TABLE_ACC_NO_DEBIT_CARD_LINK + " SET id = :id , device_id = :device_id 
,transaction_key = :transaction_key , mobile = :mobile , email = :email 
,account_no = :account_no , debit_card = :debit_card , bank = :bank 
,is_uploaded = :is_uploaded WHERE device_id = :device_id AND account_no=:account_no")

int updateAccNoDebitCardLink( String device_idc, String account_noc
,String id,String device_id ,String transaction_key
,String mobile,String email,String account_no,String debit_card, String bank
,String is_uploaded);

for example 例如

@Query(UPDATE TABLENAME <place_holder>)
int updateObject(ObjetEntity objectEntity,String field);

What should I pass in place of , such that the new objectEntity is replaced by old one where the field value matches 我应该代替什么,以便新的objectEntity被字段值匹配的旧对象替换

Try this code.. 试试这个代码。

@Update
void updateData(MyTable myTable);

and put all data into myTable class object and pass it into updateData method.. 并将所有数据放入myTable类对象中,并将其传递给updateData方法。

    @Query("update Comment set fname=:fname where id=:id")
void update data(String fname,int id);

Try updating values of your table this way. 尝试以这种方式更新表的值。 Below is the example in kotlin language. 以下是Kotlin语言的示例。

   @Query("UPDATE Test SET test_name=:arg1,test_startDate=:arg2,test_endDate=:arg3,test_location=:arg4 WHERE testId = :arg0")
   fun updateTest( testId: Int,testName:String,testStartTime:String,testEndTime:String,testLocation:String)

Here testId, test_name,test_startDate,test_endDate,test_location are the fields of table named Test. 这里的testId,test_name,test_startDate,test_endDate,test_location是名为Test的表的字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM