Skip to content

JSqlParser cannot recognize \' #875

Closed

Description

@yanbeipang

Describe the bug
Got JSQLParserException when parsing the following SQLs:

To Reproduce
Cannot parse:
insert into standard_table(gmt_create, gmt_modified, config_name, standard_code) values (now(), now(), null, 'if
@fac.sql_type in
[ 'UPDATE','DELETE','INSERT','INSERT_SELECT']
then
@act.allow_submit
end
');

Will work:
insert into standard_table(gmt_create, gmt_modified, config_name, standard_code) values (now(), now(), null, 'if
@fac.sql_type in
[ "UPDATE","DELETE","INSERT","INSERT_SELECT"]
then
@act.allow_submit
end
');

Expected behavior
A clear and concise description of what you expected to happen.

System

  • Database you are using
    MySQL
  • Java Version
    Unimportant
  • JSqlParser version
    2.1

Activity

  1. changed the title [-]Cannot parse SQL with "log" as column name, \'UPDATE\' within value[/-] [+]Cannot parse SQL with "skip" as column name, \'UPDATE\' within value[/+] on Oct 21, 2019
  2. changed the title [-]Cannot parse SQL with "skip" as column name, \'UPDATE\' within value[/-] [+]Cannot parse SQL that contains \'UPDATE\' in column value[/+] on Oct 22, 2019
  3. changed the title [-]Cannot parse SQL that contains \'UPDATE\' in column value[/-] [+]JSqlParser cannot recognize \'[/+] on Oct 22, 2019
  4. added a commit that references this issue on Jan 16, 2023
    db8f68e
  5. manticore-projects commented on Jan 16, 2023

    @manticore-projects
    Contributor

    Greetings!

    You will need to escape the single Quotes ' inside your Character Literal either SQL:2016 compliant with '' or lenient with \' and backslashEscaping activated. Please note that the later depends on PR #1715.

    Example

            String sqlStr="insert into standard_table(gmt_create, gmt_modified, config_name, standard_code) values (now(), now(), null, 'if \n"
                          + "@fac.sql_type in \n"
                          + "[ ''UPDATE'', ''DELETE'', ''INSERT'', ''INSERT_SELECT''] \n"
                          + "then \n"
                          + "@act.allow_submit \n"
                          + "end \n"
                          + "')"
                          ;
            TestUtils.assertSqlCanBeParsedAndDeparsed(
                    sqlStr
                    , true
                    , parser -> parser.withBackslashEscapeCharacter(false)
            );
    
            sqlStr="insert into standard_table(gmt_create, gmt_modified, config_name, standard_code) values (now(), now(), null, 'if \n"
                          + "@fac.sql_type in \n"
                          + "[ \\'UPDATE\\', \\'DELETE\\', \\'INSERT\\', \\'INSERT_SELECT\\'] \n"
                          + "then \n"
                          + "@act.allow_submit \n"
                          + "end \n"
                          + "')"
                    ;
            TestUtils.assertSqlCanBeParsedAndDeparsed(
                    sqlStr
                    , true
                    , parser -> parser.withBackslashEscapeCharacter(true)
            );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions