1. Are you ready for the Galaxy S20? Here is everything we know so far!

Android Room: Passing method variables to @Query annotation statement

Discussion in 'Android Development' started by Guitarist, Feb 13, 2020.

  1. Guitarist

    Guitarist Newbie
    Thread Starter

    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!

     


    Rob likes this.

    1. Download the Forums for Android™ app!


      Download

       
  2. Guitarist

    Guitarist Newbie
    Thread Starter

    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
     
    #2 Guitarist, Mar 10, 2020
    Last edited: Mar 10, 2020
Loading...
Similar Threads - Android Room Passing
  1. raywood
    Replies:
    0
    Views:
    35
  2. androinewbi
    Replies:
    4
    Views:
    167
  3. Angie82
    Replies:
    2
    Views:
    180
  4. shakushinnen
    Replies:
    5
    Views:
    178
  5. Dave_M
    Replies:
    3
    Views:
    185
  6. Dave_M
    Replies:
    4
    Views:
    227
  7. Dave_M
    Replies:
    4
    Views:
    227
  8. Annabelle iris
    Replies:
    1
    Views:
    247
  9. Guitarist
    Replies:
    0
    Views:
    708
  10. Guitarist
    Replies:
    0
    Views:
    1,154

Share This Page

Loading...