-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Escaping a backslash in an insert statement #827
Comments
The escaping is quite problematic. I will look into it. |
Maybe this is simply a copy and paste bug, but the behaviour for your example SQL is correct. If you use this within your Java file:
(two backslashes there) Then Java will put into your sql one backslash because of Javas escaping via backslash. Now JSqlParser supports escaping using backslashes as well. Therefore it finds First you should escape your backslash in Javas sense and then for JSqlParser. IMHO your statement should be:
(four backslashes) |
Thank you for your reply. Yes this is true but we have noticed that in some cases the parser works inconsistently. We created a table to illustrate this:
Our string:The raw, displayed string we would like to insert, without any Java (or other language)-specific escapes. Parser response:Whether the JSQLParser accepted our string in an INSERT or not. The insert string used for (standalone) testing was: *Special cases:The "special cases" mean that our String was either:
The first two are similar in these cases. Sometimes the responses were not what we expected (these are in parenthesis after the response). |
- 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.
Actual Behavior
I want to escape the backslash character in an insert statement at the end of a string value. To do this I use the following statement:
String insert = "INSERT INTO my_table (my_column_1, my_column_2) VALUES ('my_value_1\\', 'my_value_2')";
But when I want to parse it, it throws an exception:
CCJSqlParserUtil.parse(insert);
Caused by: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "my_value_2" <S_IDENTIFIER>
at line 1, column 73.
Was expecting one of:
It works fine in the following cases:
If the backslash is not at the end of the string, for example:
"INSERT INTO my_table (my_column_1, my_column_2) VALUES ('my_value\\_1', 'my_value_2')";
If I only want to insert a single column:
INSERT INTO my_table (my_column_1) VALUES ('my_value_1\\')
With SELECT, UPDATE, and MERGE instructions.
Specifications
The text was updated successfully, but these errors were encountered: