mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser.
This commit is contained in:
+4
-3
@@ -63,15 +63,15 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
super(exprParser);
|
||||
}
|
||||
|
||||
public SQLCreateTableStatement parseCrateTable() {
|
||||
return parseCrateTable(true);
|
||||
public SQLCreateTableStatement parseCreateTable() {
|
||||
return parseCreateTable(true);
|
||||
}
|
||||
|
||||
public MySqlExprParser getExprParser() {
|
||||
return (MySqlExprParser) exprParser;
|
||||
}
|
||||
|
||||
public MySqlCreateTableStatement parseCrateTable(boolean acceptCreate) {
|
||||
public MySqlCreateTableStatement parseCreateTable(boolean acceptCreate) {
|
||||
MySqlCreateTableStatement stmt = new MySqlCreateTableStatement();
|
||||
if (acceptCreate) {
|
||||
if (lexer.hasComment() && lexer.isKeepComments()) {
|
||||
@@ -120,6 +120,7 @@ public class MySqlCreateTableParser extends SQLCreateTableParser {
|
||||
|| lexer.token() == Token.PRIMARY //
|
||||
|| lexer.token() == Token.UNIQUE) {
|
||||
SQLTableConstraint constraint = this.parseConstraint();
|
||||
constraint.setParent(stmt);
|
||||
stmt.getTableElementList().add(constraint);
|
||||
} else if (lexer.token() == (Token.INDEX)) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -712,7 +712,7 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
}
|
||||
|
||||
accept(Token.LPAREN);
|
||||
this.names(fk.getReferencingColumns());
|
||||
this.names(fk.getReferencingColumns(), fk);
|
||||
accept(Token.RPAREN);
|
||||
|
||||
accept(Token.REFERENCES);
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.sql.parser.*;
|
||||
import com.alibaba.druid.util.FnvHash;
|
||||
|
||||
public class MySqlLexer extends Lexer {
|
||||
public static SymbolTable quoteTable = new SymbolTable(8192);
|
||||
@@ -226,7 +227,8 @@ public class MySqlLexer extends Lexer {
|
||||
|
||||
final char first = ch;
|
||||
|
||||
if (ch == 'b' && charAt(pos + 1) == '\'') {
|
||||
if (ch == 'b'
|
||||
&& charAt(pos + 1) == '\'') {
|
||||
int i = 2;
|
||||
int mark = pos + 2;
|
||||
for (;;++i) {
|
||||
@@ -336,6 +338,7 @@ public class MySqlLexer extends Lexer {
|
||||
token = Token.IDENTIFIER;
|
||||
stringVal = SymbolTable.global.addSymbol(text, mark, bufPos, hash);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,7 +398,9 @@ public class MySqlLexer extends Lexer {
|
||||
stringVal = this.subString(mark + startHintSp, starIndex - startHintSp - mark);
|
||||
token = Token.HINT;
|
||||
} else {
|
||||
stringVal = this.subString(mark, starIndex + 2 - mark);
|
||||
if (!optimizedForParameterized) {
|
||||
stringVal = this.subString(mark, starIndex + 2 - mark);
|
||||
}
|
||||
token = Token.MULTI_LINE_COMMENT;
|
||||
commentCount++;
|
||||
if (keepComments) {
|
||||
|
||||
@@ -114,7 +114,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
|
||||
public SQLCreateTableStatement parseCreateTable() {
|
||||
MySqlCreateTableParser parser = new MySqlCreateTableParser(this.exprParser);
|
||||
return parser.parseCrateTable();
|
||||
return parser.parseCreateTable();
|
||||
}
|
||||
|
||||
public SQLStatement parseSelect() {
|
||||
@@ -230,7 +230,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
lexer.reset(markBp, markChar, Token.CREATE);
|
||||
}
|
||||
MySqlCreateTableParser parser = new MySqlCreateTableParser(this.exprParser);
|
||||
MySqlCreateTableStatement stmt = parser.parseCrateTable(false);
|
||||
MySqlCreateTableStatement stmt = parser.parseCreateTable(false);
|
||||
stmt.setHints(hints);
|
||||
|
||||
if (comments != null) {
|
||||
|
||||
@@ -200,13 +200,13 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
SQLOrderBy orderBy = x.getOrderBy();
|
||||
if (orderBy != null) {
|
||||
println();
|
||||
orderBy.accept(this);
|
||||
visit(orderBy);
|
||||
}
|
||||
|
||||
SQLLimit limit = x.getLimit();
|
||||
if (limit != null) {
|
||||
println();
|
||||
limit.accept(this);
|
||||
visit(limit);
|
||||
}
|
||||
|
||||
SQLName procedureName = x.getProcedureName();
|
||||
|
||||
+1
-3
@@ -1057,7 +1057,7 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
@Override
|
||||
public boolean visit(MysqlForeignKey x) {
|
||||
return super.visit(x);
|
||||
return super.visit((SQLForeignKeyImpl) x);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1310,6 +1310,4 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
public void endVisit(MySqlFlushStatement x) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+2
@@ -118,6 +118,7 @@ public class FromSubqueryResolver extends OracleASTVisitorAdapter {
|
||||
String entryName = entry.getAlias();
|
||||
|
||||
SQLCreateViewStatement entryStmt = new SQLCreateViewStatement();
|
||||
entryStmt.setOrReplace(true);
|
||||
entryStmt.setDbType(stmt.getDbType());
|
||||
|
||||
String entryViewName = visitor.generateSubViewName();
|
||||
@@ -136,6 +137,7 @@ public class FromSubqueryResolver extends OracleASTVisitorAdapter {
|
||||
String dbType = stmt.getDbType();
|
||||
for (int i = 0; i < targetList.size() - 1; ++i) {
|
||||
SQLCreateViewStatement targetStmt = (SQLCreateViewStatement) targetList.get(i);
|
||||
targetStmt.setOrReplace(true);
|
||||
targetStmt.setDbType(dbType);
|
||||
targetStmt.setAfterSemi(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user