I'm using @Query
to delete row in my Room database, but I'm not able to delete the record. Here is my query from @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 class
@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
}
Can someone give me an advice, what I'm doing wrong?
Try using @Query
this way.
@Query("DELETE FROM notes WHERE uid = :arg0")
int delete(final int noteId);
In the above code of lines, arg0 is the first argument passed to the function delete().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With