示例#1
0
        public void SemiColonDoesNotSplitScript()
        {
            const string script  = "CREATE PROC Blah AS SELECT FOO; SELECT Bar;";
            var          scripts = new ScriptSplitter(script);

            Assert.AreEqual(1, scripts.Count(), "Expected no scripts since they would be empty.");
        }
示例#2
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

";
            List <string> scripts = new ScriptSplitter(script).ToList();

            Assert.AreEqual(3, scripts.Count(), "This should parse to three scripts.");


            for (int i = 0; i < scripts.Count(); i++)
            {
                string sqlScript = scripts[i];
                Assert.IsFalse(sqlScript.StartsWith("GO"), "Script '" + i + "' failed had a GO statement");
            }

            string expectedThirdScriptBeginning = @"SET ANSI_NULLS ON 


CREATE TABLE [<username,varchar,dbo>].[blog_Gost]";

            Assert.AreEqual(expectedThirdScriptBeginning,
                            scripts[2].Substring(0, expectedThirdScriptBeginning.Length),
                            "Script not parsed correctly");
        }
示例#3
0
        public void CanParseSimpleScriptEndingInNewLine()
        {
            string        script  = "Test" + Environment.NewLine + "GO" + Environment.NewLine;
            List <string> scripts = new ScriptSplitter(script).ToList();

            Assert.AreEqual(1, scripts.Count());
            Assert.AreEqual("Test", scripts.First());
        }
 public void CanParseCommentBeforeGoStatement()
 {
     const string script = @"SELECT FOO
     /*TEST*/ GO
     BAR";
     var scripts = new ScriptSplitter(script);
     Assert.AreEqual(2, scripts.Count());
 }
示例#5
0
        public void CanParseSuccessiveGoStatements()
        {
            const string script  = @"GO
GO";
            var          scripts = new ScriptSplitter(script);

            Assert.AreEqual(0, scripts.Count(), "Expected no scripts since they would be empty.");
        }
示例#6
0
        public void CanParseCommentBeforeGoStatement()
        {
            const string script  = @"SELECT FOO
/*TEST*/ GO
BAR";
            var          scripts = new ScriptSplitter(script);

            Assert.AreEqual(2, scripts.Count());
        }
示例#7
0
        public void CanParseLineEndingInDashDashComment()
        {
            const string script  = @"SELECT * FROM BLAH -- Comment
GO
FOOBAR
GO";
            var          scripts = new ScriptSplitter(script);

            Assert.AreEqual(2, scripts.Count());
        }
 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 = new ScriptSplitter(script);
     Assert.AreEqual(2, scripts.Count());
 }
示例#9
0
        public void CanParseGoWithDashDashCommentAfter()
        {
            const string script =
                @"SELECT * FROM foo;
 GO --  Hello Phil
CREATE PROCEDURE dbo.Test AS SELECT * FROM foo";
            var scripts = new ScriptSplitter(script);

            Assert.AreEqual(2, scripts.Count());
        }
 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 = new ScriptSplitter(script);
     Assert.AreEqual(2, scripts.Count());
 }
示例#11
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 = new ScriptSplitter(script);

            Assert.AreEqual(2, scripts.Count());
        }
示例#12
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 = new ScriptSplitter(script);

            Assert.AreEqual(2, scripts.Count());
        }
示例#13
0
        public void CanParseNestedComments()
        {
            const string script  = @"/*
select 1
/* nested comment */
go
delete from users
-- */";
            var          scripts = new ScriptSplitter(script);

            Assert.AreEqual(1, scripts.Count(), "This contains a comment and no scripts.");
        }
示例#14
0
        public void MultiLineQuoteShouldNotBeSplitByGoKeyword()
        {
            string script = "PRINT '" + Environment.NewLine
                            + "GO" + Environment.NewLine
                            + "SELECT * FROM BLAH" + Environment.NewLine
                            + "GO" + Environment.NewLine
                            + "'";

            var scripts = new ScriptSplitter(script);

            Assert.AreEqual(script, scripts.First());
            Assert.AreEqual(1, scripts.Count(), "expected only one script");
        }
示例#15
0
        public void MultiLineQuoteShouldNotIgnoreDoubleQuote()
        {
            string script = "PRINT '" + Environment.NewLine
                            + "''" + Environment.NewLine
                            + "GO" + Environment.NewLine
                            + "/*" + Environment.NewLine
                            + "GO"
                            + "'";

            var scripts = new ScriptSplitter(script);

            Assert.AreEqual(1, scripts.Count());
            Assert.AreEqual(script, scripts.First());
        }
 public void SemiColonDoesNotSplitScript()
 {
     const string script = "CREATE PROC Blah AS SELECT FOO; SELECT Bar;";
     var scripts = new ScriptSplitter(script);
     Assert.AreEqual(1, scripts.Count(), "Expected no scripts since they would be empty.");
 }
        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

            ";
            List<string> scripts = new ScriptSplitter(script).ToList();
            Assert.AreEqual(3, scripts.Count(), "This should parse to three scripts.");

            for (int i = 0; i < scripts.Count(); i++)
            {
                string sqlScript = scripts[i];
                Assert.IsFalse(sqlScript.StartsWith("GO"), "Script '" + i + "' failed had a GO statement");
            }

            string expectedThirdScriptBeginning = @"SET ANSI_NULLS ON

            CREATE TABLE [<username,varchar,dbo>].[blog_Gost]";

            Assert.AreEqual(expectedThirdScriptBeginning,
                            scripts[2].Substring(0, expectedThirdScriptBeginning.Length),
                            "Script not parsed correctly");
        }
        public void MultiLineQuoteShouldNotIgnoreDoubleQuote()
        {
            string script = "PRINT '" + Environment.NewLine
                            + "''" + Environment.NewLine
                            + "GO" + Environment.NewLine
                            + "/*" + Environment.NewLine
                            + "GO"
                            + "'";

            var scripts = new ScriptSplitter(script);

            Assert.AreEqual(1, scripts.Count());
            Assert.AreEqual(script, scripts.First());
        }
        public void MultiLineQuoteShouldNotBeSplitByGoKeyword()
        {
            string script = "PRINT '" + Environment.NewLine
                            + "GO" + Environment.NewLine
                            + "SELECT * FROM BLAH" + Environment.NewLine
                            + "GO" + Environment.NewLine
                            + "'";

            var scripts = new ScriptSplitter(script);

            Assert.AreEqual(script, scripts.First());
            Assert.AreEqual(1, scripts.Count(), "expected only one script");
        }
 public void CanParseSuccessiveGoStatements()
 {
     const string script = @"GO
     GO";
     var scripts = new ScriptSplitter(script);
     Assert.AreEqual(0, scripts.Count(), "Expected no scripts since they would be empty.");
 }
 public void CanParseSimpleScriptEndingInNewLine()
 {
     string script = "Test" + Environment.NewLine + "GO" + Environment.NewLine;
     List<string> scripts = new ScriptSplitter(script).ToList();
     Assert.AreEqual(1, scripts.Count());
     Assert.AreEqual("Test", scripts.First());
 }
 public void CanParseGoWithDashDashCommentAfter()
 {
     const string script =
         @"SELECT * FROM foo;
      GO --  Hello Phil
     CREATE PROCEDURE dbo.Test AS SELECT * FROM foo";
     var scripts = new ScriptSplitter(script);
     Assert.AreEqual(2, scripts.Count());
 }
 public void CanParseLineEndingInDashDashComment()
 {
     const string script = @"SELECT * FROM BLAH -- Comment
     GO
     FOOBAR
     GO";
     var scripts = new ScriptSplitter(script);
     Assert.AreEqual(2, scripts.Count());
 }
 public void CanParseNestedComments()
 {
     const string script = @"/*
     select 1
     /* nested comment */
     go
     delete from users
     -- */";
     var scripts = new ScriptSplitter(script);
     Assert.AreEqual(1, scripts.Count(), "This contains a comment and no scripts.");
 }