コード例 #1
0
        public void TestDifferentGoDelimiters()
        {
            string goDelimiter1 = "go";
            string goDelimiter2 = "gO";

            string statements =
                STATEMENT_1 + Environment.NewLine
                + STATEMENT_2 + Environment.NewLine
                + goDelimiter1 + Environment.NewLine
                + STATEMENT_3 + Environment.NewLine
                + goDelimiter1 + Environment.NewLine
                + STATEMENT_3 + Environment.NewLine
                + goDelimiter2 + Environment.NewLine
                + "-- " + STATEMENT_3;

            SqlStatementList list = new SqlStatementList(goDelimiter1, DelimiterStyle.Line);

            list.ParseSql(statements);

            Assert.AreEqual(4, list.Count);
            Assert.AreEqual(STATEMENT_1 + Environment.NewLine + STATEMENT_2 + Environment.NewLine, list[0], "Statement 1");
            Assert.AreEqual(STATEMENT_3 + Environment.NewLine, list[1], "Statement 3.1");
            Assert.AreEqual(STATEMENT_3 + Environment.NewLine, list[2], "Statement 3.2");
            Assert.AreEqual("-- " + STATEMENT_3 + Environment.NewLine, list[3], "Comment");
        }
コード例 #2
0
        public void TestIgnoreEmptyLines()
        {
            string statements = STATEMENT_1 + DELIMITER + "\n \n";

            SqlStatementList list = new SqlStatementList(DELIMITER, DelimiterStyle.Normal);

            list.ParseSql(statements);

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(STATEMENT_1 + Environment.NewLine, list[0]);
        }
コード例 #3
0
        public void TestGoSeparatorMustNotSplitGoto()
        {
            string goDelimiter = "go";

            string statements = STATEMENT_1 + Environment.NewLine + STATEMENT_GOTO + Environment.NewLine;

            SqlStatementList list = new SqlStatementList(goDelimiter, DelimiterStyle.Line);

            list.ParseSql(statements);

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(statements, list[0]);
        }
コード例 #4
0
        public void TestCommentStripping()
        {
            string statements = STATEMENT_1 + DELIMITER + "\n //" + STATEMENT_2
                                + DELIMITER + "   \n --" + STATEMENT_3
                                + DELIMITER + "\n" + STATEMENT_1;

            SqlStatementList list = new SqlStatementList(DELIMITER, DelimiterStyle.Normal);

            list.ParseSql(statements);

            Assert.AreEqual(2, list.Count);
            Assert.AreEqual(STATEMENT_1 + Environment.NewLine, list[0]);
            Assert.AreEqual(STATEMENT_1 + Environment.NewLine, list[1]);
        }
コード例 #5
0
        public void TestLoadFromString()
        {
            string statements = STATEMENT_1 + "\n  " + DELIMITER + STATEMENT_2
                                + DELIMITER + "   \n " + STATEMENT_3;

            SqlStatementList list = new SqlStatementList(DELIMITER, DelimiterStyle.Normal);

            list.ParseSql(statements);

            Assert.AreEqual(3, list.Count);
            Assert.AreEqual(STATEMENT_1 + Environment.NewLine, list[0]);
            Assert.AreEqual(STATEMENT_2 + Environment.NewLine, list[1]);
            Assert.AreEqual(STATEMENT_3 + Environment.NewLine, list[2]);
        }
コード例 #6
0
        public void TestKeepLineFormatting()
        {
            string goDelimiter = "go";

            string statements = "\t" +
                                STATEMENT_1 + Environment.NewLine
                                + "\t" + STATEMENT_2 + Environment.NewLine;

            SqlStatementList list = new SqlStatementList(goDelimiter, DelimiterStyle.Line);

            list.ParseSql(statements);

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(statements, list[0]);
        }
コード例 #7
0
        public void TestPropertyReplacement()
        {
            string sqlWithPropertyTags  = @"use ${dbName}";
            string expectedSqlStatement = @"use master";

            string goDelimiter = "go";

            string inputStatements = "\t" +
                                     sqlWithPropertyTags + Environment.NewLine
                                     + "\t" + sqlWithPropertyTags + Environment.NewLine;

            string expectedStatements = "\t" +
                                        expectedSqlStatement + Environment.NewLine
                                        + "\t" + expectedSqlStatement + Environment.NewLine;

            SqlStatementList list = new SqlStatementList(goDelimiter, DelimiterStyle.Line);

            string buildFile = null;

            try {
                // persist buildfile
                buildFile = CreateFileWithContents(ProjectXml);

                // create project for buildfile
                Project project = new Project(buildFile, Level.Info, 0);

                var callStack = typeof(Project).GetProperty("RootTargetCallStack", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(project) as TargetCallStack;
                list.Properties = new PropertyAccessor(project, callStack);
                list.Properties.Set("dbName", "master");

                list.ParseSql(inputStatements);

                Assert.AreEqual(1, list.Count);
                Assert.AreEqual(expectedStatements, list[0]);
            } finally {
                // make sure temp buildfile is deleted
                if (buildFile != null)
                {
                    File.Delete(buildFile);
                }
            }
        }
コード例 #8
0
ファイル: SqlTask.cs プロジェクト: divyang4481/ci-factory
        /// <summary>
        /// Executes the SQL Statements one by one.
        /// </summary>
        /// <param name="sqlHelper"></param>
        private void ExecuteStatements(SqlHelper sqlHelper)
        {
            SqlStatementList list = CreateStatementList();

            if (Source == null)
            {
                list.ParseSql(_embeddedSqlStatements);
            }
            else
            {
                list.ParseSqlFromFile(Source);
            }

            foreach (string statement in list)
            {
                // only write messages to the build log if the OutputWriter is not
                // writing to the build log too
                if (Output != null)
                {
                    Log(Level.Verbose, "SQL Statement:");
                    Log(Level.Verbose, statement);
                }

                if (this.Verbose)
                {
                    OutputWriter.WriteLine();
                    OutputWriter.WriteLine("SQL Statement:");
                    OutputWriter.WriteLine(statement);
                }

                IDataReader results = null;

                try {
                    results = sqlHelper.Execute(statement, CommandTimeout);
                } catch (Exception ex) {
                    Log(Level.Error, "SQL Error: " + ex.Message);
                    Log(Level.Error, "Statement: " + statement);
                } finally {
                    ProcessResults(results, OutputWriter);
                }
            }
        }
コード例 #9
0
        public void TestLineSpawningDelimiter()
        {
            string delimiter = "#";

            string statements =
                STATEMENT_1 + Environment.NewLine
                + STATEMENT_2 + delimiter + STATEMENT_3 + Environment.NewLine
                + delimiter + "ABC";

            SqlStatementList list = new SqlStatementList(delimiter, DelimiterStyle.Normal);

            list.ParseSql(statements);

            Assert.AreEqual(3, list.Count);
            Assert.AreEqual(STATEMENT_1 + Environment.NewLine + STATEMENT_2,
                            list[0], "Statement 1");
            Assert.AreEqual(STATEMENT_3 + Environment.NewLine, list[1],
                            "Statement 2");
            Assert.AreEqual("ABC" + Environment.NewLine, list[2], "Statement 3");
        }
コード例 #10
0
        public void TestPropertyReplacement()
        {
            string sqlWithPropertyTags  = @"use ${dbName}";
            string expectedSqlStatement = @"use master";

            string goDelimiter = "go";

            string inputStatements = "\t" +
                                     sqlWithPropertyTags + Environment.NewLine
                                     + "\t" + sqlWithPropertyTags + Environment.NewLine;

            string expectedStatements = "\t" +
                                        expectedSqlStatement + Environment.NewLine
                                        + "\t" + expectedSqlStatement + Environment.NewLine;

            SqlStatementList list = new SqlStatementList(goDelimiter, DelimiterStyle.Line);

            string buildFile = null;

            try {
                // persist buildfile
                buildFile = CreateFileWithContents(ProjectXml);

                // create project for buildfile
                Project project = new Project(buildFile, Level.Info, 0);

                list.Properties = new PropertyDictionary(project);
                list.Properties.Add("dbName", "master");

                list.ParseSql(inputStatements);

                Assert.AreEqual(1, list.Count);
                Assert.AreEqual(expectedStatements, list[0]);
            } finally {
                // make sure temp buildfile is deleted
                if (buildFile != null)
                {
                    File.Delete(buildFile);
                }
            }
        }