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

Running with ParseGo also splits if there are GO in comments #29

Open
jeffchulg opened this issue Feb 26, 2021 · 1 comment
Open

Running with ParseGo also splits if there are GO in comments #29

jeffchulg opened this issue Feb 26, 2021 · 1 comment

Comments

@jeffchulg
Copy link

jeffchulg commented Feb 26, 2021

Hi,

there is an option -ParseGO which splits a file or query into multiple pieces of code and runs each splitted code once at a time.

The problem is that the split doesn't take into account that GO could be in comments.

Would it be possible add an option to Invoke-SQLCmd2 to find and replace any GO inside a comment (especially those starting with /* and ending with */) by a space before actually splitting ?

Some links that could help:

@jeffchulg jeffchulg changed the title Running with ParseGo also splits if there are GO in comments Running with ParseGo also splits if there are GO in comments or inside quoted string Feb 26, 2021
@jeffchulg jeffchulg changed the title Running with ParseGo also splits if there are GO in comments or inside quoted string Running with ParseGo also splits if there are GO in comments Feb 26, 2021
@jeffchulg
Copy link
Author

Hi, here is what I tested and worked:

I changed the $GoSplitterRegex definition in line 440
from
$GoSplitterRegex = [regex]'(?smi)^[\s]*GO[\s]*$'
to
$GoSplitterRegex = [regex]'(?smi)^\s*GO(?:\s+\d+)?\s*$'

Then I added following line just below:
` $GoSanitizerRegex = '(?sm)/*+?^\sgo(?:\s+\d+)?\s$.+?[*]/'

After that I changed the lines starting 493
from

            if ($ParseGO) {
                Write-Debug -Message "Stripping GOs from source"
                $Pieces = $GoSplitterRegex.Split($Query)
            }

to

            if ($ParseGO) {
                Write-Debug -Message "Stripping GOs from source"
                $SanitizedQuery = $Query -split $GoSanitizerRegex -join ""
                
                if($SanitizedQuery -ne $Query) {
                    Write-Debug "Removed some comments with 'GO' inside it"
                }
                
                $Pieces = $GoSplitterRegex.Split($SanitizedQuery)
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant