Skip to content

Commit

Permalink
Merge pull request #116 from bruce-dunwiddie/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
bruce-dunwiddie authored Oct 24, 2022
2 parents b5f684e + b76cea9 commit 12d4497
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ public TSQLExpression ParseNext(
}
else if (tokenizer.Current.Type.In(
TSQLTokenType.Identifier,
TSQLTokenType.SystemIdentifier))
TSQLTokenType.SystemIdentifier,
// RIGHT is a keyword, but can be used as a function call
TSQLTokenType.Keyword))
{
// column, with or without alias, or with full explicit table name with up to 5 parts

Expand Down Expand Up @@ -258,8 +260,7 @@ public TSQLExpression ParseNext(
.ToList();

function.Function =
identityTokens[identityTokens.Count - 1]
.AsIdentifier;
identityTokens[identityTokens.Count - 1];

if (identityTokens.Count > 1)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override TSQLExpressionType Type

public List<TSQLToken> QualifiedPath { get; internal set; }

public TSQLIdentifier Function { get; internal set; }
public TSQLToken Function { get; internal set; }

public TSQLArgumentList Arguments { get; internal set; }
}
Expand Down
4 changes: 2 additions & 2 deletions TSQL_Parser/TSQL_Parser/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.5.0.0")]
[assembly: AssemblyFileVersion("2.5.0.0")]
[assembly: AssemblyVersion("2.6.0.0")]
[assembly: AssemblyFileVersion("2.6.0.0")]

[assembly: InternalsVisibleTo("Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100793625650b945744f8a2c57bc75da89cd4d2c551636aa180c3020b7a15b815c10e983e83c312eb02f131c6fcf18aaffd6c8d9af6c4353c91ca0e9206b0fb8fb7805fc07b510a47ff40705ae56977ae8893e2d247d166aa400926582840e8a5602df055762bc3479dd14c9621a77946b6e6b0a00a77204c78fb52c65121bd75ba")]
4 changes: 2 additions & 2 deletions TSQL_Parser/TSQL_Parser/Push.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
nuget SetApiKey %NUGET_KEY%
nuget push TSQL.Parser.2.5.0.snupkg -Source https://api.nuget.org/v3/index.json
nuget push TSQL.Parser.2.5.0.nupkg -Source https://api.nuget.org/v3/index.json
nuget push TSQL.Parser.2.6.0.nupkg -Source https://api.nuget.org/v3/index.json
nuget push TSQL.Parser.2.6.0.snupkg -Source https://api.nuget.org/v3/index.json
pause
4 changes: 2 additions & 2 deletions TSQL_Parser/TSQL_Parser/TSQL_Parser.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<package>
<metadata>
<id>TSQL.Parser</id>
<version>2.5.0</version>
<version>2.6.0</version>
<title>TSQL.Parser</title>
<authors>Bruce Dunwiddie</authors>
<owners>shriop</owners>
<license type="expression">Apache-2.0</license>
<projectUrl>https://github.com/bruce-dunwiddie/tsql-parser</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Library for Parsing SQL Server T-SQL Scripts</description>
<releaseNotes>Fixed handling of FOR XML in SELECT.</releaseNotes>
<releaseNotes>Fixed parsing of function names that overlap with reserved words.</releaseNotes>
<copyright>Copyright © 2022</copyright>
<tags>sql parser sql-server tsql</tags>
</metadata>
Expand Down
6 changes: 3 additions & 3 deletions TSQL_Parser/TSQL_Parser/TSQL_Parser_NetStandard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>TSQL_Parser</AssemblyName>
<RootNamespace>TSQL_Parser</RootNamespace>
<Version>2.5.0.0</Version>
<AssemblyVersion>2.5.0.0</AssemblyVersion>
<FileVersion>2.5.0.0</FileVersion>
<Version>2.6.0.0</Version>
<AssemblyVersion>2.6.0.0</AssemblyVersion>
<FileVersion>2.6.0.0</FileVersion>
<Description>Library for Parsing SQL Server TSQL Scripts</Description>
<Copyright>Copyright © 2022</Copyright>
<Company />
Expand Down
4 changes: 2 additions & 2 deletions TSQL_Parser/Tests/Clauses/SelectClauseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ ORDER BY

Assert.AreEqual("GroupNumber", column.ColumnAlias.Name);
Assert.AreEqual(TSQLExpressionType.Function, column.Expression.Type);
Assert.AreEqual("ROW_NUMBER", column.Expression.AsFunction.Function.Name);
Assert.AreEqual("ROW_NUMBER", column.Expression.AsFunction.Function.Text);
}
}

Expand Down Expand Up @@ -292,7 +292,7 @@ ORDER BY

TSQLFunctionExpression functionExpression = column.Expression.AsFunction;

Assert.AreEqual("Multiply", functionExpression.Function.Name);
Assert.AreEqual("Multiply", functionExpression.Function.Text);
Assert.AreEqual(3, functionExpression.QualifiedPath.Count);
Assert.AreEqual("Test", functionExpression.QualifiedPath[0].AsIdentifier.Name);
Assert.AreEqual(".", functionExpression.QualifiedPath[1].AsCharacter.Text);
Expand Down
32 changes: 30 additions & 2 deletions TSQL_Parser/Tests/Statements/SelectStatementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ public void SelectStatement_CountAlias()
.Columns
.Single();

Assert.AreEqual("COUNT", count.Expression.AsFunction.Function.Name);
Assert.AreEqual("COUNT", count.Expression.AsFunction.Function.Text);
Assert.AreEqual("count", count.ColumnAlias.Name);
}

Expand All @@ -730,7 +730,7 @@ public void SelectStatement_CountAliasWithWhitespace()
.Columns
.Single();

Assert.AreEqual("COUNT", count.Expression.AsFunction.Function.Name);
Assert.AreEqual("COUNT", count.Expression.AsFunction.Function.Text);
Assert.AreEqual("count", count.ColumnAlias.Name);
}

Expand Down Expand Up @@ -928,5 +928,33 @@ public void SelectStatement_Stuff()

Assert.AreEqual(6, innerSelect.For.Tokens.Count);
}

[Test]
public void SelectStatement_CoalesceWithInnerFunctions()
{
// regression test for https://github.com/bruce-dunwiddie/tsql-parser/discussions/114
List<TSQLStatement> statements = TSQLStatementReader.ParseStatements(
@"SELECT COALESCE(added_by, RIGHT(user, LEN(user)-5)) AS changed_by FROM my_table",
includeWhitespace: false);

Assert.AreEqual(1, statements.Count);
TSQLSelectStatement select = statements.Single().AsSelect;

Assert.AreEqual(21, select.Tokens.Count);

TSQLFunctionExpression functionExpression = select
.Select
.Columns[0]
.Expression
.AsFunction
.Arguments[1]
.AsFunction;

TSQLToken right = functionExpression
.Function;

Assert.AreEqual("RIGHT", right.Text);
Assert.IsNull(functionExpression.QualifiedPath);
}
}
}

0 comments on commit 12d4497

Please sign in to comment.