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

MySqlOutputVisitor中解析MySqlUnique出错 #946

Open
guimingyue opened this issue Sep 6, 2015 · 2 comments
Open

MySqlOutputVisitor中解析MySqlUnique出错 #946

guimingyue opened this issue Sep 6, 2015 · 2 comments

Comments

@guimingyue
Copy link

对于DDL语句CREATE TABLE task_list01 ( id bigint(20) NOT NULL AUTO_INCREMENT, did bigint(20) DEFAULT NULL COMMENT '医生ID', uid bigint(20) DEFAULT NULL COMMENT '诊断人ID', PRIMARY KEY (id), UNIQUE KEY task(uid,did) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8,首先通过Druid得到AST,然后再使用MySqlOutputVisitor将AST转换为ddl语句后UNIQUE KEY就变成了UNIQUE KEY task USING BTREE (uid,did)。对于这个转换得到的语句使用Druid再进行parse时就报错了。所以在MySqlOutputVisitor中,解析MySqlUnique时应该先打印索引的列名,再打印USING BTREE。也就是如下代码:

public boolean visit(MySqlUnique x) {
        if (x.isHasConstaint()) {
            print("CONSTRAINT ");
            if (x.getName() != null) {
                x.getName().accept(this);
                print(' ');
            }
        }

        print("UNIQUE");

        if (x.getIndexName() != null) {
            print(' ');
            x.getIndexName().accept(this);
        }

        print(" (");
        printAndAccept(x.getColumns(), ", ");
        print(")");

        if (x.getIndexType() != null) {
            print(" USING ");
            print(x.getIndexType());
        }

        return false;
    }
@wenshao
Copy link
Member

wenshao commented Sep 7, 2015

你来提交一个pull request吧,同时请带上testcase

@guimingyue
Copy link
Author

好的

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

No branches or pull requests

2 participants