javadatabasesqliteandroid-studio-2.2

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


Solution

  • 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.