0

I wanno read from cache memory using sql command. Since sql commands are dynamic each time, I need to input it as variable but using variable in sql command is not supported. Here is my code:

import com.typesafe.config.{Config, ConfigFactory}
import com.zaxxer.hikari.{HikariConfig, HikariDataSource}
import javax.sql.DataSource
import scalikejdbc._

  //load config from application.conf
  lazy val config: Config = ConfigFactory.load("application.conf")
  val md: DataSource = {
val hikariConfig = new HikariConfig()
hikariConfig.setJdbcUrl(config.getString("jdbc.ignite.url"))
hikariConfig.setUsername(config.getString("jdbc.ignite.username"))
hikariConfig.setPassword(config.getString("jdbc.ignite.password"))
hikariConfig.setDriverClassName(config.getString("jdbc.ignite.driver"))

val ds = new HikariDataSource(hikariConfig)
ds
}

ConnectionPool.singleton(new 
DataSourceConnectionPool(inMemoryDataSource))
val inMemoryDbName: String = config.getString("jdbc.ignite.name")
ConnectionPool.add(inMemoryDbName, new 
DataSourceConnectionPool(inMemoryDataSource))

lazy val inMemorySession: DBSession = AutoSession
lazy val inMemoryDatabaseExecutorContext: ExecutionContext =
ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(1))

def getAggResult(query: String) = DB readOnly {
  implicit session =>
      sql"$query".map(_.toMap()).list().apply()   
}

The problem is '$' that I used and the error says:

  java.sql.SQLException: Failed to parse query. Syntax error in SQL 
  statement "?[*]"; expected "[, ::, ="; SQL statement:

the query is a select command like select field1, field2 from table name where condition1 like value1

How to resolve that?

ArefehTam
  • 367
  • 1
  • 6
  • 20

1 Answers1

1

Srry, that was my mistake, I changed

 sql"$query".map(_.toMap()).list().apply()  

to

SQL(s"${query}").map(_.toMap()).list().apply()

and it worked

ArefehTam
  • 367
  • 1
  • 6
  • 20