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); }
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); }
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); }
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); }
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); }
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); }
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); }