如何从Slick中的最后一条SQL语句获取结果

时间:2019-03-05 11:10:01

标签: sql sql-server scala slick

我有以下Scala代码:

db.run(sql"""
  DECLARE @Ids TABLE (ID INT NOT NULL, UNIQUE CLUSTERED (ID));
  INSERT INTO @Ids VALUES ...;
  SELECT A.* FROM SomeTable AS A
  INNER JOIN @Ids AS B ON A.ID = B.ID
""".as[Dto])

在这种情况下,Slick(3.2.1)返回INSERT(受影响的行数)的结果。

如何从SELECT获取数据?

1 个答案:

答案 0 :(得分:0)

看起来Slick无法做到这一点,但是另一种方法是禁用sql更新的输出:

db.run(sql"""
  SET NOCOUNT ON;
  DECLARE @Ids TABLE (ID INT NOT NULL, UNIQUE CLUSTERED (ID));
  INSERT INTO @Ids VALUES ...;
  SELECT A.* FROM SomeTable AS A
  INNER JOIN @Ids AS B ON A.ID = B.ID
  SET NOCOUNT OFF;
""".as[Dto])