From 2ef9633cbb0b3db89fef2806f562eaf05df87828 Mon Sep 17 00:00:00 2001 From: "Erik A. Brandstadmoen" Date: Mon, 10 Apr 2023 22:07:47 +0200 Subject: [PATCH] Added unit tests for statement splitting on Oracle (#328) Maybe they need a bit more refinement, but that'll come later --- .../BatchSplitterReplacer_.cs | 563 ++++++++++++++++++ .../Statement_Splitting/StatementSplitter_.cs | 32 + .../BatchSplitterReplacer_.cs | 4 +- .../OracleSplitterContext.cs | 221 +++++++ ...Context.cs => SqlServerSplitterContext.cs} | 2 +- grate/Infrastructure/OracleSyntax.cs | 2 +- 6 files changed, 820 insertions(+), 4 deletions(-) create mode 100644 grate.unittests/Basic/Infrastructure/Oracle/Statement_Splitting/BatchSplitterReplacer_.cs create mode 100644 grate.unittests/Basic/Infrastructure/Oracle/Statement_Splitting/StatementSplitter_.cs create mode 100644 grate.unittests/TestInfrastructure/OracleSplitterContext.cs rename grate.unittests/TestInfrastructure/{SplitterContext.cs => SqlServerSplitterContext.cs} (98%) diff --git a/grate.unittests/Basic/Infrastructure/Oracle/Statement_Splitting/BatchSplitterReplacer_.cs b/grate.unittests/Basic/Infrastructure/Oracle/Statement_Splitting/BatchSplitterReplacer_.cs new file mode 100644 index 00000000..0909624b --- /dev/null +++ b/grate.unittests/Basic/Infrastructure/Oracle/Statement_Splitting/BatchSplitterReplacer_.cs @@ -0,0 +1,563 @@ +using grate.Infrastructure; +using grate.Migration; +using grate.unittests.TestInfrastructure; +using Microsoft.Extensions.Logging.Abstractions; +using NUnit.Framework; + +// ReSharper disable InconsistentNaming + +namespace grate.unittests.Basic.Infrastructure.Oracle.Statement_Splitting; + +[TestFixture] +[Category("Basic")] +public class BatchSplitterReplacer_ +{ + private const string Batch_terminator_replacement_string = StatementSplitter.BatchTerminatorReplacementString; + + private const string Symbols_to_check = "`~!@#$%^&*()-_+=,.;:'\"[]\\/?<>"; + private const string Words_to_check = "abcdefghijklmnopqrstuvwzyz0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + private static readonly IDatabase Database = new OracleDatabase(NullLogger.Instance); + private static BatchSplitterReplacer Replacer => new(Database.StatementSeparatorRegex, StatementSplitter.BatchTerminatorReplacementString); + + public class should_replace_on + { + [Test] + public void full_statement_without_issue() + { + string sql_to_match = OracleSplitterContext.FullSplitter.PLSqlStatement; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(OracleSplitterContext.FullSplitter.PLSqlStatementScrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_space() + { + const string sql_to_match = @" / "; + string expected_scrubbed = @" " + Batch_terminator_replacement_string + @" "; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_tab() + { + string sql_to_match = @" /" + "\t"; + string expected_scrubbed = @" " + Batch_terminator_replacement_string + "\t"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_by_itself() + { + const string sql_to_match = @"/"; + string expected_scrubbed = Batch_terminator_replacement_string; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_starting_file() + { + const string sql_to_match = @"/ +whatever"; + string expected_scrubbed = Batch_terminator_replacement_string + @" +whatever"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_new_line() + { + const string sql_to_match = @" / +"; + string expected_scrubbed = @" " + Batch_terminator_replacement_string + @" +"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_one_new_line_after_double_dash_comments() + { + const string sql_to_match = + @"-- +/ +"; + string expected_scrubbed = + @"-- +" + Batch_terminator_replacement_string + @" +"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_one_new_line_after_double_dash_comments_and_words() + { + string sql_to_match = @"-- " + Words_to_check + @" +/ +"; + string expected_scrubbed = @"-- " + Words_to_check + @" +" + Batch_terminator_replacement_string + @" +"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_new_line_after_double_dash_comments_and_symbols() + { + string sql_to_match = @"-- " + Symbols_to_check + @" +/ +"; + string expected_scrubbed = @"-- " + Symbols_to_check + @" +" + Batch_terminator_replacement_string + @" +"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_on_its_own_line() + { + const string sql_to_match = @" +/ +"; + string expected_scrubbed = @" +" + Batch_terminator_replacement_string + @" +"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_no_line_terminator() + { + const string sql_to_match = @" / "; + string expected_scrubbed = @" " + Batch_terminator_replacement_string + @" "; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_words_before() + { + string sql_to_match = Words_to_check + @" / +"; + string expected_scrubbed = Words_to_check + @" " + Batch_terminator_replacement_string + @" +"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_symbols_and_words_before() + { + string sql_to_match = Symbols_to_check + Words_to_check + @" / +"; + string expected_scrubbed = Symbols_to_check + Words_to_check + @" " + + Batch_terminator_replacement_string + @" +"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_words_and_symbols_before() + { + string sql_to_match = Words_to_check + Symbols_to_check + @" / +"; + string expected_scrubbed = Words_to_check + Symbols_to_check + @" " + + Batch_terminator_replacement_string + @" +"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_words_after_on_the_same_line() + { + string sql_to_match = @" / " + Words_to_check; + string expected_scrubbed = @" " + Batch_terminator_replacement_string + @" " + Words_to_check; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_words_after_on_the_same_line_including_symbols() + { + string sql_to_match = @" / " + Words_to_check + Symbols_to_check; + string expected_scrubbed = @" " + Batch_terminator_replacement_string + @" " + Words_to_check + + Symbols_to_check; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_words_before_and_after_on_the_same_line() + { + string sql_to_match = Words_to_check + @" / " + Words_to_check; + string expected_scrubbed = Words_to_check + @" " + Batch_terminator_replacement_string + @" " + + Words_to_check; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_words_before_and_after_on_the_same_line_including_symbols() + { + string sql_to_match = Words_to_check + Symbols_to_check.Replace("'", "").Replace("\"", "") + + " / BOB" + Symbols_to_check; + string expected_scrubbed = Words_to_check + Symbols_to_check.Replace("'", "").Replace("\"", "") + + " " + Batch_terminator_replacement_string + " BOB" + Symbols_to_check; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_after_double_dash_comment_with_single_quote_and_single_quote_after_slash() + { + string sql_to_match = Words_to_check + @" -- ' +/ +select '' +/"; + string expected_scrubbed = Words_to_check + @" -- ' +" + Batch_terminator_replacement_string + @" +select '' +" + Batch_terminator_replacement_string; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_comment_after() + { + string sql_to_match = " / -- comment"; + string expected_scrubbed = " " + Batch_terminator_replacement_string + " -- comment"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_semicolon_directly_after() + { + string sql_to_match = "jalla /;"; + string expected_scrubbed = "jalla " + Batch_terminator_replacement_string + ";"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + } + + public class should_not_replace_on + { + + [Test] + public void slash_when_slash_is_the_last_part_of_the_last_word_on_a_line() + { + string sql_to_match = Words_to_check + @"/ +"; + string expected_scrubbed = Words_to_check + @"/ +"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_double_dash_comment_starting_line() + { + string sql_to_match = @"--/ +"; + string expected_scrubbed = @"--/ +"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_double_dash_comment_and_space_starting_line() + { + string sql_to_match = @"-- / +"; + string expected_scrubbed = @"-- / +"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_double_dash_comment_and_space_starting_line_and_words_after_slash() + { + string sql_to_match = @"-- / " + Words_to_check + @" +"; + string expected_scrubbed = @"-- / " + Words_to_check + @" +"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_double_dash_comment_and_space_starting_line_and_symbols_after_slash() + { + string sql_to_match = @"-- / " + Symbols_to_check + @" +"; + string expected_scrubbed = @"-- / " + Symbols_to_check + @" +"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_double_dash_comment_and_tab_starting_line() + { + string sql_to_match = "--" + "\t" + @"/ +"; + string expected_scrubbed = @"--" + "\t" + @"/ +"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_double_dash_comment_and_tab_starting_line_and_words_after_slash() + { + string sql_to_match = @"--" + "\t" + @"/ " + Words_to_check + @" +"; + string expected_scrubbed = @"--" + "\t" + @"/ " + Words_to_check + @" +"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_double_dash_comment_and_tab_starting_line_and_symbols_after_slash() + { + string sql_to_match = @"--" + "\t" + @"/ " + Symbols_to_check + @" +"; + string expected_scrubbed = @"--" + "\t" + @"/ " + Symbols_to_check + @" +"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_double_dash_comment_starting_line_with_words_before_slash() + { + string sql_to_match = @"-- " + Words_to_check + @" / +"; + string expected_scrubbed = @"-- " + Words_to_check + @" / +"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_when_between_tick_marks() + { + const string sql_to_match = @"' / + '"; + const string expected_scrubbed = @"' / + '"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void + slash_when_between_tick_marks_with_symbols_and_words_before_ending_on_same_line() + { + string sql_to_match = @"' " + Symbols_to_check.Replace("'", string.Empty) + Words_to_check + @" /'"; + string expected_scrubbed = + @"' " + Symbols_to_check.Replace("'", string.Empty) + Words_to_check + @" /'"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_when_between_tick_marks_with_symbols_and_words_before() + { + string sql_to_match = @"' " + Symbols_to_check.Replace("'", string.Empty) + Words_to_check + @" / + '"; + string expected_scrubbed = @"' " + Symbols_to_check.Replace("'", string.Empty) + Words_to_check + @" / + '"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_when_between_tick_marks_with_symbols_and_words_after() + { + string sql_to_match = @"' / + " + Symbols_to_check.Replace("'", string.Empty) + Words_to_check + @"'"; + string expected_scrubbed = @"' / + " + Symbols_to_check.Replace("'", string.Empty) + Words_to_check + @"'"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_with_double_dash_comment_starting_line_with_symbols_before_slash() + { + string sql_to_match = @"--" + Symbols_to_check + @" / +"; + string expected_scrubbed = @"--" + Symbols_to_check + @" / +"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void + slash_with_double_dash_comment_starting_line_with_words_and_symbols_before_slash() + { + string sql_to_match = @"--" + Symbols_to_check + Words_to_check + @" / +"; + string expected_scrubbed = @"--" + Symbols_to_check + Words_to_check + @" / +"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_inside_of_comments() + { + string sql_to_match = @"/* / */"; + string expected_scrubbed = @"/* / */"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_inside_of_comments_with_a_line_break() + { + string sql_to_match = @"/* / +*/"; + string expected_scrubbed = @"/* / +*/"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_inside_of_comments_with_words_before() + { + string sql_to_match = + @"/* +" + Words_to_check + @" / + +*/"; + string expected_scrubbed = + @"/* +" + Words_to_check + @" / + +*/"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_inside_of_comments_with_words_before_on_a_different_line() + { + string sql_to_match = + @"/* +" + Words_to_check + @" +/ + +*/"; + string expected_scrubbed = + @"/* +" + Words_to_check + @" +/ + +*/"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_inside_of_comments_with_words_before_and_after_on_different_lines() + { + string sql_to_match = + @"/* +" + Words_to_check + @" +/ + +" + Words_to_check + @" +*/"; + string expected_scrubbed = + @"/* +" + Words_to_check + @" +/ + +" + Words_to_check + @" +*/"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + + [Test] + public void slash_inside_of_comments_with_symbols_after_on_different_lines() + { + string sql_to_match = + @"/* +/ + +" + Symbols_to_check + @" +*/"; + string expected_scrubbed = + @"/* +/ + +" + Symbols_to_check + @" +*/"; + TestContext.WriteLine(sql_to_match); + string sql_statement_scrubbed = Replacer.Replace(sql_to_match); + Assert.AreEqual(expected_scrubbed, sql_statement_scrubbed); + } + } + +} diff --git a/grate.unittests/Basic/Infrastructure/Oracle/Statement_Splitting/StatementSplitter_.cs b/grate.unittests/Basic/Infrastructure/Oracle/Statement_Splitting/StatementSplitter_.cs new file mode 100644 index 00000000..d5bf5a6c --- /dev/null +++ b/grate.unittests/Basic/Infrastructure/Oracle/Statement_Splitting/StatementSplitter_.cs @@ -0,0 +1,32 @@ +using FluentAssertions; +using grate.Infrastructure; +using grate.Migration; +using Microsoft.Extensions.Logging.Abstractions; +using NUnit.Framework; + +namespace grate.unittests.Basic.Infrastructure.Oracle.Statement_Splitting; + +[TestFixture] +[Category("Basic")] +// ReSharper disable once InconsistentNaming +public class StatementSplitter_ +{ + private static readonly IDatabase Database = new OracleDatabase(NullLogger.Instance); + private static readonly StatementSplitter Splitter = new(Database.StatementSeparatorRegex); + + [Test] + public void Splits_and_removes_GO_statements() + { + var original = @" +SELECT * FROM v$version WHERE banner LIKE 'Oracle%'; + + +/ +SELECT 1 +"; + var batches = Splitter.Split(original); + + batches.Should().HaveCount(2); + } + +} diff --git a/grate.unittests/Basic/Infrastructure/SqlServer/Statement_Splitting/BatchSplitterReplacer_.cs b/grate.unittests/Basic/Infrastructure/SqlServer/Statement_Splitting/BatchSplitterReplacer_.cs index 4cc55838..52510e3d 100644 --- a/grate.unittests/Basic/Infrastructure/SqlServer/Statement_Splitting/BatchSplitterReplacer_.cs +++ b/grate.unittests/Basic/Infrastructure/SqlServer/Statement_Splitting/BatchSplitterReplacer_.cs @@ -25,10 +25,10 @@ public class should_replace_on [Test] public void full_statement_without_issue() { - string sql_to_match = SplitterContext.FullSplitter.tsql_statement; + string sql_to_match = SqlServerSplitterContext.FullSplitter.tsql_statement; TestContext.WriteLine(sql_to_match); string sql_statement_scrubbed = Replacer.Replace(sql_to_match); - Assert.AreEqual(SplitterContext.FullSplitter.tsql_statement_scrubbed, sql_statement_scrubbed); + Assert.AreEqual(SqlServerSplitterContext.FullSplitter.tsql_statement_scrubbed, sql_statement_scrubbed); } [Test] diff --git a/grate.unittests/TestInfrastructure/OracleSplitterContext.cs b/grate.unittests/TestInfrastructure/OracleSplitterContext.cs new file mode 100644 index 00000000..5c5e856d --- /dev/null +++ b/grate.unittests/TestInfrastructure/OracleSplitterContext.cs @@ -0,0 +1,221 @@ +using grate.Infrastructure; +// ReSharper disable StringLiteralTypo + +namespace grate.unittests.TestInfrastructure; + +public static class OracleSplitterContext +{ + + public static class FullSplitter + { + public static string PLSqlStatement = @" +BOB1 +/ + +/* COMMENT */ +BOB2 +/ + +-- / + +BOB3 / + +--`~!@#$%^&*()-_+=,.;:'""[]\/?<> / + +BOB5 + / + +BOB6 +/ + +/* / */ + +BOB7 + +/* + +/ + +*/ + +BOB8 + +-- +/ + +BOB9 + +-- `~!@#$%^&*()-_+=,.;:'""[]\/?<> +/ + +BOB10/ + +CREATE TABLE PO/ +{} + +INSERT INTO PO/ (id,desc) VALUES (1,'/') + +BOB11 + + -- TODO: To be good, there should be type column + +-- dfgjhdfgdjkgk dfgdfg / +BOB12 + +UPDATE Timmy SET id = 'something something /' +UPDATE Timmy SET id = 'something something: /' + +ALTER TABLE Inv.something ADD + gagagag decimal(20, 12) NULL, + asdfasdf DECIMAL(20, 6) NULL, + didbibi decimal(20, 6) NULL, + yeppsasd decimal(20, 6) NULL, + uhuhhh datetime NULL, + slsald varchar(15) NULL, + uhasdf varchar(15) NULL, + daf_asdfasdf DECIMAL(20,6) NULL; +/ + +EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Daily job', + @step_id=1, + @cmdexec_success_code=0, + @on_success_action=3, + @on_success_step_id=0, + @on_fail_action=3, + @on_fail_step_id=0, + @retry_attempts=0, + @retry_interval=0, + @os_run_priority=0, @subsystem=N'PLSQL', + @command=N' +dml statements +/ +dml statements ' + +/ + +INSERT [dbo].[Foo] ([Bar]) VALUES (N'hello--world. +Thanks!') +INSERT [dbo].[Foo] ([Bar]) VALUES (N'/ speed racer, / speed racer, / speed racer /!!!!! ') + +/"; + + public static string PLSqlStatementScrubbed = @" +BOB1 +" + StatementSplitter.BatchTerminatorReplacementString + @" + +/* COMMENT */ +BOB2 +" + StatementSplitter.BatchTerminatorReplacementString + @" + +-- / + +BOB3 " + StatementSplitter.BatchTerminatorReplacementString + @" + +--`~!@#$%^&*()-_+=,.;:'""[]\/?<> / + +BOB5 + " + StatementSplitter.BatchTerminatorReplacementString + @" + +BOB6 +" + StatementSplitter.BatchTerminatorReplacementString + @" + +/* / */ + +BOB7 + +/* + +/ + +*/ + +BOB8 + +-- +" + StatementSplitter.BatchTerminatorReplacementString + @" + +BOB9 + +-- `~!@#$%^&*()-_+=,.;:'""[]\/?<> +" + StatementSplitter.BatchTerminatorReplacementString + @" + +BOB10/ + +CREATE TABLE PO/ +{} + +INSERT INTO PO/ (id,desc) VALUES (1,'/') + +BOB11 + + -- TODO: To be good, there should be type column + +-- dfgjhdfgdjkgk dfgdfg / +BOB12 + +UPDATE Timmy SET id = 'something something /' +UPDATE Timmy SET id = 'something something: /' + +ALTER TABLE Inv.something ADD + gagagag decimal(20, 12) NULL, + asdfasdf DECIMAL(20, 6) NULL, + didbibi decimal(20, 6) NULL, + yeppsasd decimal(20, 6) NULL, + uhuhhh datetime NULL, + slsald varchar(15) NULL, + uhasdf varchar(15) NULL, + daf_asdfasdf DECIMAL(20,6) NULL; +" + StatementSplitter.BatchTerminatorReplacementString + @" + +EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Daily job', + @step_id=1, + @cmdexec_success_code=0, + @on_success_action=3, + @on_success_step_id=0, + @on_fail_action=3, + @on_fail_step_id=0, + @retry_attempts=0, + @retry_interval=0, + @os_run_priority=0, @subsystem=N'PLSQL', + @command=N' +dml statements +/ +dml statements ' + +" + StatementSplitter.BatchTerminatorReplacementString + @" + +INSERT [dbo].[Foo] ([Bar]) VALUES (N'hello--world. +Thanks!') +INSERT [dbo].[Foo] ([Bar]) VALUES (N'/ speed racer, / speed racer, / speed racer /!!!!! ') + +" + StatementSplitter.BatchTerminatorReplacementString + @""; + + public static string plsql_statement = + @" +SQL1; +; +SQL2; +; +tmpSql := 'DROP SEQUENCE mutatieStockID'; +EXECUTE IMMEDIATE tmpSql; +; +BEGIN +INSERT into Table (columnname) values ("";""); +UPDATE Table set columnname="";""; +END; +"; + public static string plsql_statement_scrubbed = @" +SQL1; +" + StatementSplitter.BatchTerminatorReplacementString + @" +SQL2; +" + StatementSplitter.BatchTerminatorReplacementString + @" +tmpSql := 'DROP SEQUENCE mutatieStockID'; +EXECUTE IMMEDIATE tmpSql; +" + StatementSplitter.BatchTerminatorReplacementString + @" +BEGIN +INSERT into Table (columnname) values ("";""); +UPDATE Table set columnname="";""; +END; +"; + } +} diff --git a/grate.unittests/TestInfrastructure/SplitterContext.cs b/grate.unittests/TestInfrastructure/SqlServerSplitterContext.cs similarity index 98% rename from grate.unittests/TestInfrastructure/SplitterContext.cs rename to grate.unittests/TestInfrastructure/SqlServerSplitterContext.cs index 3a0acd47..b897ae25 100644 --- a/grate.unittests/TestInfrastructure/SplitterContext.cs +++ b/grate.unittests/TestInfrastructure/SqlServerSplitterContext.cs @@ -3,7 +3,7 @@ namespace grate.unittests.TestInfrastructure; -public static class SplitterContext +public static class SqlServerSplitterContext { public static class FullSplitter diff --git a/grate/Infrastructure/OracleSyntax.cs b/grate/Infrastructure/OracleSyntax.cs index 08347504..dbc1a99b 100644 --- a/grate/Infrastructure/OracleSyntax.cs +++ b/grate/Infrastructure/OracleSyntax.cs @@ -11,7 +11,7 @@ public string StatementSeparatorRegex const string strings = @"(?'[^']*')"; const string dashComments = @"(?--.*$)"; const string starComments = @"(?/\*[\S\s]*?\*/)"; - const string separator = @"(?^|\s)(?GO|/)(?\s|;|$)"; + const string separator = @"(?^|\s)(?/)(?\s|;|$)"; return strings + "|" + dashComments + "|" + starComments + "|" + separator; } }