JUST EXECUTE THE PARAMETER SQL NOT THE FULL SQL
import scalikejdbc.{DBSession, ReadOnlyAutoSession}
import java.time.LocalDateTime
import javax.inject.{Inject, Singleton}
import scalikejdbc._
import scala.collection.mutable.ArrayBuffer
/**
*
*/
object HelloWorld {
def main(args: Array[String]): Unit = {
val no_parameter: String = findMemberList("")
val has_parameter: String = findMemberList("select * from exchange_transaction")
println(no_parameter)
println(has_parameter)
}
/**
*
*/
private def findMemberList(segmentExecuteSql: String)(
implicit
session: DBSession = ReadOnlyAutoSession
): String = {
if (segmentExecuteSql.isEmpty) {
sql"""
select * from exchange_transaction
"""
.statement
} else {
sql"""
$segmentExecuteSql
"""
.statement
}
}
}
JUST EXECUTE FULL SQL
segmentExecuteSql->select * from exchange_transaction
private def findMemberList(segmentExecuteSql: Option[String])(
implicit
session: DBSession = ReadOnlyAutoSession
): List[String] = {
if (segmentExecuteSql.isEmpty) {
List()
} else {
val resultList: List[List[String]] =
SQL(segmentExecuteSql.get)
.map(
rs =>
List(
rs.string("user_id")
)
)
.list()
.apply()
var memberList = ArrayBuffer[String]()
for (rowList <- resultList) {
for (row <- rowList) {
memberList += row.toString
}
}
memberList.toSet.toList
}
}