[CONJ-785] jdbc insert query throws SQLSyntaxErrorException (unknown escape sequence) with 2.6.0 j-connector Created: 2020-04-26 Updated: 2020-06-22 Resolved: 2020-06-22 |
|
| Status: | Closed |
| Project: | MariaDB Connector/J |
| Component/s: | JDBC compatibility |
| Affects Version/s: | None |
| Fix Version/s: | 2.6.1 |
| Type: | Bug | Priority: | Major |
| Reporter: | Cabir Zounaidou | Assignee: | Diego Dupin |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
|
||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Description |
|
We recently upgraded to MariaDB Connector/J (version 2.6.0) from version 1.5.x and found that our insert statement is breaking with "SQLSyntaxErrorException: unknown escape sequence" exception. The same insert works fine if we use mysql client For example,
and if try to insert a string for "str_value" with trailing '\' character followed by some json string for "json_value", we see the following exception.
The main problem is with trailing '\' character in the first string and if the insert command got some column which can hold json string. If we remove the trailing '\' characters in the first string, the query passes. Please find here attached the test case with the above issue. Our project is blocked by issue. |
| Comments |
| Comment by T Tock [ 2020-04-27 ] | |||||
|
The fix for the bug is this (or something like it) in Utils.nativeSql():
Explanation: if we hit an escaped backslash character, we do not want it to still act like an escaping character for the next character visited. So that's why the code above sets 'lastChar' to '.' after we see two backslash characters in a row (the '.' character could be something different, so long as it's not something that has special meaning to the rest of the function). Note: the nativeSql() call adds a noticeable slowdown in the driver performance when processing large queries (as compared to previous versions of the driver). All it takes is a single '{' anywhere in the query to force the expensive character-by-character analysis and copy of the query. When inserting variable numbers of rows we have found the best performance is achieved by constructing our own escaped queries. Occasionally our queries are >1MB in size, which is slow to process in nativeSql(). These queries are noticeably slower to execute because of the client-side / driver overhead when we upgraded to the latest version. It would be great for performance-sensitive folks to have an option that disables the functionality provided by nativeSql(), allowing that expensive function to be bypassed. Please let me know if this suggestion should be filed as a separate ticket. | |||||
| Comment by T Tock [ 2020-06-22 ] | |||||
|
Thank you for the fix, as well as for providing a way to avoid escaping all together. Where can I see the changes that you've made? I looked here: Thanks! |