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

Batch Splitter: Handle trailing comments with single quotes. #108

Merged
merged 2 commits into from
Mar 23, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion product/roundhouse.databases.sqlserver/SqlServerDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ public class SqlServerDatabase : AdoNetDatabase

public override string sql_statement_separator_regex_pattern
{
get { return @"(?<KEEP1>^\s*--.*$)|(?<KEEP1>/\*[\S\s]*?\*/)|(?<KEEP1>'[^']*')|(?<KEEP1>\s)(?<BATCHSPLITTER>GO)(?<KEEP2>\s|$)"; }
get
{
const string strings = @"(?<KEEP1>'[^']*')";
const string dashComments = @"(?<KEEP1>--.*$)";
const string starComments = @"(?<KEEP1>/\*[\S\s]*?\*/)";
const string separator = @"(?<KEEP1>\s)(?<BATCHSPLITTER>GO)(?<KEEP2>\s|$)";
return strings + "|" + dashComments + "|" + starComments + "|" + separator;
}
}

public override void initialize_connections(ConfigurationPropertyHolder configuration_property_holder)
Expand Down
31 changes: 29 additions & 2 deletions product/roundhouse.tests/sqlsplitters/StatementSplitterSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -605,4 +631,5 @@ public void should_not_replace_on_assigning_values_to_variables()
}
}
}
}
}