-5
val resultList: List[List[String]] =
  sql"""
       select * from exchange_transaction
     """
    .map(
      rs =>
        List(
          rs.string("transaction_id")
        )
    )
    .list()
    .apply()

执行上面的代码,没问题,但是这个sql“select * from exchange_transaction”不固定。我想要这个 sql 像一个参数,就像下面(速记代码.....)

def findMemberList(segmentExecuteSql: String
    val resultList: List[List[String]] =
      sql"""
           $segmentExecuteSql
         """
        .map(
          rs =>
            List(
              rs.string("transaction_id")
            )
        )
        .list()
        .apply()

但执行后出现错误消息是

[error] s.StatementExecutor$$anon$1 - SQL execution failed (Reason: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''select * from  exchange_transaction'' at line 1
Query is : 
           'select * from  exchange_transaction'
         ):

   'select * from  exchange_transaction'

我该怎么办,如何解决异常?

4

2 回答 2

0

你可以尝试resultList变成一个函数:

import scalikejdbc.SQL

def resultList(sqlQuery: String): List[List[String]] =
  SQL(sqlQuery)
    .map(
      rs =>
        List(
          rs.string("transaction_id")
        )
    )
    .list()
    .apply()
于 2016-12-06T13:18:10.627 回答
0
val resultList: List[List[String]] =
  SQL(segmentExecuteSql)
    .map(
      rs =>
        List(
          rs.string("transaction_id")
        )
    )
    .list()
    .apply()
于 2016-12-08T04:17:31.303 回答