-1

This doesn't work, and I'm not sure if I wore it wrong or if it's a limitation of Android's Room

@Query("SELECT * FROM foobar WHERE :column IN (:values)")
fun getByFieldName(column: String, vararg values: String): Flowable<List<FooBar>>
user3063925
  • 255
  • 3
  • 12
  • 2
    Room simply augments SQLite's placeholder system, and in SQLite, AFAIK, you cannot make a column name be a placeholder. – CommonsWare Oct 16 '17 at 19:14
  • Room do **compile time** checking. I don't think you can do it. – Joshua Oct 17 '17 at 06:30
  • Possible duplicate of [How to dynamically query the room database at runtime?](https://stackoverflow.com/questions/44287465/how-to-dynamically-query-the-room-database-at-runtime) – Bertram Gilfoyle Aug 18 '18 at 17:56

1 Answers1

1

@user3063925, Your question is in limitation of Room Library,

But don't worry,

We can write fully dynamic query on Room Database by using the @query()

String mQuery = "SELECT * FROM foobar WHERE columnName1 IN ('value_1','value_2') and columnName2 In('value_3','value_4')";

AppDatabase appDatabase = Room.databaseBuilder(getApplicationContext(),
        AppDatabase.class, "database-name").build();

Cursor mCursor = AppDatabase.getAppDatabase(context).getOpenHelper().getReadableDatabase().query(myQuery);

Now you can convert cursor row wise data to your POJO class.

TejaDroid
  • 6,561
  • 4
  • 31
  • 38