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).
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()
:
SQL("DELETE FROM events WHERE eventId = {eventId}")
.on('eventId -> eventId)
.execute()
and test if the returned value is 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.
Using .executeUpdate
, the result is the count of updated/deleted rows. If the goal is to check whether something has been altered by execution, then .executeUpdate
is useful.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.