Dream
Dream

Reputation: 19

Returning List<Object> to variables;

I am doing a room database


    @Query("SELECT distinct UserID FROM USER WHERE CovidStat=='T'")
    public List<USER> checkCovid();

    @Query("SELECT DISTINCT PID,VisitDate FROM USER_PLACE,USER WHERE User.UserID=USER_PLACE.UID AND UID=(:UID)")
    int selectCovidPlace(int UID);

I wanted checkCovid() to return UserID where CovidStat='T' and I wanted to put the ID into selectCovidPlace to identify which place that ID been to. The problem is that checkCovid would return me a list instead of 1 variable since its not only 1 person who would have CovidStat='T', but im not sure that how can I put a list into selectCovidPlace().

Upvotes: 0

Views: 59

Answers (2)

msl12
msl12

Reputation: 68

I'm not familiar with SQLite. But the SQL syntax should be generic.

How about use IN statement?

like this ... WHERE User.UserID=USER_PLACE.UID AND UID IN (:UID)")

And then you can pass List as parameter.

Upvotes: 1

Gaurav Jeswani
Gaurav Jeswani

Reputation: 4592

Here you should use IN clause as below:

 @Query("SELECT DISTINCT PID,VisitDate FROM USER_PLACE,USER WHERE User.UserID=USER_PLACE.UID AND UID IN (:UIDs)")
    int selectCovidPlace(List<Integer> UIDs);

Upvotes: 1

Related Questions