Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing interpolated SQL query in Slick

I am trying to print an interpolated Slick2 SQL statement for debugging and all I get is the one with question marks e.g.

def query(name: String) = sql"SELECT MAX(age) FROM users WHERE name = $name".as[Int]
println(query("Bob").getStatement)   

The above prints this:

SELECT MAX(age) FROM users WHERE name = ?

How can I make it print this:

SELECT MAX(age) FROM users WHERE name = 'Bob'

Note: This questions is NOT a duplicate of this

like image 283
pathikrit Avatar asked Oct 23 '15 16:10

pathikrit


2 Answers

You probably want to add the following to your application.conf

logger.scala.slick.session=DEBUG

This should show compiled query strings in the console.

like image 185
airudah Avatar answered Oct 19 '22 02:10

airudah


From the slick documentation: "You can use #$ instead of $ to get the literal value inserted directly into the query".

//note the '#'
def query(name : String) = sql"SELECT MAX(age) FROM users WHERE name = '#$name'".as[Int]
like image 45
Ramón J Romero y Vigil Avatar answered Oct 19 '22 02:10

Ramón J Romero y Vigil