Skip to content

Comments within the SQL scripts can cause problems #1

@phaselden

Description

@phaselden

For example, when "GO" is within multi-line comments.

I would do a PR but I have been hacking away at the code and it's all a bit messy ATM. However the following seems to work if called from the top of the DBHelper.ExecuteMigration method:

private string RemoveSqlComments(string commandText)
{
    // Remove all comments, mainly because GO might be in the comments and since we split
    // on that it can cause problems. The regular expression used below is from:
    // http://stackoverflow.com/questions/7690380/regular-expression-to-match-all-comments-in-a-t-sql-script

    Regex commentRegex = new Regex("(--.*)|(((/\\*)+?[\\w\\W]+?(\\*/)+))", RegexOptions.CultureInvariant);
    return commentRegex.Replace(commandText, "");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions