I am using Anorm for database queries in my Play application. I went through some tutorials it is given that SQL(....).execute()
returns Boolean
if execution was succesful. I tested the method but it always returned false
(don't know when it returns true:/ ). I also tried SQL(...).executeInsert()
but there is not any 'auto-increment' column in the table, so the problem still exists. Please help me if there is any solution(any expanded version of the '.execute()' method or other) with anyone.
Here is a part of my code which is failing 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 query should run only when the insertion fails(due to any constraint etc.). Is there any other function/alternative? Please help. Thanks in advance.