mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
fix not support ALTER TABLE XXX ADD KEY xxx('xxx')
This commit is contained in:
@@ -20,6 +20,7 @@ import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLAlterTableAddIndex extends SQLObjectImpl implements SQLAlterTableItem {
|
||||
@@ -33,6 +34,8 @@ public class SQLAlterTableAddIndex extends SQLObjectImpl implements SQLAlterTabl
|
||||
private String type;
|
||||
|
||||
private String using;
|
||||
|
||||
private String keyOrIndex = Token.INDEX.name;
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
@@ -79,4 +82,11 @@ public class SQLAlterTableAddIndex extends SQLObjectImpl implements SQLAlterTabl
|
||||
this.using = using;
|
||||
}
|
||||
|
||||
public String getKeyOrIndex() {
|
||||
return keyOrIndex;
|
||||
}
|
||||
|
||||
public void setKeyOrIndex(String keyOrIndex) {
|
||||
this.keyOrIndex = keyOrIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2290,7 +2290,11 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
SQLAlterTableAddConstraint item = new SQLAlterTableAddConstraint(primaryKey);
|
||||
stmt.getItems().add(item);
|
||||
} else if (lexer.token() == Token.KEY) {
|
||||
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
|
||||
// throw new ParserException("TODO " + lexer.token() +
|
||||
// " " + lexer.stringVal());
|
||||
SQLAlterTableAddIndex item = parseAlterTableAddIndex();
|
||||
item.setParent(stmt);
|
||||
stmt.getItems().add(item);
|
||||
} else if (lexer.token() == Token.CONSTRAINT) {
|
||||
lexer.nextToken();
|
||||
SQLName constraintName = this.exprParser.name();
|
||||
|
||||
@@ -1688,10 +1688,20 @@ public class SQLStatementParser extends SQLParser {
|
||||
item.setUnique(true);
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.INDEX) {
|
||||
item.setKeyOrIndex(Token.INDEX.name);
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == Token.KEY) {
|
||||
item.setKeyOrIndex(Token.KEY.name);
|
||||
lexer.nextToken();
|
||||
}
|
||||
} else {
|
||||
accept(Token.INDEX);
|
||||
if (lexer.token() == Token.INDEX) {
|
||||
item.setKeyOrIndex(Token.INDEX.name);
|
||||
accept(Token.INDEX);
|
||||
} else if (lexer.token() == Token.KEY) {
|
||||
item.setKeyOrIndex(Token.KEY.name);
|
||||
accept(Token.KEY);
|
||||
}
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.LPAREN) {
|
||||
|
||||
@@ -1990,7 +1990,8 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print("UNIQUE ");
|
||||
}
|
||||
|
||||
print("INDEX ");
|
||||
print(x.getKeyOrIndex());
|
||||
print(" ");
|
||||
|
||||
if (x.getName() != null) {
|
||||
x.getName().accept(this);
|
||||
|
||||
Reference in New Issue
Block a user