denisenkom / go-mssqldb

Microsoft SQL server driver written in go language
BSD 3-Clause "New" or "Revised" License
1.81k stars 493 forks source link

Reading sqlexp.Messages #787

Closed dmzkrsk closed 12 months ago

dmzkrsk commented 12 months ago

I try to use sqlexp.Messages as it's implemented in https://github.com/denisenkom/go-mssqldb/pull/690

I created a test procedure and run it in docker image mcr.microsoft.com/azure-sql-edge:latest

CREATE OR ALTER PROCEDURE procedureWithPrint
AS
BEGIN
  PRINT N'1';
  PRINT N'2';
  SELECT *
  from example
  WHERE id > 7
  ORDER BY ID desc;
  PRINT N'3';
END;

Using an example code in https://github.com/microsoft/go-mssqldb/blob/main/messages_example_test.go#L69 I get only two first prints, since after the SELECT, NextResultSet returns false

If I remove active = rows.NextResultSet() (so active is always true) I get message with 3, but the loop does not break.

When procedure contains no selects:

CREATE OR ALTER PROCEDURE procedureWithPrint
AS
BEGIN
  PRINT N'1';
  PRINT N'2';
  PRINT N'3';
END;

I get all three messages

Am I doing it wrong? What is correct way to get all three messages AND select results AND make the loop to stop?