question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed parsing CASE with includeWhitespace: true

See original GitHub issue

Thank you for this library! I noticed I get a null reference fault here:


namespace Tests
{
   public class ParseSelect
   {
        [Test]
        public void Parse_TypicalStoredProc()
        {
            const string sql = @"SELECT DISTINCT ISNULL((
                           CASE 1
                               WHEN 2
                                   THEN 2
                               ELSE 3
                               END
                           ), '') AS F
FROM FAMILY_LOAN AS FL";

            List<TSQLStatement> statements = TSQLStatementReader.ParseStatements(sql, 
              useQuotedIdentifiers: false, includeWhitespace: true);

        }
  }
}

stack trace

Error Message:
   System.NullReferenceException : Object reference not set to an instance of an object.
  Stack Trace:
     at TSQL.Expressions.Parsers.TSQLArgumentListParser.Parse(ITSQLTokenizer tokenizer) in /Users/chui.tey/toyapps/tsql-parser/TSQL_Parser/TSQL_Parser/Expressions/Parsers/TSQLArgumentListParser.cs:line 39
   at TSQL.Expressions.Parsers.TSQLValueExpressionParser.ParseNext(ITSQLTokenizer tokenizer) in /Users/chui.tey/toyapps/tsql-parser/TSQL_Parser/TSQL_Parser/Expressions/Parsers/TSQLValueExpressionParser.cs:line 286
   at TSQL.Expressions.Parsers.TSQLSelectExpressionParser.ParseNext(ITSQLTokenizer tokenizer) in /Users/chui.tey/toyapps/tsql-parser/TSQL_Parser/TSQL_Parser/Expressions/Parsers/TSQLSelectExpressionParser.cs:line 66
   at TSQL.Expressions.Parsers.TSQLSelectExpressionParser.Parse(ITSQLTokenizer tokenizer) in /Users/chui.tey/toyapps/tsql-parser/TSQL_Parser/TSQL_Parser/Expressions/Parsers/TSQLSelectExpressionParser.cs:line 15
   at TSQL.Elements.Parsers.TSQLSelectColumnParser.Parse(ITSQLTokenizer tokenizer) in /Users/chui.tey/toyapps/tsql-parser/TSQL_Parser/TSQL_Parser/Elements/Parsers/TSQLSelectColumnParser.cs:line 20
   at TSQL.Clauses.Parsers.TSQLSelectClauseParser.Parse(ITSQLTokenizer tokenizer) in /Users/chui.tey/toyapps/tsql-parser/TSQL_Parser/TSQL_Parser/Clauses/Parsers/TSQLSelectClauseParser.cs:line 173
   at TSQL.Statements.Parsers.TSQLSelectStatementParser.Parse() in /Users/chui.tey/toyapps/tsql-parser/TSQL_Parser/TSQL_Parser/Statements/Parsers/TSQLSelectStatementParser.cs:line 50
   at TSQL.Statements.Parsers.TSQLSelectStatementParser.TSQL.Statements.Parsers.ITSQLStatementParser.Parse() in /Users/chui.tey/toyapps/tsql-parser/TSQL_Parser/TSQL_Parser/Statements/Parsers/TSQLSelectStatementParser.cs:line 170
   at TSQL.TSQLStatementReader.MoveNext() in /Users/chui.tey/toyapps/tsql-parser/TSQL_Parser/TSQL_Parser/TSQLStatementReader.cs:line 89
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at TSQL.TSQLStatementReader.ParseStatements(String tsqlText, Boolean useQuotedIdentifiers, Boolean includeWhitespace) in /Users/chui.tey/toyapps/tsql-parser/TSQL_Parser/TSQL_Parser/TSQLStatementReader.cs:line 110
   at Tests.ParseLoanMarket.Parse_TypicalStoredProc() in /Users/chui.tey/toyapps/tsql-parser/TSQL_Parser/Tests/ParseLoanMarket.cs:line 61

Incidentally, would you accept a PR to convert this to netstandard20 classlib and netcore60 test project?

Issue Analytics

  • State:open
  • Created 8 months ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bruce-dunwiddiecommented, Feb 2, 2023

I’d be interested in helping towards your use case. I also find code generation and such interesting. Recreating OUTER APPLY subqueries with current day EF generation should be doable. Let me know if you get stuck.

0reactions
bruce-dunwiddiecommented, Feb 5, 2023

I’m not sure I follow how that would solve the problems. It’s not that I worry about the token handling themselves, it’s more about making sure the cursor stays where we expect it, while not dropping any tokens along the way, as they get passed through all the recursion levels.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I remove extra whitespace from strings when ...
Adding parameter skipinitialspace=True to read_table worked for me. So try: pd.read_table("data.csv", sep=r',', names=["Year", "Make", ...
Read more >
Consistent handling of whitespace in test data · Issue #3121
Consecutive spaces aren't collapsed. This only affects the pipe separated format. There are some real benefits compared to the old parser:.
Read more >
Dealing with extra white spaces while reading CSV in ...
Even though the white spaces are almost invisible, pile millions of them into the file and they will take some space. Other time...
Read more >
Why is trailing whitespace a big deal? [closed]
When I have string literals that span multiple lines, trailing whitespace can make the output string look incorrect when it's used. While not ......
Read more >
configparser — Configuration file parser — Python 3.11.4 ...
By default, section names are case sensitive but keys are not 1. Leading and trailing whitespace is removed from keys and values. Values...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found