0

そのようなコードによって発生した例外をどこで見つけることができるのだろうか:

def readFromDB: String = {
    db_sqlite_xml.withSession {
      implicit db: Session =>
        xmlQuery.first.text

    }
  }

洗練された scaladoc ( http://slick.typesafe.com/doc/2.0.1/api/#package ) では見つかりません。javadoc の tableQuery クラスで「最初に」メソッドを検索しましたが、成功しませんでした。

ありがとう。

オリビエ

ps:これが私の答えです、それは働いています:

def readFromDB: String = {
    db_sqlite_xml.withSession {
      implicit db: Session =>
        xmlQuery.firstOption.map(u=>u.text).getOrElse("")
    }
  }
}

答えてくれてありがとう、それは私を助けました。

4

1 に答える 1

1

メソッドはscaladocUnitInvokerのtrait に属します:

final def first()(implicit session: SessionDef): R

Execute the statement and return the first row of the result set. 
If the result set is empty, a NoSuchElementException is thrown.

例外をキャッチしようとする代わりに、アドバイスできる場合は、次を使用する必要がありますfirstOption

final def firstOption()(implicit session: SessionDef): Option[R]

Execute the statement and return the first row of the result set wrapped in Some, 
or None if the result set is empty.

このようにして、次のようにクエリ結果を param-match できます。

def readFromDB: String = {
  db_sqlite_xml.withSession {
    implicit db: Session =>
      xmlQuery.firstOption match {
        case Some(value) => value.text
        case _ => // handle no result
      }
  }
}
于 2014-04-19T17:48:40.373 に答える