简体   繁体   English

我应该使用executeUpdate还是execute来用Anorm删除行?

[英]Should I use executeUpdate or execute to delete a row with Anorm?

I'm using Anorm and I wonder which solution is the best to use when I have to delete only one row (for instance here I know that the field eventId is unique). 我正在使用Anorm,我想知道当只删除一行时(例如,在这里我知道eventId字段是唯一的)哪种解决方案最适合使用。

SQL("DELETE FROM events WHERE eventId = {eventId}")
   .on('eventId -> eventId)
   .executeUpdate()

And test if the returned value is 1 or, use this version with execute() : 并测试返回的值是否为1,或者将此版本与execute()

 SQL("DELETE FROM events WHERE eventId = {eventId}")
    .on('eventId -> eventId)
    .execute()

and test if the returned value is true ? 并测试返回的值是否为true

Is there any difference ? 有什么区别吗?

The boolean from .execute doesn't indicate whether it's successful, but whether it has executed a query or an update. .execute中的布尔值并不指示其是否成功,而是指示它是否已执行查询或更新。

Using .executeUpdate , the result is the count of updated/deleted rows. 使用.executeUpdate ,结果是更新/删除的行数。 If the goal is to check whether something has been altered by execution, then .executeUpdate is useful. 如果目标是检查是否已通过执行更改了某些内容,则.executeUpdate很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM