Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert: Incorrect parameters count #22

Closed
tamimattafi opened this issue May 22, 2024 · 1 comment · Fixed by #23
Closed

Insert: Incorrect parameters count #22

tamimattafi opened this issue May 22, 2024 · 1 comment · Fixed by #23

Comments

@tamimattafi
Copy link
Owner

Problem

The generated code uses an incorrect parameters count for @Insert @Update and other similar annotations, it can be reproduced inside the sample, here's an extract from UserDao:

  public suspend fun insertOrReplace(entity: BankEntity) {
    driver.execute(
            -1230324746,
            """INSERT OR REPLACE INTO BankEntity VALUES (?, ?, ?, ?)""",
            1
        )
     {
      bindLong(0, entity.number)
      bindString(1, entity.country)
      bindString(2, entity.region)
      bindString(3, kotlinCollectionsListKotlinStringKotlinStringAdapter.encode(entity.supportedCards))
    }
    notifyQueries(-1230324746) { emit ->
      emit("BankEntity")
    }
  }

Solution

Parameters count must be equal to columns count of the entity, in our example, it must be 4

@tamimattafi
Copy link
Owner Author

There is another issue with the @Update method:

public suspend fun update(entity: UserEntity) {
    driver.execute(
            511551143,
           
            """UPDATE UserEntity SET id = ?, phoneNumber = ?, gender = ?, name = ?, sampleAge = ?, salary = ?, isMarried = ?, spouseId = ?, data = ?, embeddedData_bankNumber = ?, embeddedData_cardToken = ?, embeddedData_cardNumber = ?, embeddedData_car = ?, embeddedData_price = ?, embeddedData_tires = ?, embeddedData_money = ? WHERE id = ? AND phoneNumber = ?""",
            18
        )
     {
      bindLong(0, kotlinIntKotlinLongAdapter.encode(entity.id))
      bindString(1, entity.phoneNumber)
      bindString(2, comAttafitamimKabinLocalEntitiesUserGenderKotlinStringAdapter.encode(entity.gender))
      bindString(3, entity.name)
      bindString(4, kotlinIntKotlinStringAdapter.encode(entity.age))
      bindDouble(5, entity.salary?.let(kotlinFloatKotlinDoubleAdapter::encode))
      bindBoolean(6, entity.isMarried)
      bindLong(7, entity.spouseId?.let(kotlinIntKotlinLongAdapter::encode))
      bindString(8, entity.data)
      bindLong(9, entity.bankInfo?.bankNumber)
      bindString(10, entity.bankInfo?.cardToken)
      bindString(11, entity.bankInfo?.cardNumber)
      bindString(12, entity.bankInfo?.carPurchase?.car)
      bindString(13, entity.bankInfo?.carPurchase?.price)
      bindLong(14, entity.bankInfo?.carPurchase?.tires?.let(kotlinIntKotlinLongAdapter::encode))
      bindDouble(15, entity.bankInfo?.money?.let(kotlinFloatKotlinDoubleAdapter::encode))
    }
    notifyQueries(511551143) { emit ->
      emit("UserEntity")
    }
}

As we can see, primary key columns are not bound at indexes 16 and 17 WHERE id = ? AND phoneNumber = ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant