示例#1
0
        private List <string> ParseColumnNamesFromQuery()
        {
            var result = SqlParser.ParseColumnNames(QB != string.Empty ? SqlForRead.Replace(QB, "").Replace(QE, "") : SqlForRead);

            if (TypeInfo.IsArray && result?.Count == 0)
            {
                throw new ETLBoxException("Could not parse column names from Sql Query! Please pass a valid TableDefinition to the " +
                                          " property SourceTableDefinition with at least a name for each column that you want to use in the source."
                                          );
            }
            return(result);
        }
示例#2
0
        public void SqlSelectStart()
        {
            //Arrange
            List <string> expected = new List <string>()
            {
            };
            string sql = $@"SELECT * FROM Table";

            //Act
            var actual = SqlParser.ParseColumnNames(sql);

            //Assert
            Assert.Equal(expected, actual);
        }
示例#3
0
        public void SqlOneColumn()
        {
            //Arrange
            List <string> expected = new List <string>()
            {
                "Col1"
            };
            string sql = $@"SELECT Col1";

            //Act
            var actual = SqlParser.ParseColumnNames(sql);

            //Assert
            Assert.Equal(expected, actual);
        }
示例#4
0
        public void SqlSimple()
        {
            //Arrange
            List <string> expected = new List <string>()
            {
                "Col1", "Col2"
            };
            string sql = $@"SELECT Col1, Col2 FROM Table";

            //Act
            var actual = SqlParser.ParseColumnNames(sql);

            //Assert
            Assert.Equal(expected, actual);
        }
示例#5
0
        public void SqlWithSchemaOneColumn()
        {
            //Arrange
            List <string> expected = new List <string>()
            {
                "Col1"
            };
            string sql = $@"SELECT sou.Col1 FROM table AS sou";

            //Act
            var actual = SqlParser.ParseColumnNames(sql);

            //Assert
            Assert.Equal(expected, actual);
        }
示例#6
0
        public void SqlWithSeveralFunctions()
        {
            //Arrange
            List <string> expected = new List <string>()
            {
                "Col1", "Col2"
            };
            string sql = $@"SELECT CONCAT('','Test',ISNULL(Col1,''), GETDATE()) AS Col1, 
( CONVERT(INT, Col2) * 5) Col2 
FROM Table";

            //Act
            var actual = SqlParser.ParseColumnNames(sql);

            //Assert
            Assert.Equal(expected, actual);
        }
示例#7
0
        public void SqlWithFunction()
        {
            //Arrange
            List <string> expected = new List <string>()
            {
                "Col1", "Col2"
            };
            string sql = $@"SELECT CASE WHEN ISNULL(Col1,'') IS NOT NULL THEN Col1 ELSE Col1 END AS Col1, 
Col2 
FROM Table";

            //Act
            var actual = SqlParser.ParseColumnNames(sql);

            //Assert
            Assert.Equal(expected, actual);
        }