DISABLE ADBLOCK

ADBlock is blocking some content on the site

ADBlock errore

Where is “?” placeholder of sql in play2's anorm

StackOverflow https://stackoverflow.com/questions/9339908

Question

We can write sqls like following in play2's anorm:

def findById(id: String): Option[Link] = DB.withConnection {implicit connection =>
  SQL("select * from links where id={id}").on('id -> id).as(simple.singleOpt)
}

It uses {xxx} format as the placeholder, and the specify a map 'id->id. Is there anyway to use ? as the placeholder as we do in play1?

I hope I can write it like:

def findById(id:String): Option[Link] = DB.withConnection {implicit connection =>
  SQL("select * from links where id=?").on(id).as(simple.singleOpt)
}

This format is very useful sometimes.

Solution

No, currently Anorm uses the Scala symbols for the mapping and you can't use '?'.

This may change in the future, but it is not possible right now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow