mercredi 4 février 2015

Scala Increment Counter on calling Function


Vote count:

0




How to increment a function each time its called in scala? I have a function A which performs a set of actions, when a user calls the function A, i would like to have a counter which increments and returns the counter value. The below code doesnt return the expected counter of 1 when i call it.



def return_id (email_user: String) : Int = {
Thread.sleep(1000)
val count = 0
implicit val conn = ExecuteQuery.getConnection(GENERAL_DB, DB_USER, DB_PASS)
var idQuery=executeQuery(s"SELECT id FROM Profile WHERE email = '$email_user';")
idQuery.first()
val pid=idQuery.getInt("id")
println(pid)
if(pid != 0){
+count = 1
}
return count
}


asked 32 secs ago







Scala Increment Counter on calling Function

Aucun commentaire:

Enregistrer un commentaire