Skip to content

Commit

Permalink
Merge pull request #94 from bruce-dunwiddie/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
bruce-dunwiddie authored Jun 5, 2022
2 parents a7c7d87 + c99d643 commit bd2e361
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,39 @@ public TSQLExpression ParseNext(
}
}

return null;
// this is the fall through if none of the "returns" hit above

// will also hit if we parse a simple single column expression, e.g. "SELECT blah"

TSQLColumnExpression simpleColumn = new TSQLColumnExpression();

simpleColumn.Tokens.AddRange(tokens);

List<TSQLToken> simpleColumnReference = tokens
.Where(t =>
!t.IsComment() &&
!t.IsWhitespace() &&
!t.IsCharacter(TSQLCharacters.Semicolon))
.ToList();

if (simpleColumnReference.Count > 1)
{
// p.ProductID will have the single token p in the final list

// AdventureWorks..ErrorLog.ErrorLogID will have 4 tokens in the final list
// e.g. {AdventureWorks, ., ., ErrorLog}

simpleColumn.TableReference = simpleColumnReference
.GetRange(0, simpleColumnReference
.FindLastIndex(t => t.IsCharacter(TSQLCharacters.Period)))
.ToList();
}

simpleColumn.Column = simpleColumnReference
.Last()
.AsIdentifier;

return simpleColumn;
}
else
{
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.1.0.0")]
[assembly: AssemblyFileVersion("2.1.0.0")]
[assembly: AssemblyVersion("2.2.0.0")]
[assembly: AssemblyFileVersion("2.2.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.1.0.snupkg -Source https://api.nuget.org/v3/index.json
nuget push TSQL.Parser.2.1.0.nupkg -Source https://api.nuget.org/v3/index.json
nuget push TSQL.Parser.2.2.0.snupkg -Source https://api.nuget.org/v3/index.json
nuget push TSQL.Parser.2.2.0.nupkg -Source https://api.nuget.org/v3/index.json
pause
1 change: 0 additions & 1 deletion TSQL_Parser/TSQL_Parser/TSQLIdentifiers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ public struct TSQLIdentifiers
public static readonly TSQLIdentifiers COLUMNS_UPDATED = new TSQLIdentifiers("COLUMNS_UPDATED");
public static readonly TSQLIdentifiers EVENTDATA = new TSQLIdentifiers("EVENTDATA");
public static readonly TSQLIdentifiers TRIGGER_NESTLEVEL = new TSQLIdentifiers("TRIGGER_NESTLEVEL");
public static readonly TSQLIdentifiers UPDATE = new TSQLIdentifiers("UPDATE");

#pragma warning restore 1591

Expand Down
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.1.0</version>
<version>2.2.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 argument parsing for CAST function.</releaseNotes>
<releaseNotes>Fixed simple single column SELECT parsing.</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.1.0.0</Version>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
<FileVersion>2.1.0.0</FileVersion>
<Version>2.2.0.0</Version>
<AssemblyVersion>2.2.0.0</AssemblyVersion>
<FileVersion>2.2.0.0</FileVersion>
<Description>Library for Parsing SQL Server TSQL Scripts</Description>
<Copyright>Copyright © 2022</Copyright>
<Company />
Expand Down
48 changes: 48 additions & 0 deletions TSQL_Parser/Tests/Statements/SelectStatementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -744,5 +744,53 @@ public void SelectStatement_CASTMissingASRegression()
TSQLSelectStatement select = statements.Single().AsSelect;
Assert.AreEqual(14, select.Tokens.Count);
}

[Test]
public void SelectStatement_system_user_Regression()
{
// regression test for https://github.com/bruce-dunwiddie/tsql-parser/issues/93
List<TSQLStatement> statements = TSQLStatementReader.ParseStatements(
//@"SELECT system_user;",
@"SELECT system_user;",
includeWhitespace: false);

// System.NullReferenceException
// this shouldn't happen even if only because it encountered the end of the string

// system_user is a system property, not a function
// is it trying to parse arguments?

// should system properties be split out from system functions?
// what should each be named?

Assert.AreEqual(1, statements.Count);
TSQLSelectStatement select = statements.Single().AsSelect;
Assert.AreEqual(3, select.Tokens.Count);
Assert.AreEqual("system_user", select.Select.Columns[0].Expression.AsColumn.Column.Name);
}

[Test]
public void SelectStatement_system_user_Regression_without_semicolon()
{
// regression test for https://github.com/bruce-dunwiddie/tsql-parser/issues/93
List<TSQLStatement> statements = TSQLStatementReader.ParseStatements(
//@"SELECT system_user;",
@"SELECT system_user",
includeWhitespace: false);

// System.NullReferenceException
// this shouldn't happen even if only because it encountered the end of the string

// system_user is a system property, not a function
// is it trying to parse arguments?

// should system properties be split out from system functions?
// what should each be named?

Assert.AreEqual(1, statements.Count);
TSQLSelectStatement select = statements.Single().AsSelect;
Assert.AreEqual(2, select.Tokens.Count);
Assert.AreEqual("system_user", select.Select.Columns[0].Expression.AsColumn.Column.Name);
}
}
}

0 comments on commit bd2e361

Please sign in to comment.