Slick 3.2:无法使用mysql执行upsert操作

时间:2017-08-03 05:02:22

标签: mysql scala playframework slick

我使用slick 3.2来创建简单的CRUD应用程序,但在执行upsert操作时,记录不会更新。但在日志中,似乎记录已更新。以下是我的代码:

private val product = TableQuery[Products]
override def updateProduct(id: Int, row: ProductsRow): Future[Int] = db.run {
    product.insertOrUpdate(row)
  }

ProductsRow(3,'PULLY','DDD',new TimeStamp(new Data().getTime), 4, 202, -1)

我的日志是:

[debug] s.j.J.statement - Preparing statement: insert into `mae_app`.`products` (`id`,`name`,`code`,`date`,`quantity`,`price`,`company_id`)  values (?,?,?,?,?,?,?) on duplicate key update `name`=VALUES(`name`), `code`=VALUES(`code`), `date`=VALUES(`date`), `quantity`=VALUES(`quantity`), `price`=VALUES(`price`), `company_id`=VALUES(`company_id`)
[debug] s.j.J.parameter - /-----+--------+--------+-------------------------+-----+------------+-----\
[debug] s.j.J.parameter - | 1   | 2      | 3      | 4                       | 5   | 6          | 7   |
[debug] s.j.J.parameter - | Int | String | String | Timestamp               | Int | BigDecimal | Int |
[debug] s.j.J.parameter - |-----+--------+--------+-------------------------+-----+------------+-----|
[debug] s.j.J.parameter - | 3   | PULLY  | DDD    | 2017-08-03 10:17:47.144 | 4   | 205.0      | -1  |
[debug] s.j.J.parameter - \-----+--------+--------+-------------------------+-----+------------+-----/

日志看起来像是,记录是用新值更新的,但是当我们检查数据库时,db仍然有旧的记录值。

似乎生成的sql查询不正确,例如on duplicate key update名称=VALUES(名称)语句包含name字段,而不是名称字段值。我无法弄清楚,究竟是什么问题?那么,如何解决这个问题呢?

0 个答案:

没有答案