注意返回多個結果被查詢異常
當我用下面的依賴(即使用ANORM的舊版本)以下按預期工作(沒有拋出異常)。
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.8")
"org.postgresql" % "postgresql" % "9.4-1202-jdbc42"
問題
在PostgreSQL我有一個用戶定義的函數
CREATE OR REPLACE FUNCTION pPersonGet(p_personId bigint)
RETURNS TABLE (
id bigint,
shortname character varying,
longname character varying,
avatarURL character varying,
isActive boolean) AS
$$
BEGIN
return QUERY
select p.id, p.shortname, p.longname, p.avatarURL, p.isActive
From person p
where p_personId is null or p.id = p_personId;
END
$$ LANGUAGE plpgsql;
當ANORM 2.4
val selectStmt =
"""
select id, shortname, longname, avatarURL, isActive from pPersonGet({id});
"""
....
....
val simple = {
get[PersonID]("id") ~
str("shortname") ~
str("longname") ~
str("avatarurl") ~
get[Boolean]("isActive") map {
case id~shortname~longname~avatarurl~isActive
=> Person(Some(id),
Name(short, long),
avatarurl,
isActive)
}
}
....
....
def find(id:Option[PersonID]) : List[Person] = {
DB.withConnection { implicit conn =>
anorm.SQL(selectStmt).on("id" -> id).as(simple *)
}
}
我得到下面的異常執行以下find
功能
[PSQLException: Multiple ResultSets were returned by the query.]
依賴關係:
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.0")
"org.postgresql" % "postgresql" % "9.4-1202-jdbc42"
"com.typesafe.play" %% "anorm" % "2.4.0"
斯卡拉版
scala-sdk-2.11.2
手動執行查詢以檢查結果會很有用。 – cchantep
這並不重要。在PostgreSQL中,多個結果集可能的唯一方式是通過'return setof refcursor',並通過驅動程序仿真將其轉換爲多個結果集。請顯示完整的堆棧跟蹤並仔細檢查您認爲觸發的代碼是實際觸發的代碼。 (編輯問題以添加PostgreSQL和PgJDBC版本以及完整的堆棧跟蹤,然後在完成時發表評論) –