Gulab Sagevadiya
Gulab Sagevadiya

Reputation: 991

Android Room Database How to Filter By String Value in Room

@Dao
public interface DaoAccess {

    @Insert
    void insertImage(ImagesOfEmployee image);

    @Query("Select * from ImagesOfEmployee where id like '%' || :id ||'%'")
    String getProfileImagePathByID(String id);

    @Query(("Delete from ImagesOfEmployee where id like '%' || :id || '%'"))
    void deleteEmployee(String id);
}

@Entity
public class ImagesOfEmployee {
    @NonNull
    @PrimaryKey
    String id;
    @ColumnInfo
    String path;

    public ImagesOfEmployee(String id, String path) {
        this.id = id;
        this.path = path;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }
}

I don't know how to filter In Room Database Android String Query Can Any One Know How to do this

I AM attaching the error below. what android studio shows me in the error box Screen Shot This is ScreenShot

Upvotes: 2

Views: 1495

Answers (1)

Rajnikant B
Rajnikant B

Reputation: 126

Android studio error says 'not sure how to convert cursor to the method's return type' as the query with 'Select *' will return the whole record, and I think you are trying to get only path of the image, Just replace * with path as in,

Select path from ImagesOfEmployee where id like '%' || :id ||'%'

hope you are looking for this only.

Upvotes: 3

Related Questions