NarayanJr NarayanJr - 1 year ago 112
Scala Question

How do you print out filled in Anorm SQL statements in Play framework

How can I print out the SQL state that is going to be run using Anorm.


SQL(s"SELECT $terms FROM $PERSON_TABLE WHERE name = {name}").on("name" -> "Bill")

Printing that gives me this

SimpleSql(anorm.SqlQuery$$anon$1@1197b8ab,Map(name -> ParameterValue(Bill)),<function1>,false)

I want to see the exact query that is going to run on the server,

SELECT id, name, state FROM person WHERE name = "Bill";

I dont want to use interpolation like this

s"SELECT $terms FROM $PERSON_TABLE WHERE name = $name"

I need to be able to see all the escaped characters and what is wrapped in (') and what is wrapped in (")


Play 2.4.1-Scala



Answer Source

You can use the debuging utility from Acolyte.

import acolyte.jdbc.AcolyteDSL

AcolyteDSL.debuging() { implicit con =>
  // debug any JDBC execution within

  SQL"SELECT * FROM Test WHERE id = $id"
  // Will print the stmt prepared for
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download