JSqlParser: Error while parsing literals with backslash

Describe the bug Can’t properly parse the statement when

  1. Backslash is the last character of a literal;
  2. The literal is not the last value of a sequence.

To Reproduce Steps to reproduce the behavior:

  1. Example: CCJSqlParserUtil.parseStatements("""INSERT INTO "a"."b"("c", "d", "e") VALUES ('c c\', 'dd', 'ee\')""") (Kotlin)
  2. Exception:
net.sf.jsqlparser.JSQLParserException: Encountered unexpected token: "dd" <S_IDENTIFIER>
    at line 1, column 53.

Was expecting one of:

    "&"
    ")"
    ","
    "::"
    "<<"
    ">>"
    "COLLATE"
    "["
    "^"
    "|"
  1. Note that CCJSqlParserUtil.parseStatements("""INSERT INTO "a"."b"("c", "d", "e") VALUES ('c c', 'dd', 'ee\')""") won’t trigger the exception.

Expected behavior

The literals 'c c\' and 'dd'should be properly parsed.

System

  • Database: Oracle
  • Kotlin Version: 1.4.21-release-IJ2020.2-1
  • Java Version: 1.8
  • JSqlParser version: 4.0

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 35 (20 by maintainers)

Commits related to this issue

Most upvoted comments

Yes, this was exactly what I have suggested to the @wumpz. As kind of Pre-Processing and Post-Processing outside of the Parser itself.

On Mon, 2021-05-24 at 21:06 -0700, Xingcan Cui wrote:

Thanks for your insights! @manticore-projects To temporarily fix this problem, I replace all \ with \ before parsing the SQL and replace them back after the parsing process. Do you think this is a feasible workaround? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.