Environment
- WCDB
2.1.15 (com.tencent.wcdb:compiler / main / annotation)
- Annotation processing via KSP (
com.google.devtools.ksp), Kotlin 2.x, AGP 9, Android
Problem
For a Kotlin @WCDBTableCoding model with an auto-increment Long primary key, the KSP-generated ORM (DBXxxModel.kt) emits an isAutoIncrement that does not compile:
override fun isAutoIncrement(`object`: KspAutoIncProbe): Boolean {
return `object`.databaseId == 0
}
databaseId is Long, the literal 0 is Int, and Kotlin rejects mixed-type ==:
e: .../DBKspAutoIncProbe.kt:83:10 Operator '==' cannot be applied to 'Long' and 'Int'.
So any Kotlin model with an auto-increment Long primary key fails to compile. The Java generator is unaffected because Java applies numeric promotion for long == 0; Kotlin does not allow Long == Int.
The field must stay Long (the generated setLastInsertRowId(object, lastInsertRowId: Long) assigns a Long, and rowid is 64-bit), so it cannot be worked around on the model side.
Minimal reproduction
package com.example
import com.tencent.wcdb.WCDBField
import com.tencent.wcdb.WCDBTableCoding
@WCDBTableCoding
class KspAutoIncProbe {
@WCDBField(isPrimary = true, isAutoIncrement = true)
var databaseId: Long = 0
@WCDBField
var nullableLong: Long? = null
}
Build with the KSP processor. The generated DBKspAutoIncProbe.kt contains return \object`.databaseId == 0`, which fails Kotlin compilation.
Suggested fix
Emit a Long literal in the generated comparison for Long fields, e.g. \object`.databaseId == 0L(or.toLong()), wherever the Kotlin generator compares a Long` field against an integer literal.
Question
Is this already fixed in 2.1.16 (current latest)? We are on 2.1.15 and would like to migrate our Java ORM models to Kotlin once the generated Kotlin compiles for auto-increment Long primary keys.
Environment
2.1.15(com.tencent.wcdb:compiler/main/annotation)com.google.devtools.ksp), Kotlin 2.x, AGP 9, AndroidProblem
For a Kotlin
@WCDBTableCodingmodel with an auto-incrementLongprimary key, the KSP-generated ORM (DBXxxModel.kt) emits anisAutoIncrementthat does not compile:databaseIdisLong, the literal0isInt, and Kotlin rejects mixed-type==:So any Kotlin model with an auto-increment
Longprimary key fails to compile. The Java generator is unaffected because Java applies numeric promotion forlong == 0; Kotlin does not allowLong == Int.The field must stay
Long(the generatedsetLastInsertRowId(object, lastInsertRowId: Long)assigns aLong, and rowid is 64-bit), so it cannot be worked around on the model side.Minimal reproduction
Build with the KSP processor. The generated
DBKspAutoIncProbe.ktcontainsreturn \object`.databaseId == 0`, which fails Kotlin compilation.Suggested fix
Emit a
Longliteral in the generated comparison forLongfields, e.g.\object`.databaseId == 0L(or.toLong()), wherever the Kotlin generator compares aLong` field against an integer literal.Question
Is this already fixed in
2.1.16(current latest)? We are on2.1.15and would like to migrate our Java ORM models to Kotlin once the generated Kotlin compiles for auto-incrementLongprimary keys.