crimdon / SQLToolkit

An Extension for Azure DevOps Server
MIT License
17 stars 14 forks source link

GO Commands at beginning of files break scripts #68

Closed tophallen closed 5 years ago

tophallen commented 5 years ago

While it is bad practice on the part of a script writer, I don't always have control over preventing it from happening, if a script has a random GO statement at the beginning of the file (which SSMS doesn't complain about) then it tries to execute GO as a SQL Command. i.e.

GO

SET ANSI_NULLS ON
GO
-- rest of script file

While there is no good reason to have an empty GO statement, it should be handled appropriately and not executed as a command statement.

By changing it to check for newline before or after, we can capture both start, end, and middle GO statements.

This seems to work based on all my testing:

-split '(\r?\n\s*go\s*\r?\n)|(^go\s*\r?\n)|(\r?\n\s*go)'
crimdon commented 5 years ago

Hi Chris,

I'll sort out this fix and get a new version out sometime this week