[英]Pattern matching using regex with Scala Anorm
I'm Using Scala(2.11) and playframework(2.3) and trying to run a query using a helper function to get results through pattern matching.我正在使用 Scala(2.11) 和 playframework(2.3) 并尝试使用帮助程序 function 运行查询,以通过模式匹配获得结果。 The function is as follows
function如下
def resultsfunc() = {
val gradeRegex = "^Class 5\."
val currRegex = "\.NCERT$"
DB.withConnection{ implicit c =>
val filterQuery = SQL(
"""
select * from tbl_graphs
where graph_name REGEXP '{grade_regex}' and
graph_name REGEXP '{curr_regex}' and org_id = 4
""")
.on("grade_regex" -> gradeRegex,
"curr_regex" -> currRegex)
filterQuery().map{ graphRecord =>
new ResultObj(graphRecord[Long]("id"),
graphRecord[String]("name"))
}.toList
}
}
I don't get any errors but I get empty result even though there are multiple records that match the pattern.我没有收到任何错误,但即使有多个与模式匹配的记录,我也会得到空结果。 The same query works if I try to run in mysql workbench and when I tried to print
filterQuery
the arguments were also mapped correctly.如果我尝试在 mysql 工作台中运行,并且当我尝试打印
filterQuery
时,同样的查询也有效,arguments 也被正确映射。
Should Pattern matching with regex must be carried out differently in Scala Anorm?是否应该在 Scala 异常中以不同方式执行与正则表达式的模式匹配?
It has absolutely nothing to do specifically with Anorm.它与 Anorm 完全没有关系。
... '{grade_regex}'...
).... '{grade_regex}'...
)。SQL"SELECT x FROM y WHERE z = ${v}"
) rather than SQL(..)
function.SQL"SELECT x FROM y WHERE z = ${v}"
) 而不是SQL(..)
function。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.