DbUp / dbup-mysql

MySQL provider for DbUp
MIT License
2 stars 8 forks source link

dbup-mysql not handling 'delimiter' correctly #7

Closed graemevwilson closed 7 months ago

graemevwilson commented 5 years ago

When using dbup v4 if a statement contains the word 'delimiter' then the word and the following word are dropped from the statement. This causes a problem if the word occurs in a string that's being inserted or updated for example. See the unit test below. This was not an issue in v3.3.5.

Expecting 'Some text with delimiter in it' to be written to the database but what actually gets written is 'Some text with it'.

        [Fact]
        public void DoesNotParseOutTheWordDelimiterWhenItsInAString()
        {
            var multiCommand = "USE `test`;";
            multiCommand += "CREATE TABLE IF NOT EXISTS 'FOO';";
            multiCommand += Environment.NewLine;
            multiCommand += "DELIMITER $$";
            multiCommand += Environment.NewLine;
            multiCommand += "CREATE TABLE 'ZIP'$$";
            multiCommand += Environment.NewLine;
            multiCommand += "CREATE TABLE IF NOT EXISTS 'BAR';";
            multiCommand += Environment.NewLine;
            multiCommand += "INSERT INTO mytable(description) VALUES ('Some text with delimiter in it');";

            var connectionManager = new MySqlConnectionManager("connectionstring");
            var result = connectionManager.SplitScriptIntoCommands(multiCommand);

            var enumerable = result as string[] ?? result.ToArray();
            enumerable.Length.ShouldBe(4);
            enumerable[0].IndexOf("DELIMITER", StringComparison.Ordinal).ShouldBe(-1);
            enumerable[1].IndexOf("DELIMITER", StringComparison.Ordinal).ShouldBe(-1);
            enumerable[2].IndexOf("DELIMITER", StringComparison.Ordinal).ShouldBe(-1);
            enumerable[3].IndexOf("DELIMITER", StringComparison.OrdinalIgnoreCase).ShouldBeGreaterThan(-1);
        }