我有一个sql查询,它返回两行和每列值。我想获取该数据并检查它是否为空。我怎样才能做到这一点? 我是一个新鲜的人,scala与playframework任何人请在这里帮助我。 我使用模型类来存储响应并以json格式显示,但我想知道如何检查数据的条件。
val query= s""" select * from table"""
override def map2Object(implicit map: Map[String, Any]): HierarchyEntryBillingRoleCheck = {
HierarchyEntryBillingRoleCheck(str("roleName"), oint("PersonID"))
}
现在我想知道如何检查sql是否返回空或真数据的条件我想执行下一个sql查询。
所以我尝试了一些在类型转换中出错的方法:
override val singleQuery = s"""select * from Sitable"""
override val allQuery= s"""select * from Sitable1"""
override def map2Object(implicit map: Map[String, Any]): HierarchyEntryBillingRoleCheck = {
HierarchyEntryBillingRoleCheck(str("roleName"), oint("PersonID"))
}
def map2ObjectBilling(implicit map: Map[String, Any]): HierarchyEntryBilling = {
HierarchyEntryBilling(str("Name"), str("Provider"), oint("Year"),
ostr("Month"), ostr("Status"), ostr("ProviderType"))
}
def getAll(implicit loginName: String): Future[Seq[HierarchyEntryBillingRoleCheck]] = {
doQueryIgnoreRowErrors(allQuery, "loginName" -> loginName)
result.map {
if (map2Object.roleName !="" && map2Object.PersonID.isEmpty) {
"error"
} else {
getOnetask()
} //GEtting error with unit type cannot resolve future[seq[]]
}
def getOnetask(): Future[Seq[HierarchyEntryBilling]] = {
doQueryIgnoreRowErrors(singleQuery)
} //Getting error with type unit does not confirm Future[Seq[]]
.// doQueryignore errors signature =>
protected def doQueryIgnoreRowErrors(query: String, args: NamedParameter*)
= {
logger.debug(s"SQL: $query, args: $args")
TimedFuture(actualityTimeout) {
queryHandler.doQuery(query, args: _*) map { list =>
// ignore mapping errors of specific rows
list.flatten
}
} flatMap {
case scala.util.Success(s) => Future.successful(s)
case Failure(ex) if ex.isInstanceOf[SQLException] &&
ex.getMessage == "The executeQuery method must return a result set." =>
Future.successful(Nil)
case Failure(fail) =>
Future.failed(fail)
答案 0 :(得分:1)
请检查doQueryIgnoreRowErrors方法的签名 我怀疑它应该是这样的:
def doQueryIgnoreRowErrors(sql: String, name: String): Future[Seq[HierarchyEntryBillingRoleCheck]] = {
// next lines instead of calling data sources
Future[Seq[HierarchyEntryBillingRoleCheck]] {
List(HierarchyEntryBillingRoleCheck(1, "Data"))
}
}
我认为你得到的结果如下:
def getAll(implicit loginName: String): Future[Seq[HierarchyEntryBillingRoleCheck]] = {
val result = doQueryIgnoreRowErrors(allQuery, "loginName")
..
}
如果你还在努力解决这个问题,请告诉我。