Skip to content

Combination of double quotes, asterisks, and GO command breaks deployment #3

@blevalley

Description

@blevalley

If a script both selects a column as a name using double quotes (i.e. SELECT 1 AS "Test/*") and uses a GO command, the upgrade process will fail with message 'Incorrect syntax near GO'. Removing the GO command, or converting the double quotes to either single quotes or square brackets fixes the issue.

Tested on SqlServer 2016 and 2017.

Code to reproduce:

static void Main(string[] args)
        {
            var connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

            /* 
             * SELECT 'Test' AS "Test/*"
             * GO
             */
            var sql = "SELECT 'Test' AS \"Test/*\"\nGO";
            var script = new DbUp.Engine.SqlScript("Tester", sql);

            var builder = DbUp.DeployChanges.To
                .SqlDatabase(connectionString)
                .JournalTo(new NullJournal())
                .WithScripts(script)
                .WithTransaction()
                .LogToConsole()
                .Build();

            var result = builder.PerformUpgrade();
            Debug.Assert(!result.Successful); // Fails

            /*
             * SELECT 'Test' AS "Test/*"
             */
            sql = "SELECT 'Test' AS \"Test/*\"";
            script = new DbUp.Engine.SqlScript("Tester", sql);

            builder = DbUp.DeployChanges.To
            .SqlDatabase(connectionString)
            .JournalTo(new NullJournal())
            .WithScripts(script)
            .WithTransaction()
            .LogToConsole()
            .Build();

            result = builder.PerformUpgrade();
            Debug.Assert(result.Successful); // Succeeds


            /* 
             * SELECT 'Test' AS 'Test/*'
             * GO
             */
            sql = "SELECT 'Test' AS 'Test/*'\nGO";
            script = new DbUp.Engine.SqlScript("Tester", sql);

            builder = DbUp.DeployChanges.To
                .SqlDatabase(connectionString)
                .WithScripts(script)
                .JournalTo(new NullJournal())
                .WithTransaction()
                .LogToConsole()
                .Build();

            result = builder.PerformUpgrade();
            Debug.Assert(result.Successful); // Succeeds
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Bugs

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions