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

execute the above code,it is ok but this sql "select * from exchange_transaction" is not fixed. I want this sql like a parameter ,like the follow(shorthand code.....)

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

but it's error after the execution the message is

[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'

what should i do ,how to fix the exception?

Syscall
  • 19,327
  • 10
  • 37
  • 52
DJQTDJ
  • 71
  • 1
  • 9

2 Answers2

0

You can try turning resultList into a function:

import scalikejdbc.SQL

def resultList(sqlQuery: String): List[List[String]] =
  SQL(sqlQuery)
    .map(
      rs =>
        List(
          rs.string("transaction_id")
        )
    )
    .list()
    .apply()
adamwy
  • 1,239
  • 1
  • 7
  • 12
0
val resultList: List[List[String]] =
  SQL(segmentExecuteSql)
    .map(
      rs =>
        List(
          rs.string("transaction_id")
        )
    )
    .list()
    .apply()
DJQTDJ
  • 71
  • 1
  • 9
  • 4
    While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – DimaSan Dec 08 '16 at 09:59
  • thank you for your comment, my account has been ban.do you know how to get out of a question ban? – DJQTDJ Aug 06 '21 at 04:55
  • https://meta.stackoverflow.com/questions/255583/what-can-i-do-when-getting-we-are-no-longer-accepting-questions-answers-from-th – DimaSan Aug 06 '21 at 14:57