JSqlParser
JSqlParser copied to clipboard
JSQLParserException: MySQL style single quoted string with line break and backslash escaped single quote
Test case to reproduce:
@Test
public void testInsertWithStringWithLineBreakAndEscapedSingleQuote() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(
"INSERT INTO `table_a` (`code`) VALUES ('\n" +
" print(\\'a string\\')\n" +
"')"
);
}
Not only select statement, but also in insert values
Greetings.
Your quotes are wrong, this will work:
INSERT INTO table_a ( code )
VALUES ( '\n print(''a string'')\n' )
;
Translates to
String test =
"INSERT INTO table_a (\n" +
" code )\n" +
"VALUES ( '\\n print(''a string'')\\n' )\n" +
";";
Though not recommended, it is supported and executable with MySQL.
Please retest with latest JSQLParser 4.6 since quoting has been improved.
INSERT INTO table_a ( code )
VALUES ( '\n print(\'a string\')\n' )
;
Parses fine now.
Closed, since no further question has been asked.