Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<S_CHAR_LITERAL> wrongly matches the chars with ' #1172

Closed
ZhaoRuidong opened this issue Apr 22, 2021 · 2 comments · Fixed by #1715
Closed

<S_CHAR_LITERAL> wrongly matches the chars with ' #1172

ZhaoRuidong opened this issue Apr 22, 2021 · 2 comments · Fixed by #1715

Comments

@ZhaoRuidong
Copy link

ZhaoRuidong commented Apr 22, 2021

Describe the bug

To Reproduce
Steps to reproduce the behavior:

  1. Example SQL
    SELECT A ALIA1, CASE WHEN B LIKE 'ABC\_%' ESCAPE '\' THEN 'DEF' ELSE 'CCCC' END AS OBJ_SUB_TYPE FROM TABLE2

Expected behavior
<S_CHAR_LITERAL> should match the [ '\' ] rather than [ '' THEN ']

System

  • Database you are using Oracle
  • Java Version 1.8
  • JSqlParser version 4.0
@ZhaoRuidong
Copy link
Author

I'm confused to the explanation of ~["0"-"9","a"-"z","A"-"Z","'","-"] matches any single character that is not a digit. https://www.engr.mun.ca/~theo/JavaCC-Tutorial/javacc-tutorial.pdf mentioned in Chap 1.4.1

@wumpz
Copy link
Member

wumpz commented Apr 28, 2021

This is indeed an open problem of JSqlparser. Since we are supporting multiple databases the escaping of single quotes can be \' or ''. This leads unfortunately to this behavior.

Until now I was not able to produce a better regular expression. One solution would be to make this processing either way optional like for instance bracket parsing. Then only one way would be successful and then a correction would be easier.

I'm confused to the explanation of ~["0"-"9","a"-"z","A"-"Z","'","-"] matches any single character that is not a digit. https://www.engr.mun.ca/~theo/JavaCC-Tutorial/javacc-tutorial.pdf mentioned in Chap 1.4.1

Additionally, I don't see the connection between your second question to this issue.

manticore-projects added a commit to manticore-projects/JSqlParser that referenced this issue Jan 15, 2023
- Enables `\` as escape character in String Literals (beside SQL:2016 compliant `'`)
- Default is OFF (since its not SQL:2016 compliant)
- Activate per Parser Feature
- Fixes JSQLParser#1638
- Fixes JSQLParser#1209
- Fixes JSQLParser#1173
- Fixes JSQLParser#1172
- Fixes JSQLParser#832
- Fixes JSQLParser#827
- Fixes JSQLParser#578

BREAKING-CHANGE: Backslash Escaping needs to be activated explicitly or else Backslash won't work as Escape Character.
wumpz pushed a commit that referenced this issue Jan 20, 2023
* refactor: Merge REPLACE into UPSERT

fixes #1706

* feat: `DROP TEMPORARY TABLE ...`

fixes #1712

* build: PMD compliance

* ci: Merge master

* feat: Configurable backslash `\` escaping

- Enables `\` as escape character in String Literals (beside SQL:2016 compliant `'`)
- Default is OFF (since its not SQL:2016 compliant)
- Activate per Parser Feature
- Fixes #1638
- Fixes #1209
- Fixes #1173
- Fixes #1172
- Fixes #832
- Fixes #827
- Fixes #578

BREAKING-CHANGE: Backslash Escaping needs to be activated explicitly or else Backslash won't work as Escape Character.

* style: Checkstyle

* style: remove dead code

* style: PMD compliance

* style: Checkstyle, unused import

* feat: allow `S_CHAR_LITERAL` to break lines

- fixes #875
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants