I use Anorm to query the database in the Play application. I looked through some tutorials in which SQL(....).execute() returns a Boolean if the execution was successful. I tested the method, but it always returned false (I don't know when it returns true: /). I also tried SQL(...).executeInsert() , but there is no "auto-increment" column in the table, so the problem still exists. Please help me if there is any solution (any extended version of the .execute () method or another) with someone.
Here is the part of my code that doesn't work due to unexpected return ...
def addSuggestion(sessionId: BigInteger, suggestionId: BigInteger) = { DB.withConnection { implicit c => if (!SQL("insert into user_suggestion_" + sessionId + " values (" + suggestionId + ",1,0,0)").execute()) { SQL("update user_suggestion_" + sessionId + " set count=(count+1) where user_id=" + suggestionId).executeUpdate() } } }
The update request should only be executed if the insert fails (due to any restrictions, etc.). Is there any other feature / alternative? Please help. Thank you in advance.
source share