【问题标题】:Know the result of 'insertIgnore' with Jetbrains Exposed知道 Jetbrains Exposed 的 'insertIgnore' 的结果
【发布时间】:2021-06-03 01:34:48
【问题描述】:

我正在使用 Jetbrains Exposed 与我的 MySQL 5.7 数据库进行交互。
我遇到的问题是insertIgnore

在我看来,没有办法知道语句的结果。如果插入了一行,MySQL 本身将返回 1,如果由于错误(在我的情况下,重复键错误)而被忽略,则返回 0。
但是从插入的结果中我看不到任何方法。

我的代码基本上就是:

transaction(database) {
  MyTable.insertIgnore {
    it[uniqueColumn] = "foo"
  }
}

uniqueColumn 唯一的情况下执行了两次。结果没有区别,虽然第一次成功,第二次没有。

在某处表示该语句的结果行似乎很容易,但我自己或在谷歌搜索时找不到任何东西。

【问题讨论】:

    标签: mysql kotlin-exposed


    【解决方案1】:

    我遇到了类似的问题,我使用 IntIdTable 而不是 Table 解决了它 并用 insertIgnoreAndGetId 代替 insertIgnore

    也许它会帮助任何人

    【讨论】:

    • 请注意,返回的 Id 始终是您尝试保存的实体之一,而不是表中的实体,以防重复。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-05
    • 2022-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多