How to use a String value as part of the SQLinterpolation?

101 views
Skip to first unread message

Miguel Angel Fernandez

unread,
Apr 11, 2018, 3:14:58 PM4/11/18
to ScalikeJDBC Users Group
Hi guys,

I'm trying to use a value of String type as part of the SQLinterpolation but simple quotation marks are always added automatically:

val dbName = "myDatabase"

NamedDB(JDBCPoolName) autoCommit { implicit session =>
   sql"""CREATE DATABASE ${dbName}""".update().apply()   
}

The next exception is launched:

SQL execution failed (Reason: ERROR: syntax error at or near "$1"  Position: 17): CREATE DATABASE 'myDatabase'

Any idea?

Miguel Angel Fernandez

unread,
Apr 11, 2018, 6:21:49 PM4/11/18
to ScalikeJDBC Users Group
I answer to myself:

SQL(s"CREATE DATABASE ${dbName}").update().apply()

Kazuhiro Sera

unread,
Apr 11, 2018, 6:24:51 PM4/11/18
to Miguel Angel Fernandez, ScalikeJDBC Users Group
Use SQLSyntax.createUnsafely(String) to build the part "dbName".

Kaz
> --
> You received this message because you are subscribed to the Google Groups
> "ScalikeJDBC Users Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scalikejdbc-users...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages