A number delete request does not delete a row in the database

I use @Query to delete a row in the My Room database, but I cannot delete the entry. Here is my request 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 advice on what I'm doing wrong?

+5
source share
4 answers

You can use the @Delete annotation, and all parameters of the Delete method must be either classes annotated by Entity, or collections / arrays from them.

In your case, I believe that you should use @Delete int delete (note) or

@Delete int delete (Note ... note)

+1
source

Use the delete request as follows:

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

where "quote_no" is the unique value in the database from which you want to delete the row, and "Orders" is the name of the table.

0
source

Try using @Query this way.

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

In the string code above, arg0 is the first argument passed to delete ().

0
source

enter a description of the link here Here I explained an example of how you can remove rooms from the database there are also various ways, but if you want to delete a specific item, then you can do it as in this project.

-3
source

Source: https://habr.com/ru/post/1273404/


All Articles