如何在KotlinExposed中使用raw sql获取插入的行id?

vuv7lop3  于 2023-04-12  发布在  Kotlin
关注(0)|答案(1)|浏览(164)

我在一个使用raw sql公开了Kotlin的表中插入了一行。是否可以返回行id?

  1. val sql: String =
  2. """
  3. INSERT INTO customer (name, city) VALUES ('Tom', 'Dublin')
  4. """
  5. TransactionManager.current().connection.prepareStatement(sql, true).executeUpdate()
oknwwptz

oknwwptz1#

  1. conn.prepareStatement(sqlString).use { statement ->
  2. statement.executeUpdate()
  3. val insertedId = (statement as ClientPreparedStatement).lastInsertID
  4. }

我使用Kotlin服务器只有6个小时,也许它不能100%正确,但我只能通过cast对象获得id(通过ide调试器发现)。

相关问题