Search code examples
androidsqlitesugarorm

SugarORM findWithQuery and WHERE IN


I'm working on an android app that uses sugarORM. I want to get a multiple items that match the ids in a list.

However when i call

findWithQuery(A.class, "SELECT * FROM <table> WHERE <column> in (?)", "1,2,3") 

I always get an empty list(although I double checked the query with SQLite DB Browser and it worked).

Splitting this query into multiple findById seems inefficient. Any thoughts on getting WHERE IN to work using SugarORM?


Solution

  • After more attempts I found that there is a problem with replacing the placeholders.

    Switching from:

    findWithQuery(A.class, "SELECT * FROM <table> WHERE <column> in (?)", "1,2,3")
    

    To:

    findWithQuery(A.class, "SELECT * FROM <table> WHERE <column> in (1,2,3)", null)
    

    fixes the issue.