Reputation: 168
I am using JSqlParser 3.0 and my query is SELECT * from [dev-testdb].dbo.EMPLOYEES
. I am trying to remove [] characters because JSqlParser 3.0 version is not supported for these characters.I guess 1.x does but I have to use 3.0.
After remove brackets, my query seems like SELECT * from dev-testdb.dbo.EMPLOYEES
.
I am debugging my project and on this command
final Statement statement = CCJSqlParserUtil.parse(sql);
I catch this exception
net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "-" "-"
at line 1, column 18.
How can I fix this 3 characters when I parse with JSqlParser?
Upvotes: 1
Views: 1732
Reputation: 9131
It is not an issue of JSqlParser but its evolution. :)
Bracketquotation was switched off by default, to support all kinds of array syntax, which uses in most cases square brackets as well. This change was introduced with JSqlParser 3.0.
The array parsing is the default behaviour. Square bracket quotation has to be enabled using a parser flag (CCJSqlParser.withSquareBracketQuotation).
Here is the discussion: https://github.com/JSQLParser/JSqlParser/issues/677.
To activate this bracket quotation again use something like:
CCJSqlParserUtil.parse("select * from [mytable]", parser -> parser.withSquareBracketQuotation(true));
The lambda expression is used to somehow modify the used parsers configuration.
Upvotes: 3