Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

scala

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).

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 ?

like image 942
Simon Avatar asked Jan 08 '23 07:01

Simon


1 Answers

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.

like image 95
cchantep Avatar answered Jan 28 '23 10:01

cchantep