Skip to content
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

版本 3.5.1 or 3.5.3.1 Encountered unexpected token: "\n\n\n" <ST_SEMICOLON> #5345

Closed
zjmJavaByte opened this issue May 19, 2023 · 7 comments

Comments

@zjmJavaByte
Copy link

当前使用版本(必填,否则不予处理)

3.5.1

该问题是如何引起的?(确定最新版也有问题再提!!!)

使用自带的updateById方法,生成的sql如下UPDATE om_calendar_act_info SET action_calendar_id =?,act_time =?,sys_code =?,apply =?,act_name =?,begin_date =?,end_date =?,STATUS =?,is_commit =?,activity_details =?,images =?,materials =?,hr_bh =?,hr_name =?,create_time =?,update_user =?,update_time =? WHEREid =? AND del =0 ,一开始执行的时候会报错如下Encountered unexpected token: "apply" "APPLY",于是我提了一个issue ,但是我根据回复修改后,又出现如下问题Encountered unexpected token: "\n\n\n" <ST_SEMICOLON>。我将版本改为3.5.3.1后还是会出现该问题

重现步骤(如果有就写完整)

报错信息

  • Encountered unexpected token: "apply" "APPLY"
  • Encountered unexpected token: "\n\n\n" <ST_SEMICOLON>
@zjmJavaByte zjmJavaByte changed the title 版本 3.5.1 or 3.5.2.1 Encountered unexpected token: "\n\n\n" <ST_SEMICOLON> 版本 3.5.1 or 3.5.3.1 Encountered unexpected token: "\n\n\n" <ST_SEMICOLON> May 19, 2023
@manticore-projects
Copy link

Greetings!

Starting with JSQLParser 4.6, two empty lines .*\n\n\n terminate a statement.
(And I still will need a good argument why anyone would need 2 empty rows within one statement.)

select 1 from dual


select 2 from dual

gives 2 statements (without typing semicolons ;)

I will appreciate your consideration, since we receive reports about MyBatis Plus' auto-generated statements. Thank you.

@bubble2121
Copy link

同遇到这个问题,暂时换回4.4,把关键字换换,先用着

@nieqiurong
Copy link
Contributor

暂时可以通过配置去除一下,后面的版本解决.

mybatis-plus:
  configuration:
    shrink-whitespaces-in-sql: true

@qq592304796
Copy link

暂时可以通过配置去除一下,后面的版本解决.

mybatis-plus:
  configuration:
    shrink-whitespaces-in-sql: true

#5484
originalSql.replaceAll("(\\r?\\n){2,}", "$1")
使用StringTokenizer如果SQL中有注释什么的会有异常。

@krystal9003
Copy link

krystal9003 commented May 10, 2024

6559F7C7-C455-4AF7-B984-DDAC622F75C2
when mybatis-plus generate updateById method,it use "\n" to split every properties. so when the propertie is null, the dynamic sql will appear \n\n\n.So I suggeset modify the "\n" to "\n ".

@GuanWeiGit
Copy link

GuanWeiGit commented May 20, 2024

 二开 org.apache.ibatis.builder.SqlSourceBuilder.parse

//将连续的空行替换为一个空行
originalSql = originalSql.replaceAll("\n+", "\n");

`
public SqlSource parse(String originalSql, Class<?> parameterType, Map<String, Object> additionalParameters) {

    ParameterMappingTokenHandler handler = new ParameterMappingTokenHandler(configuration, parameterType, additionalParameters);
    GenericTokenParser parser = new GenericTokenParser("#{", "}", handler);
    String sql;
    //TODO 将连续的空行替换为一个空行
    originalSql = originalSql.replaceAll("\\n+", "\n");

    if (configuration.isShrinkWhitespacesInSql()) {
        sql = parser.parse(removeExtraWhitespaces(originalSql));
    } else {
        sql = parser.parse(originalSql);
    }
    return new StaticSqlSource(configuration, sql, handler.getParameterMappings());
}`

或者 (不推荐)
configuration:
shrink-whitespaces-in-sql: true

@manticore-projects
Copy link

Again, you can call CCJSqlParserUtil.sanitizeSingleSql( sqlStr) to clean your statements properly.
Details see here: JSQLParser/JSqlParser#1988 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants