diff --git a/TSQL_Parser/TSQL_Parser/Expressions/Parsers/TSQLValueExpressionParser.cs b/TSQL_Parser/TSQL_Parser/Expressions/Parsers/TSQLValueExpressionParser.cs index 1c6929a..2be6776 100644 --- a/TSQL_Parser/TSQL_Parser/Expressions/Parsers/TSQLValueExpressionParser.cs +++ b/TSQL_Parser/TSQL_Parser/Expressions/Parsers/TSQLValueExpressionParser.cs @@ -19,7 +19,6 @@ public TSQLExpression Parse(ITSQLTokenizer tokenizer) if ( tokenizer.Current != null && - tokenizer.Current.Text != "*" && tokenizer.Current.Type.In( TSQLTokenType.Operator)) { @@ -111,6 +110,7 @@ public TSQLExpression ParseNext( group.InnerExpression = new TSQLValueExpressionParser().Parse( tokenizer); + group.Tokens.AddRange(group.InnerExpression.Tokens); if (tokenizer.Current.IsCharacter( @@ -293,7 +293,8 @@ public TSQLExpression ParseNext( #endregion } - else if (tokenizer.Current.Text == "*") + else if (tokenizer.Current.Text == "*" && + tokens.Last().IsCharacter(TSQLCharacters.Period)) { #region parse multi column reference @@ -309,18 +310,15 @@ public TSQLExpression ParseNext( .Where(t => !t.IsComment() && !t.IsWhitespace()) .ToList(); - if (columnReference.Count > 0) - { - // p.* will have the single token p in the final list + // p.* will have the single token p in the final list - // AdventureWorks..ErrorLog.* will have 4 tokens in the final list - // e.g. {AdventureWorks, ., ., ErrorLog} + // AdventureWorks..ErrorLog.* will have 4 tokens in the final list + // e.g. {AdventureWorks, ., ., ErrorLog} - multi.TableReference = columnReference - .GetRange(0, columnReference - .FindLastIndex(t => t.IsCharacter(TSQLCharacters.Period))) - .ToList(); - } + multi.TableReference = columnReference + .GetRange(0, columnReference + .FindLastIndex(t => t.IsCharacter(TSQLCharacters.Period))) + .ToList(); TSQLTokenParserHelper.ReadThroughAnyCommentsOrWhitespace( tokenizer, diff --git a/TSQL_Parser/TSQL_Parser/Properties/AssemblyInfo.cs b/TSQL_Parser/TSQL_Parser/Properties/AssemblyInfo.cs index 8027805..48c43df 100644 --- a/TSQL_Parser/TSQL_Parser/Properties/AssemblyInfo.cs +++ b/TSQL_Parser/TSQL_Parser/Properties/AssemblyInfo.cs @@ -32,7 +32,7 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.2.2.0")] -[assembly: AssemblyFileVersion("2.2.2.0")] +[assembly: AssemblyVersion("2.3.0.0")] +[assembly: AssemblyFileVersion("2.3.0.0")] [assembly: InternalsVisibleTo("Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100793625650b945744f8a2c57bc75da89cd4d2c551636aa180c3020b7a15b815c10e983e83c312eb02f131c6fcf18aaffd6c8d9af6c4353c91ca0e9206b0fb8fb7805fc07b510a47ff40705ae56977ae8893e2d247d166aa400926582840e8a5602df055762bc3479dd14c9621a77946b6e6b0a00a77204c78fb52c65121bd75ba")] \ No newline at end of file diff --git a/TSQL_Parser/TSQL_Parser/Push.bat b/TSQL_Parser/TSQL_Parser/Push.bat index 8bc9b1b..0a3c997 100644 --- a/TSQL_Parser/TSQL_Parser/Push.bat +++ b/TSQL_Parser/TSQL_Parser/Push.bat @@ -1,4 +1,4 @@ nuget SetApiKey %NUGET_KEY% -nuget push TSQL.Parser.2.2.2.snupkg -Source https://api.nuget.org/v3/index.json -nuget push TSQL.Parser.2.2.2.nupkg -Source https://api.nuget.org/v3/index.json +nuget push TSQL.Parser.2.3.0.snupkg -Source https://api.nuget.org/v3/index.json +nuget push TSQL.Parser.2.3.0.nupkg -Source https://api.nuget.org/v3/index.json pause \ No newline at end of file diff --git a/TSQL_Parser/TSQL_Parser/TSQL_Parser.nuspec b/TSQL_Parser/TSQL_Parser/TSQL_Parser.nuspec index 91eff84..7e132aa 100644 --- a/TSQL_Parser/TSQL_Parser/TSQL_Parser.nuspec +++ b/TSQL_Parser/TSQL_Parser/TSQL_Parser.nuspec @@ -2,7 +2,7 @@ TSQL.Parser - 2.2.2 + 2.3.0 TSQL.Parser Bruce Dunwiddie shriop @@ -10,7 +10,7 @@ https://github.com/bruce-dunwiddie/tsql-parser false Library for Parsing SQL Server T-SQL Scripts - Fixed parsing of CAST function arguments when data type specification includes parentheses. + Fixed handling of asterisks within SELECT, as both multiplication and multicolumn expression. Copyright © 2022 sql parser sql-server tsql diff --git a/TSQL_Parser/TSQL_Parser/TSQL_Parser_NetStandard.csproj b/TSQL_Parser/TSQL_Parser/TSQL_Parser_NetStandard.csproj index a11e502..d1328e9 100644 --- a/TSQL_Parser/TSQL_Parser/TSQL_Parser_NetStandard.csproj +++ b/TSQL_Parser/TSQL_Parser/TSQL_Parser_NetStandard.csproj @@ -4,9 +4,9 @@ netstandard2.0 TSQL_Parser TSQL_Parser - 2.2.2.0 - 2.2.2.0 - 2.2.2.0 + 2.3.0.0 + 2.3.0.0 + 2.3.0.0 Library for Parsing SQL Server TSQL Scripts Copyright © 2022 diff --git a/TSQL_Parser/Tests/Statements/SelectStatementTests.cs b/TSQL_Parser/Tests/Statements/SelectStatementTests.cs index b624218..a50f681 100644 --- a/TSQL_Parser/Tests/Statements/SelectStatementTests.cs +++ b/TSQL_Parser/Tests/Statements/SelectStatementTests.cs @@ -823,5 +823,26 @@ public void SelectStatement_CAST_argument_parsing_with_whitespace() Assert.AreEqual(456.321, argument.Expression.AsConstant.Literal.AsNumericLiteral.Value); Assert.AreEqual("VARCHAR(10)", argument.DataType); } + + [Test] + public void SelectStatement_ColumnAliasAsEquals() + { + // example from https://docs.microsoft.com/en-us/sql/t-sql/queries/select-examples-transact-sql?view=sql-server-ver16 + List statements = TSQLStatementReader.ParseStatements( + @"SELECT p.Name AS ProductName, + NonDiscountSales = (OrderQty * UnitPrice), + Discounts = ((OrderQty * UnitPrice) * UnitPriceDiscount) + FROM Production.Product AS p + INNER JOIN Sales.SalesOrderDetail AS sod + ON p.ProductID = sod.ProductID + ORDER BY ProductName DESC;", + includeWhitespace: false); + + Assert.AreEqual(1, statements.Count); + TSQLSelectStatement select = statements.Single().AsSelect; + Assert.AreEqual(3, select.Select.Columns.Count); + Assert.AreEqual("NonDiscountSales", select.Select.Columns[1].ColumnAlias.Name); + Assert.AreEqual("Discounts", select.Select.Columns[2].ColumnAlias.Name); + } } }