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.