mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved mysql parser add_index support. for issue #1645
This commit is contained in:
@@ -2126,6 +2126,16 @@ public class SQLStatementParser extends SQLParser {
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
item.setName(this.exprParser.name());
|
||||
|
||||
if (JdbcConstants.MYSQL.equals(dbType)) {
|
||||
if (identifierEquals("USING")) {
|
||||
lexer.nextToken();
|
||||
String indexType = lexer.stringVal;
|
||||
item.setType(indexType);
|
||||
accept(Token.IDENTIFIER);
|
||||
}
|
||||
}
|
||||
|
||||
accept(Token.LPAREN);
|
||||
}
|
||||
|
||||
|
||||
@@ -2799,8 +2799,12 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableAddIndex x) {
|
||||
print0(ucase ? "ADD " : "add ");
|
||||
if (x.getType() != null) {
|
||||
print0(x.getType());
|
||||
String type = x.getType();
|
||||
|
||||
boolean mysql = JdbcConstants.MYSQL.equals(dbType);
|
||||
|
||||
if (type != null && !mysql) {
|
||||
print0(type);
|
||||
print(' ');
|
||||
}
|
||||
|
||||
@@ -2818,6 +2822,13 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
x.getName().accept(this);
|
||||
print(' ');
|
||||
}
|
||||
|
||||
if (type != null && mysql) {
|
||||
print0(ucase ? "USING " : "using ");
|
||||
print0(type);
|
||||
print(' ');
|
||||
}
|
||||
|
||||
print('(');
|
||||
printAndAccept(x.getItems(), ", ");
|
||||
print(')');
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.alibaba.druid.bvt.bug;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 23/03/2017.
|
||||
*/
|
||||
public class Issue1654 extends TestCase {
|
||||
public void test_for_issue() throws Exception {
|
||||
String sql = "ALTER TABLE db_manage.zcy_gpcatalog_node_t ADD INDEX index_code USING BTREE (code);";
|
||||
String formatedSql = SQLUtils.format(sql, JdbcConstants.MYSQL);
|
||||
assertEquals("ALTER TABLE db_manage.zcy_gpcatalog_node_t\n" +
|
||||
"\tADD INDEX index_code USING BTREE (code);", formatedSql);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user