JSQLParser / JSqlParser

JSqlParser parses an SQL statement and translate it into a hierarchy of Java classes. The generated hierarchy can be navigated using the Visitor Pattern

Home Page:https://github.com/JSQLParser/JSqlParser/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] JSQLParser Version 4.6 and beyond failing to parse SQL with three or more line breaks in the statement

thebiguno opened this issue · comments

Failing SQL Feature:

  • Version 4.6 and beyond seems to fail to parse some statements with three or more newlines in them.
  • Example: SELECT\n\n\nFOO1\nFROM FOO can't be parsed in 4.6 and beyond, but it could in 4.5.

SQL Example:

  • Simplified Query Example, focusing on the failing feature
SELECT
  
 
FOO1
FROM FOO

If you take out one of the new lines, it works:

SELECT

FOO1
FROM FOO

The error happens with the extra newlines in many positions, not just in the select list. This is just one of the simplest queries that I found which reproduces the problem.

Software Information:

  • JSqlParser version 4.5 works, version 4.6 and beyond does not. I tested 4.6, 4.9, and the latest snapshot (commit b815601)

The test class that I am running is just two lines of code plus the surrounding boilerplate:

package ca.richer.phoebie;

import net.sf.jsqlparser.parser.CCJSqlParserUtil;

public class SQLParserTest {

	public static void main(String[] args) throws Exception {
		final String sql = "SELECT\n\n\n\nFOO1\nFROM FOO";
		CCJSqlParserUtil.parse(sql);
	}
}

We use JSqlParser to parse many reports prior to modification and execution, and many of them have extra whitespace like this.

Please see #1988
Duplicate #1988