mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve parser ddl support
This commit is contained in:
@@ -284,11 +284,24 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
}
|
||||
|
||||
public SQLStatement parseCreate() {
|
||||
char markChar = lexer.current();
|
||||
int markBp = lexer.bp();
|
||||
|
||||
accept(Token.CREATE);
|
||||
|
||||
boolean replace = false;
|
||||
if (lexer.token() == Token.OR) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("REPLACE");
|
||||
replace = true;
|
||||
}
|
||||
|
||||
List<SQLCommentHint> hints = this.exprParser.parseHints();
|
||||
|
||||
if (lexer.token() == Token.TABLE || identifierEquals(TEMPORARY)) {
|
||||
if (replace) {
|
||||
lexer.reset(markBp, markChar, Token.CREATE);
|
||||
}
|
||||
MySqlCreateTableParser parser = new MySqlCreateTableParser(this.exprParser);
|
||||
MySqlCreateTableStatement stmt = parser.parseCrateTable(false);
|
||||
stmt.setHints(hints);
|
||||
@@ -296,19 +309,32 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.DATABASE) {
|
||||
if (replace) {
|
||||
lexer.reset(markBp, markChar, Token.CREATE);
|
||||
}
|
||||
return parseCreateDatabase();
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.UNIQUE || lexer.token() == Token.INDEX || identifierEquals(FULLTEXT)
|
||||
|| identifierEquals(SPATIAL)) {
|
||||
if (replace) {
|
||||
lexer.reset(markBp, markChar, Token.CREATE);
|
||||
}
|
||||
return parseCreateIndex();
|
||||
}
|
||||
|
||||
if (identifierEquals(USER)) {
|
||||
if (replace) {
|
||||
lexer.reset(markBp, markChar, Token.CREATE);
|
||||
}
|
||||
return parseCreateUser();
|
||||
}
|
||||
|
||||
|
||||
if (lexer.token() == Token.VIEW) {
|
||||
if (replace) {
|
||||
lexer.reset(markBp, markChar, Token.CREATE);
|
||||
}
|
||||
|
||||
return parseCreateView();
|
||||
}
|
||||
|
||||
@@ -1494,7 +1520,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
|
||||
if (lexer.token() == Token.VALUES || identifierEquals("VALUE")) {
|
||||
lexer.nextToken();
|
||||
|
||||
|
||||
parseValueClause(stmt.getValuesList(), 0);
|
||||
} else if (lexer.token() == Token.SELECT) {
|
||||
SQLQueryExpr queryExpr = (SQLQueryExpr) this.exprParser.expr();
|
||||
@@ -1871,7 +1897,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SQLInsertStatement.ValuesClause values = new SQLInsertStatement.ValuesClause(valueExprList);
|
||||
valueClauseList.add(values);
|
||||
} else {
|
||||
@@ -2222,11 +2248,11 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
if (identifierEquals("COLUMN")) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
|
||||
SQLAlterTableAlterColumn alterColumn = new SQLAlterTableAlterColumn();
|
||||
SQLColumnDefinition columnDef = this.exprParser.parseColumn();
|
||||
alterColumn.setColumn(columnDef);
|
||||
|
||||
|
||||
stmt.getItems().add(alterColumn);
|
||||
} else if (identifierEquals("CHANGE")) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -1078,6 +1078,7 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlDropViewStatement x) {
|
||||
setMode(x, Mode.Drop);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -129,6 +129,11 @@ public class SQLServerExprParser extends SQLExprParser {
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.PERCENT) {
|
||||
lexer.nextToken();
|
||||
top.setPercent(true);
|
||||
}
|
||||
|
||||
return top;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ public class SQLServerLexer extends Lexer {
|
||||
map.put("TOP", Token.TOP);
|
||||
map.put("USE", Token.USE);
|
||||
map.put("WITH", Token.WITH);
|
||||
map.put("PERCENT", Token.PERCENT);
|
||||
|
||||
DEFAULT_SQL_SERVER_KEYWORDS = new Keywords(map);
|
||||
}
|
||||
|
||||
+2
-4
@@ -76,9 +76,7 @@ public class SQLServerSelectParser extends SQLSelectParser {
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.TOP) {
|
||||
SQLServerTop top = new SQLServerTop();
|
||||
lexer.nextToken();
|
||||
top.setExpr(createExprParser().primary());
|
||||
SQLServerTop top = this.createExprParser().parseTop();
|
||||
queryBlock.setTop(top);
|
||||
}
|
||||
|
||||
@@ -101,7 +99,7 @@ public class SQLServerSelectParser extends SQLSelectParser {
|
||||
return queryRest(queryBlock);
|
||||
}
|
||||
|
||||
protected SQLExprParser createExprParser() {
|
||||
protected SQLServerExprParser createExprParser() {
|
||||
return new SQLServerExprParser(lexer);
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -96,6 +96,10 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
print(")");
|
||||
}
|
||||
|
||||
if (x.isPercent()) {
|
||||
print(" PERCENT");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user