diff --git a/product/roundhouse.databases.sqlserver/SqlServerDatabase.cs b/product/roundhouse.databases.sqlserver/SqlServerDatabase.cs index 648c6ce5..155922bb 100644 --- a/product/roundhouse.databases.sqlserver/SqlServerDatabase.cs +++ b/product/roundhouse.databases.sqlserver/SqlServerDatabase.cs @@ -16,7 +16,14 @@ public class SqlServerDatabase : AdoNetDatabase public override string sql_statement_separator_regex_pattern { - get { return @"(?^\s*--.*$)|(?/\*[\S\s]*?\*/)|(?'[^']*')|(?\s)(?GO)(?\s|$)"; } + get + { + const string strings = @"(?'[^']*')"; + const string dashComments = @"(?--.*$)"; + const string starComments = @"(?/\*[\S\s]*?\*/)"; + const string separator = @"(?\s)(?GO)(?\s|$)"; + return strings + "|" + dashComments + "|" + starComments + "|" + separator; + } } public override void initialize_connections(ConfigurationPropertyHolder configuration_property_holder) diff --git a/product/roundhouse.tests/sqlsplitters/StatementSplitterSpecs.cs b/product/roundhouse.tests/sqlsplitters/StatementSplitterSpecs.cs index 2727f6b8..f2c21c3f 100644 --- a/product/roundhouse.tests/sqlsplitters/StatementSplitterSpecs.cs +++ b/product/roundhouse.tests/sqlsplitters/StatementSplitterSpecs.cs @@ -118,7 +118,7 @@ public void should_replace_on_go_with_on_new_line_after_double_dash_comments_and } [Observation] - public void should_replace_on_go_with_on_new_line_after_double_dash_comments_and_symbols() + public void should_replace_on_go_with_new_line_after_double_dash_comments_and_symbols() { string sql_to_match = @"-- " + symbols_to_check + @" GO @@ -231,6 +231,32 @@ public void should_replace_on_go_with_words_before_and_after_on_the_same_line_in Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); } + [Observation] + public void should_replace_on_go_after_double_dash_comment_with_single_quote_and_single_quote_after_go() + { + string sql_to_match = words_to_check + @" -- ' +GO +select '' +go"; + string expected_scrubbed = words_to_check + @" -- ' +" + batch_terminator_replacement_string + @" +select '' +" + batch_terminator_replacement_string; + Console.WriteLine(sql_to_match); + string sql_statement_scrubbed = script_regex_replace.Replace(sql_to_match, match => StatementSplitter.evaluate_and_replace_batch_split_items(match, script_regex_replace)); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Observation] + public void should_replace_on_go_with_comment_after() + { + string sql_to_match = " GO -- comment"; + string expected_scrubbed = " " + batch_terminator_replacement_string + " -- comment"; + Console.WriteLine(sql_to_match); + string sql_statement_scrubbed = script_regex_replace.Replace(sql_to_match, match => StatementSplitter.evaluate_and_replace_batch_split_items(match, script_regex_replace)); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + [Observation] public void should_not_replace_on_g() { @@ -605,4 +631,5 @@ public void should_not_replace_on_assigning_values_to_variables() } } } -} \ No newline at end of file +} +