Home > OS >  Returning List<Object> to variables;
Returning List<Object> to variables;

Time:09-29

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

CodePudding user response:

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);

CodePudding user response:

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.

  • Related