我正在使用 @Query
删除我的 Room 数据库中的行,但我无法删除记录。这是我来自 @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
}
谁能给我一个建议,我做错了什么?
最佳答案
尝试以这种方式使用@Query
。
@Query("DELETE FROM notes WHERE uid = :arg0")
int delete(final int noteId);
在上面的代码行中,arg0 是传递给函数 delete() 的第一个参数。
关于android - 房间删除查询不会删除数据库中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47312900/