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

格式化MySQL无法保留注释 #1703

Closed
aichaoxy opened this issue Apr 26, 2017 · 2 comments
Closed

格式化MySQL无法保留注释 #1703

aichaoxy opened this issue Apr 26, 2017 · 2 comments
Milestone

Comments

@aichaoxy
Copy link

aichaoxy commented Apr 26, 2017

测试代码:

@Test
public void test() {

    String sqlWithLeadingComment = "/*0abcde*/select max(id) from base_request_log";

    printFormatted(sqlWithLeadingComment);


    String sqlWithEndingComment = "select max(id) from base_request_log/*0abcde*/";

    printFormatted(sqlWithEndingComment);


    String sqlWithIntermediateComment = "select max(id) from base_request_log  /* haha */ ignore index (i1) ";

    printFormatted(sqlWithIntermediateComment);

}

private void printFormatted(String sql) {
    System.out.println("======");
    // System.out.println(SQLUtils.formatMySql(sql));
    System.out.println(SQLUtils.formatMySql(sql));
}

输出:

======
SELECT MAX(id)
FROM base_request_log
======
SELECT MAX(id)
FROM base_request_log
======
SELECT MAX(id)
FROM base_request_log IGNORE INDEX (i1)

印象中旧版本的格式化实现,不会吞掉注释。

能否设置一个开关到FormatOption里面:是否保留注释 ?

@wenshao wenshao added this to the 1.0.30 milestone May 14, 2017
@wenshao
Copy link
Member

wenshao commented May 14, 2017

ODPS是支持保留注释的,并且做得比较完善。mysql部分支持了,只支持你所说的第一个场景。请使用新版本 https://github.com/alibaba/druid/releases/tag/1.0.30

@wenshao wenshao closed this as completed May 14, 2017
@aichaoxy
Copy link
Author

经测试已经可用,高铁给力!

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

2 participants