JSqlParser icon indicating copy to clipboard operation
JSqlParser copied to clipboard

JSQLParserException: MySQL style single quoted string with line break and backslash escaped single quote

Open SylphiaWindy opened this issue 3 years ago • 2 comments

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

SylphiaWindy avatar May 23 '22 17:05 SylphiaWindy

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" +
              ";";

manticore-projects avatar May 23 '22 17:05 manticore-projects

Though not recommended, it is supported and executable with MySQL.

SylphiaWindy avatar May 23 '22 17:05 SylphiaWindy

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.

manticore-projects avatar Mar 02 '23 00:03 manticore-projects

Closed, since no further question has been asked.

manticore-projects avatar Mar 15 '23 00:03 manticore-projects