Skip to content

Support for MySQL IN-Statement #44

Open

Description

@MaaxGr

Explaination

In MySQL the IN operator allows you to determine if a value matches any value in a list of values.
Unfortunately there is currently no support vor passing a list as a query parameter

This works

fun testSelect(): List<String> {
    val sql = """
        SELECT column_1, column_2 FROM TEST_TABLE WHERE column_1 IN ('a', 'b')
    """.trimIndent()

    val query = queryOf(sql).map { row -> row.string("column_2") }.asList

    return scanappDb.useConnection { dbSession ->
        dbSession.run(query)
    }
}

This doesn't work

fun testSelect2(): List<String> {
    val sql = """
        SELECT column_1, column_2 FROM TEST_TABLE WHERE column_1 IN :values
    """.trimIndent()

    val query = queryOf(sql, mapOf("values" to arrayOf("a", "b")))
        .map { row -> row.string("column_2") }.asList

    return scanappDb.useConnection { dbSession ->
        dbSession.run(query)
    }
}

I tried:

  • Passing a list or array
  • Using Brackets "(" around :values
  • None of the combinations work

Where it works

For example room has an implementation for this:
https://stackoverflow.com/questions/48406228/room-select-query-with-in-condition

Final words

It would be really nice if you could look into this issue :)

Activity

  1. seratch commented on Sep 1, 2021

    @seratch
    Owner

    Hey @MaaxGr, thanks for writing in! Unfortunately, I myself do not have enough time to work on this project (in my spare time). If you are interested in making pull requests for it, I'm happy to be a reviewer and, if the change looks great, I'm happy to have the change in the next release.

  2. seratch commented on Sep 1, 2021

    @seratch
    Owner

    #17 may be related

  3. MaaxGr commented on Sep 1, 2021

    @MaaxGr
    Author

    Hi seratch,
    thx for your answer! Unfortunately i don't have that much spare time to dive deep into unfamiliar code bases at the moment as well. 😅
    I will look into it and see what i can do. But if someone else is interested in contributing, feel free.

    Regards Max

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions