Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Room delete query does not remove the row in database

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?

like image 610
Martin Avatar asked Nov 15 '17 16:11

Martin


1 Answers

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().

like image 139
hetsgandhi Avatar answered Oct 20 '22 00:10

hetsgandhi