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]);
        }
        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]);
        }
        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]);
        }
Esempio n. 4
0
        private SqlStatementList CreateStatementList()
        {
            SqlStatementList list = new SqlStatementList(Delimiter, DelimiterStyle);

            if (ExpandProperties) {
                list.Properties = Project.Properties;
            }
            return list;
        }
 /// <summary>
 /// Creates a new instance
 /// </summary>
 /// 
 public SqlStatementAdapter(SqlStatementList stmtList) {
     _list = stmtList;
 }
        public void TestGoLineBatch() {
            string goDelimiter = "go";

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

            SqlStatementList list = new SqlStatementList(goDelimiter, 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");
        }
        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]);
        }
        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);
                }
            }
        }
        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]);
        }
        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");
        }
Esempio n. 11
0
 /// <summary>
 /// Creates a new instance
 /// </summary>
 ///
 public SqlStatementAdapter(SqlStatementList stmtList)
 {
     _list = stmtList;
 }