Kotlin: 1.6.20
Ktorm: 3.4.1
MySQL Connector/J: 8.0.28
C3P0 Connection Pool: 0.9.5.5
I seem to be having a problem with "datetimes" (LocalDateTime) that have zero seconds. I know this would look like an issue with the JDBC driver but I tested the driver and it does not even accept LocalDateTime (only java.util.Date). This issue does not come up if the LDT does have seconds.
- Am I doing something wrong?
- Am I missing some configuration?
- Have I got the types wrong?
- Does anyone know of a workaround?
A minimum test that I am using to isolate the issue
const val tableName = "test"
const val fieldName = "ldt"
interface TestRecord : Entity<TestRecord> {
companion object : Entity.Factory<TestRecord>()
val ldt: LocalDateTime
}
object TestTable : Table<TestRecord>(tableName) {
val ldt = datetime(fieldName).bindTo { it.ldt }
}
class BlahTest {
@Test
fun a() {
val dataSource = DbConfig.from("test.properties").provideDataSource()
dataSource.connection.use {
it.prepareStatement("DROP TABLE IF EXISTS $tableName").execute()
it.prepareStatement("CREATE TABLE IF NOT EXISTS $tableName ($fieldName TIMESTAMP)").execute()
}
val db = Database.connect(dataSource = dataSource, dialect = MySqlDialect())
val tb = TestTable
val ldt = LocalDateTime.ofEpochSecond(0, 0, ZoneOffset.UTC)
.truncatedTo(ChronoUnit.SECONDS)
//.plusSeconds(1) // with anything but 0 it will work
db.insertOrUpdate(TestTable) {
set(tb.ldt, ldt)
}
}
}
Produces an error
com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Incorrect datetime value: '1970-01-01 00:00:00' for column 'ldt' at row 1
Ktorm issue: https://github.com/kotlin-orm/ktorm/issues/391