Ejemplo n.º 1
0
 public void TestCommentFollowingGO()
 {
     string[] scripts = BatchSqlParser.SplitBatch("/*script1*/GO/*script2*/");
     Assert.AreEqual(2, scripts.Length);
     Assert.AreEqual("/*script1*/", scripts[0]);
     Assert.AreEqual("/*script2*/", scripts[1]);
 }
Ejemplo n.º 2
0
		public void CanParseQuotedCorrectly() {
			const string script = @"INSERT INTO #Indexes
		EXEC sp_helpindex 'dbo.subtext_URLs'";

			var scripts = BatchSqlParser.SplitBatch(script);
			Assert.AreEqual(script, scripts[0], "Script text should not be modified");
		}
Ejemplo n.º 3
0
 public void TestCommentPrecedingGO()
 {
     string[] scripts = BatchSqlParser.SplitBatch("/*script1*/GO--script2");
     Assert.AreEqual(2, scripts.Length);
     Assert.AreEqual("/*script1*/", scripts[0]);
     Assert.AreEqual("--script2", scripts[1]);
 }
Ejemplo n.º 4
0
        public void SemiColonDoesNotSplitScript()
        {
            const string script  = "CREATE PROC Blah AS SELECT FOO; SELECT Bar;";
            var          scripts = BatchSqlParser.SplitBatch(script);

            Assert.AreEqual(1, scripts.Length, "Expected no scripts since they would be empty.");
        }
Ejemplo n.º 5
0
		public void CanParseGoWithDashDashCommentAfter() {
			const string script = @"SELECT * FROM foo;
 GO --  Hello Phil
CREATE PROCEDURE dbo.Test AS SELECT * FROM foo";
			var scripts = BatchSqlParser.SplitBatch(script);
			Assert.AreEqual(2, scripts.Length);
		}
Ejemplo n.º 6
0
		public void CanParseCommentBeforeGoStatement() {
			const string script = @"SELECT FOO
/*TEST*/ GO
BAR";
			var scripts = BatchSqlParser.SplitBatch(script);
			Assert.AreEqual(2, scripts.Length);
		}
Ejemplo n.º 7
0
		public void CanParseDashDashCommentWithQuoteChar() {
			const string script = @"-- Add the Url column to the subtext_Log table if it doesn't exist
SELECT * FROM BLAH
GO
PRINT 'FOO'";
			var scripts = BatchSqlParser.SplitBatch(script);
			Assert.AreEqual(2, scripts.Length);
		}
Ejemplo n.º 8
0
		public void SlashStarCommentAfterGoThrowsException() {
			const string script = @"PRINT 'blah'
GO /* blah */";

			Assert.AreEqual(2, BatchSqlParser.SplitBatch(script).Length);
			//why should this throw an exception?
			//UnitTestHelper.AssertThrows<SqlParseException>(() => BatchSqlParser.SplitBatch(script));
		}
Ejemplo n.º 9
0
		public void CanParseCommentWithQuoteChar() {
			const string script = @"/* Add the Url column to the subtext_Log table if it doesn't exist */
		ADD [Url] VARCHAR(255) NULL
GO
				AND             COLUMN_NAME = 'BlogGroup') IS NULL";
			var scripts = BatchSqlParser.SplitBatch(script);
			Assert.AreEqual(2, scripts.Length);
		}
Ejemplo n.º 10
0
        public void CanParseSimpleScript()
        {
            var script  = "Test" + Environment.NewLine + "go";
            var scripts = BatchSqlParser.SplitBatch(script);

            Assert.AreEqual(1, scripts.Length);
            Assert.AreEqual("Test" + Environment.NewLine, scripts[0]);
        }
Ejemplo n.º 11
0
		public void CanParseLineEndingInDashDashComment() {
			const string script = @"SELECT * FROM BLAH -- Comment
GO
FOOBAR
GO";
			var scripts = BatchSqlParser.SplitBatch(script);
			Assert.AreEqual(2, scripts.Length);
		}
Ejemplo n.º 12
0
        public void CanParseSimpleScriptEndingInNewLine()
        {
            string script = "Test" + Environment.NewLine + "GO" + Environment.NewLine;

            string[] scripts = BatchSqlParser.SplitBatch(script);
            Assert.AreEqual(1, scripts.Length);
            Assert.AreEqual("Test" + Environment.NewLine, scripts[0]);
        }
Ejemplo n.º 13
0
        public void CanParseSuccessiveGoStatements()
        {
            const string script  = @"GO
GO";
            var          scripts = BatchSqlParser.SplitBatch(script);

            Assert.AreEqual(0, scripts.Length, "Expected no scripts since they would be empty.");
        }
Ejemplo n.º 14
0
		public void TestScriptWithGOTO() {
			var script = @"script 1
GO
script 2
GOTO <-- not a GO <-- niether is this
NOGO <-- also not a GO <-- still no
";
			var scripts = BatchSqlParser.SplitBatch(script);
			Assert.AreEqual(2, scripts.Length);
		}
Ejemplo n.º 15
0
		public void TestSplitGOInComment() {
			string[] scripts = null;
			scripts = BatchSqlParser.SplitBatch(@"
1:1
-- GO eff yourself
1:2
");
			//shoud be 1 script
			Assert.AreEqual(1, scripts.Length);
		}
Ejemplo n.º 16
0
		public void TestSplitGOInQuotes() {
			string[] scripts = null;
			scripts = BatchSqlParser.SplitBatch(@"
1:1 ' 
GO
' 1:2
");
			//should be 1 script
			Assert.AreEqual(1, scripts.Length);
		}
Ejemplo n.º 17
0
		public void TestSplitGONoEndLine() {
			string[] scripts = null;
			scripts = BatchSqlParser.SplitBatch(@"
1:1
1:2
GO");
			//should be 1 script with no 'GO'
			Assert.AreEqual(1, scripts.Length);
			Assert.IsFalse(scripts[0].Contains("GO"));
		}
Ejemplo n.º 18
0
		public void CanParseNestedComments() {
			const string script = @"/*
select 1
/* nested comment */
go
delete from users
-- */";
			var scripts = BatchSqlParser.SplitBatch(script);
			Assert.AreEqual(1, scripts.Length, "This contains a comment and no scripts.");
		}
Ejemplo n.º 19
0
        public void ParseScriptParsesCorrectly()
        {
            const string script  = @"SET QUOTED_IDENTIFIER OFF
-- Comment
Go
			   
SET ANSI_NULLS ON


GO

GO


SET ANSI_NULLS ON


CREATE TABLE [<username,varchar,dbo>].[blog_Gost] (
		[HostUserName] [nvarchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
		[Password] [nvarchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
		[Salt] [nvarchar] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
		[DateCreated] [datetime] NOT NULL
) ON [PRIMARY]
gO

";
            var          scripts = BatchSqlParser.SplitBatch(script);

            Assert.AreEqual(3, scripts.Length, "This should parse to three scripts.");
            //for (int i = 0; i < scripts.Length; i++) {
            //    Script sqlScript = scripts[i];
            //    Assert.IsFalse(sqlScript.ScriptText.StartsWith("GO"), "Script '" + i + "' failed had a GO statement");
            //}

            //string expectedThirdScriptBeginning = "SET ANSI_NULLS ON "
            //                                      + Environment.NewLine
            //                                      + Environment.NewLine
            //                                      + Environment.NewLine +
            //                                      "CREATE TABLE [<username,varchar,dbo>].[blog_Gost]";

            //Assert.AreEqual(expectedThirdScriptBeginning,
            //                scripts[2].OriginalScriptText.Substring(0, expectedThirdScriptBeginning.Length),
            //                "Script not parsed correctly");

            //scripts.TemplateParameters.SetValue("username", "haacked");

            //expectedThirdScriptBeginning = "SET ANSI_NULLS ON "
            //                               + Environment.NewLine
            //                               + Environment.NewLine
            //                               + Environment.NewLine + "CREATE TABLE [haacked].[blog_Gost]";

            //Assert.AreEqual(expectedThirdScriptBeginning,
            //                scripts[2].ScriptText.Substring(0, expectedThirdScriptBeginning.Length),
            //                "Script not parsed correctly");
        }
Ejemplo n.º 20
0
        public void IgnoresGoInsideQuotedIdentifier()
        {
            var scripts = BatchSqlParser.SplitBatch(@"
1:1
select 1 as ""GO""
SET ANSI_NULLS OFF
GO
");

            Assert.AreEqual(1, scripts.Length);
        }
Ejemplo n.º 21
0
        public void IgnoresGoInsideBrackets()
        {
            var scripts = BatchSqlParser.SplitBatch(@"
1:1
select 1 as [GO]
SET ANSI_NULLS OFF
GO
");

            Assert.AreEqual(1, scripts.Length);
        }
Ejemplo n.º 22
0
		public void MultiLineQuoteShouldNotBeSplitByGoKeyword() {
			var script = "PRINT '" + Environment.NewLine
			             + "GO" + Environment.NewLine
			             + "SELECT * FROM BLAH" + Environment.NewLine
			             + "GO" + Environment.NewLine
			             + "'";

			var scripts = BatchSqlParser.SplitBatch(script);

			Assert.AreEqual(script, scripts[0]);
			Assert.AreEqual(1, scripts.Length, "expected only one script");
		}
Ejemplo n.º 23
0
        public void IgnoresSlashStarInsideQuotedIdentifier()
        {
            var scripts = BatchSqlParser.SplitBatch(@"
select 1 as ""/*""
GO
SET ANSI_NULLS OFF
GO
");

            //should be 2 scripts
            Assert.AreEqual(2, scripts.Length);
        }
Ejemplo n.º 24
0
		public void TestSplitMultipleGOs() {
			string[] scripts = null;
			scripts = BatchSqlParser.SplitBatch(@"
1:1
GO
GO
GO
GO
2:1
");
			//should be 2 scripts
			Assert.AreEqual(2, scripts.Length);
		}
Ejemplo n.º 25
0
		public void MultiLineQuoteShouldNotIgnoreDoubleQuote() {
			var script = "PRINT '" + Environment.NewLine
			             + "''" + Environment.NewLine
			             + "GO" + Environment.NewLine
			             + "/*" + Environment.NewLine
			             + "GO"
			             + "'";

			var scripts = BatchSqlParser.SplitBatch(script);

			Assert.AreEqual(1, scripts.Length);
			Assert.AreEqual(script, scripts[0]);
		}
Ejemplo n.º 26
0
 public void TestLeadingTablsDashDash()
 {
     string[] scripts = null;
     scripts = BatchSqlParser.SplitBatch("\t\t\t\t-- comment");
     Assert.AreEqual("\t\t\t\t-- comment", scripts[0]);
 }
Ejemplo n.º 27
0
 public void TestLeadingTabsSlashStar()
 {
     string[] scripts = null;
     scripts = BatchSqlParser.SplitBatch("\t\t\t\t/* comment */");
     Assert.AreEqual("\t\t\t\t/* comment */", scripts[0]);
 }
Ejemplo n.º 28
0
 public void TestLeadingTabsSingleQuotes()
 {
     string[] scripts = null;
     scripts = BatchSqlParser.SplitBatch("\t\t\t\t'AddProjectToSourceSafe',");
     Assert.AreEqual("\t\t\t\t'AddProjectToSourceSafe',", scripts[0]);
 }
Ejemplo n.º 29
0
 public void TestLeadingTabsParameter()
 {
     string[] scripts = null;
     scripts = BatchSqlParser.SplitBatch("\t\t\t\t@param");
     Assert.AreEqual("\t\t\t\t@param", scripts[0]);
 }