• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Android Room: Passing method variables to @Query annotation statement

Guitarist

Newbie
I'm trying to figure out how to pass multiple method variables to an Android Room DAO @Query statement. Below is my attempt. I'm trying to create a 'generic' @Query method to avoid duplicating it for each and every table query. As you can see from the image, I'm able to pass all my variables except the 'table' variable which identifies the table name to be searched.

I wasn't sure if anyone here works with Room enough to know or have tried this?

Thanks!

[GALLERY=media, 149]RoomQueryStatement by Guitarist posted Feb 13, 2020 at 11:13 AM[/GALLERY]
 
  • Like
Reactions: Rob
I did find resolution to this issue, but not as expected. The following code was provided by Android Room development as the proper syntax and solution. They stated that the examples provided shouldn't be taken literally, which doesn't make any sense from a documentation standpoint. The purpose of documentation is to "document" how to do or use something, why would you make it up? Especially when the purpose of the Room Persistence Library is to reduce complexity, even in querying data.

@Query("SELECT CommentID FROM Comments WHERE Comment LIKE '%' || :value || '%'")
List<Integer> customSearchCommentsTable(String value);

Anyhow, sorry for the rant. Just know the example provided in the documentation does not work as implied.

For further reference if needed, see the following I posted:
Issue Tracker:
https://issuetracker.google.com/issues/149519050

StackOverflow:
https://stackoverflow.com/questions...turning-data-known-to-exist/60622070#60622070
 
Last edited:
Back
Top Bottom