i do not want to delete and reinsert every row, so I have used the following to try to use multiple rows with anorm:
SQL("""
delete from PERSON_ROLES
WHERE person_id = {userId}
and role_id not in ({rolescommastring})
)
""").on('userId -> userId,
'rolescommastring -> rolescommastring).execute()
The above yields a string that it doesn't like and i get :
c.j.b.PreparedStatementHandle - delete from PERSON_ROLES WHERE person_id = 1460 and role_id not in ( '1, 3, 8, 9' )
can i create dynamic sql with anorm?
Since Anorm 2.3, multi-value parameters are supported.
SQL("""
delete from PERSON_ROLES
WHERE person_id = {userId}
and role_id not in ({rolescommastring})
)
""").on('userId -> userId,
'rolescommastring -> Seq("id1", "id2", "id3")).execute()
There are more similar examples at https://www.playframework.com/documentation/2.3.x/ScalaAnorm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With