Git Product home page Git Product logo

Comments (5)

tamimattafi avatar tamimattafi commented on July 18, 2024

The issue could be reproduced inside the sample using the following query:

@Query("SELECT * FROM BackPackEntity WHERE(:studentIds IS NULL OR studentId IN :studentIds)")
    suspend fun getStudentBackPacks(
        studentIds: List<String>?
): Flow<List<BackPackEntity>>

The generated code looks like this:

override fun <R> execute(mapper: SqlCursor.() -> QueryResult<R>): QueryResult<R> {
      val studentIds = studentIds.orEmpty()
      val studentIdsIndexes = createArguments(studentIds.size)
      val studentIds = studentIds.orEmpty()
      val studentIdsIndexes = createArguments(studentIds.size)
      val kabinQuery =
          """SELECT * FROM BackPackEntity WHERE($studentIdsIndexes IS NULL OR studentId IN $studentIdsIndexes)"""
      val kabinParametersCount = studentIds.size + studentIds.size + 0
      val result = driver.executeQuery(
              -1664847722,
              kabinQuery,
              mapper,
              kabinParametersCount
          )
       {
        studentIds.forEachIndexed { index, studentIdsChild ->
          bindString(index, studentIdsChild)
        }
        studentIds.forEachIndexed { index, studentIdsChild ->
          bindString(index + studentIds.orEmpty().size, studentIdsChild)
        }
      }
      return result
    }

from kabin.

tamimattafi avatar tamimattafi commented on July 18, 2024

Generated code for such case should and would look like this:

override fun <R> execute(mapper: SqlCursor.() -> QueryResult<R>): QueryResult<R> {
      val studentIdsSize = studentIds.orEmpty().size
      val studentIdsIndexes = createNullableArguments(studentIds?.size)
      val kabinQuery =
          """SELECT * FROM BackPackEntity WHERE($studentIdsIndexes IS NULL OR studentId IN $studentIdsIndexes)"""
      val kabinParametersCount = studentIdsSize + studentIdsSize + 0
      val result = driver.executeQuery(
              261282966,
              kabinQuery,
              mapper,
              kabinParametersCount
          )
       {
        studentIds?.forEachIndexed { index, studentIdsChild ->
          bindString(index, studentIdsChild)
        }
        studentIds?.forEachIndexed { index, studentIdsChild ->
          bindString(index + studentIdsSize, studentIdsChild)
        }
      }
      return result
    }

from kabin.

tamimattafi avatar tamimattafi commented on July 18, 2024

Fixed in 0.1.0-pre-alpha03
Further testing will be made in real environment

from kabin.

tamimattafi avatar tamimattafi commented on July 18, 2024

The generated queries, which look like this, have invalid SQL syntax:

NULL IS NULL OR type IN NULL
(?, ?) IS NULL OR type IN (?, ?)
  1. The IN operator can't be called with NULL
  2. (?, ?) can't be checked as NULL and will break parameters count and indexes

The generated queries should look like this:

NULL IS NULL OR type IN ()
:anyNotNullValue IS NULL OR type IN (?, ?)

from kabin.

tamimattafi avatar tamimattafi commented on July 18, 2024

Testing in a real environment resulted in a success, therefore, this issue is considered solved.
Changes were published to 0.1.0-pre-alpha04

from kabin.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.