improved mysql parser.

This commit is contained in:
wenshao
2018-02-24 17:41:47 +08:00
parent 30be97f0b0
commit 9d893f72f4
4 changed files with 69 additions and 13 deletions
@@ -3449,7 +3449,9 @@ public class MySqlStatementParser extends SQLStatementParser {
if (lexer.token() == Token.COLUMN) {
lexer.nextToken();
parseAlterTableAddColumn(stmt);
} else if (lexer.token() == Token.INDEX || lexer.identifierEquals("FULLTEXT")) {
} else if (lexer.token() == Token.INDEX
|| lexer.identifierEquals(FnvHash.Constants.FULLTEXT)
|| lexer.identifierEquals(FnvHash.Constants.SPATIAL)) {
SQLAlterTableAddIndex item = parseAlterTableAddIndex();
item.setParent(stmt);
stmt.addItem(item);
@@ -3539,10 +3541,6 @@ public class MySqlStatementParser extends SQLStatementParser {
}
stmt.addItem(item);
} else if (lexer.identifierEquals(FULLTEXT)) {
throw new ParserException("TODO " + lexer.info());
} else if (lexer.identifierEquals(SPATIAL)) {
throw new ParserException("TODO " + lexer.info());
} else {
parseAlterTableAddColumn(stmt);
}
@@ -2755,9 +2755,12 @@ public class SQLStatementParser extends SQLParser {
protected SQLAlterTableAddIndex parseAlterTableAddIndex() {
SQLAlterTableAddIndex item = new SQLAlterTableAddIndex();
if (lexer.identifierEquals("FULLTEXT")) {
if (lexer.identifierEquals(FnvHash.Constants.FULLTEXT)) {
lexer.nextToken();
item.setType("FULLTEXT");
} else if (lexer.identifierEquals(FnvHash.Constants.SPATIAL)) {
lexer.nextToken();
item.setType("SPATIAL");
}
if (lexer.token == Token.UNIQUE) {
@@ -3811,11 +3811,13 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
@Override
public boolean visit(SQLUnique x) {
if (x.getName() != null) {
SQLName name = x.getName();
if (name != null) {
print0(ucase ? "CONSTRAINT " : "constraint ");
x.getName().accept(this);
name.accept(this);
print(' ');
}
print0(ucase ? "UNIQUE (" : "unique (");
printAndAccept(x.getColumns(), ", ");
print(')');
@@ -3824,9 +3826,10 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
@Override
public boolean visit(SQLPrimaryKeyImpl x) {
if (x.getName() != null) {
SQLName name = x.getName();
if (name != null) {
print0(ucase ? "CONSTRAINT " : "constraint ");
x.getName().accept(this);
name.accept(this);
print(' ');
}
@@ -3839,7 +3842,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
print('(');
printAndAccept(x.getColumns(), ", ");
print(')');
return false;
}
@@ -3854,11 +3857,13 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
@Override
public boolean visit(SQLColumnReference x) {
if (x.getName() != null) {
SQLName name = x.getName();
if (name != null) {
print0(ucase ? "CONSTRAINT " : "constraint ");
x.getName().accept(this);
name.accept(this);
print(' ');
}
print0(ucase ? "REFERENCES " : "references ");
x.getTable().accept(this);
print0(" (");