Insert: Incorrect parameters count
Closed this issue · 1 comments
tamimattafi commented
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 commented
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 = ?