Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to cast XML results as nvarchar(max) in order to work with sqlcmd on Linux #55

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Source/Run_Methods.sql
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,11 @@ BEGIN
END;
GO

-- @CastToNvarchar is for use with sqlcmd in order to
-- capture the full output.
-- e.g. sqlcmd -y0 -Q "EXEC tSQLt.XmlResultFormatter @CastToNvarchar=1"
CREATE PROCEDURE tSQLt.XmlResultFormatter
@CastToNvarchar bit = 0
AS
BEGIN
DECLARE @XmlOutput XML;
Expand Down Expand Up @@ -735,7 +739,14 @@ BEGIN
FOR XML EXPLICIT
);

EXEC tSQLt.Private_PrintXML @XmlOutput;
If @CastToNvarchar = 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than adding IF statement there, it would probably better be moved to the Private_PrintXML procedure as now outputting logic is split in 2 different places that kind of bad practice.
Additionally this framework is written using TDD approach so you should write tests to cover this functionality otherwise I'm not sure it will be merged.
And final minor comment is that keywords in this source code are all in UPPERCASE (If, nvarchar, max)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. Is there a CI framework that runs the tests?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently you can only do that locally. If you go to the Build folder, you'll find Install the tSQLt build.docx document with instructions. And if you have troubles with the certificate, you can take a look to the ChangeSigningKey_ReadMe.txt document.
The tests should probably need to be put to the Tests/Run_Methods_Tests.class.sql file

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, you won't be able to do that on Linux ... However as I see from commits, that @mbt1 is currently working on setting automated tests on GitHub so there might be such possibility in the near future.

BEGIN
SELECT CAST(@XmlOutput AS nvarchar(max))
END
ELSE
BEGIN
EXEC tSQLt.Private_PrintXML @XmlOutput;
END
END;
GO

Expand Down