dsaeyrq451928 2018-08-23 08:53
浏览 45

在Go中同时获取多个结果集和输出,但是如何首先扫描输出?

I'm executing a stored procedure (using go-mssqldb driver), and I'm getting multiple sets with results and then selecting the output. This is the snippet:

query := "DECLARE @ErrorMessage nvarchar(4000);"+
    "EXEC [Schema].[Action] "+
    "@myInputParam=?,"+
    "@ErrorMessage = @ErrorMessage OUTPUT;"+
    "SELECT ErrorMessage = @ErrorMessage;"

ctx: ...

rows, err := r.DB.QueryxContext(ctx, query, "blabla")

in this way I can read and scan the results sets in the rows with the combination of rows.Next()and rows.NextResultSet().

And in the end I Scan the ErrorMessage in last set.

BUT it happens that the stored may return only the ErrorMessage set, breaking my expectations in the code.

So what I need is to always read the output first and then, if no error, proceed with the waltz of the reads and scans of the other sets.

I tried this way hoping to populate the var errorMessage:

QueryxContext(ctx, query, "blabla", sql.Named("ErrorMessage", sql.Out{Dest: &errorMessage}))

but it doesn't work and it complains with sql: statement expects 1 inputs; got 2

EDIT1

this is the stored I'm calling

CREATE PROCEDURE [Schema].[Action]
    @myInputParam   VARCHAR(100),
    @ErrorMessage nvarchar(4000) OUTPUT
AS 
  BEGIN
      SELECT @Id = Id
      FROM ...
      WHERE Param = @myInputParam

      IF @Id IS NULL
        BEGIN
          SET @ErrorMessage = "some error";
        END
  END
GO
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?