房间删除 查询不会删除数据库中的行

问题描述 投票:5回答:3

我使用@Query在我的房间数据库中删除行,但我无法删除的记录。下面是我的@Dao查询

@Dao
public interface NoteDao {

    @Insert
    void insert(final Note note);

    @Update
    void update(final Note note);

    @Query("DELETE FROM notes WHERE uid = :noteId")
    int delete(final int noteId);

    @Query("SELECT * FROM notes")
    LiveData<List<Note>> selectAll();
}

实体类

@Entity(tableName = "notes")
public class Note {
    @PrimaryKey(autoGenerate = true)
    @ColumnInfo(name = "id")
    @Expose(serialize = false, deserialize = false)
    private int mId;
    @ColumnInfo(name = "uid")
    @SerializedName("id")
    private int mUid;
    @ColumnInfo(name = "text")
    @SerializedName("text")
    private String mText;

    public Note() {
    }

    getters and setters ommited

}

有人可以给我一个建议,我在做什么错?

android android-room android-architecture-components
3个回答
1
投票

您可以使用@Delete注释和所有的删除方法的参数必须是与实体或集合/它的阵列注释类。

在你的情况,我相信,你应该使用@Delete诠释删除(注记)或

@Delete诠释删除(注......注)


1
投票

使用删除查询是这样的:

@Query("Delete FROM Orders where quote_no LIKE  :quote_no")
void deleteOrderById(String quote_no);

其中“quote_no”是在数据库与您要删除的行和“订单”的独特价值是表名。


1
投票

尝试使用@Query这种方式。

 @Query("DELETE FROM notes WHERE uid = :arg0")
 int delete(final int noteId);

在线路中的上面的代码,为arg0是()传递给函数删除第一个参数。

© www.soinside.com 2019 - 2024. All rights reserved.