mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor sql parser.
This commit is contained in:
@@ -17,12 +17,15 @@ package com.alibaba.druid.sql.dialect.mysql.ast.expr;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
import com.alibaba.druid.util.FNVUtils;
|
||||
|
||||
public class MySqlUserName extends MySqlExprImpl implements SQLName, Cloneable {
|
||||
|
||||
private String userName;
|
||||
private String host;
|
||||
|
||||
protected transient long userName_hash;
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
@@ -59,4 +62,29 @@ public class MySqlUserName extends MySqlExprImpl implements SQLName, Cloneable {
|
||||
x.host = host;
|
||||
return x;
|
||||
}
|
||||
|
||||
public long name_hash_lower() {
|
||||
if (userName_hash == 0
|
||||
&& userName != null) {
|
||||
final int len = userName.length();
|
||||
|
||||
boolean quote = false;
|
||||
|
||||
String name = this.userName;
|
||||
if (len > 2) {
|
||||
char c0 = name.charAt(0);
|
||||
char c1 = name.charAt(len - 1);
|
||||
if (c0 == c1
|
||||
&& (c0 == '`' || c1 == '"')) {
|
||||
quote = true;
|
||||
}
|
||||
}
|
||||
if (quote) {
|
||||
userName_hash = FNVUtils.fnv_64_lower(name, 1, len -1);
|
||||
} else {
|
||||
userName_hash = FNVUtils.fnv_64_lower(name);
|
||||
}
|
||||
}
|
||||
return userName_hash;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.Map;
|
||||
import com.alibaba.druid.sql.parser.*;
|
||||
|
||||
public class MySqlLexer extends Lexer {
|
||||
public static SymbolTable quoteTable = new SymbolTable(8192);
|
||||
|
||||
public final static Keywords DEFAULT_MYSQL_KEYWORDS;
|
||||
|
||||
@@ -251,20 +252,30 @@ public class MySqlLexer extends Lexer {
|
||||
bufPos = 1;
|
||||
char ch;
|
||||
|
||||
int quoteIndex = text.indexOf('`', pos + 1);
|
||||
int startPos = pos + 1;
|
||||
int quoteIndex = text.indexOf('`', startPos);
|
||||
if (quoteIndex == -1) {
|
||||
throw new ParserException("illegal identifier. " + info());
|
||||
}
|
||||
|
||||
hash_lower = 0xcbf29ce484222325L;
|
||||
hash = 0xcbf29ce484222325L;
|
||||
|
||||
for (int i = startPos; i < quoteIndex; ++i) {
|
||||
ch = text.charAt(i);
|
||||
|
||||
hash_lower ^= ((ch >= 'A' && ch <= 'Z') ? (ch + 32) : ch);
|
||||
hash_lower *= 0x100000001b3L;
|
||||
|
||||
hash ^= ch;
|
||||
hash *= 0x100000001b3L;
|
||||
}
|
||||
|
||||
stringVal = quoteTable.addSymbol(text, pos, quoteIndex + 1 - pos, hash);
|
||||
//stringVal = text.substring(mark, pos);
|
||||
pos = quoteIndex + 1;
|
||||
this.ch = charAt(pos);
|
||||
stringVal = text.substring(mark, pos);
|
||||
Token tok = keywods.getKeyword(stringVal);
|
||||
if (tok != null) {
|
||||
token = tok;
|
||||
} else {
|
||||
token = Token.IDENTIFIER;
|
||||
}
|
||||
token = Token.IDENTIFIER;
|
||||
} else {
|
||||
final boolean firstFlag = isFirstIdentifierChar(first);
|
||||
if (!firstFlag) {
|
||||
|
||||
@@ -171,7 +171,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
if (into != null) {
|
||||
println();
|
||||
print0(ucase ? "INTO " : "into ");
|
||||
into.accept(this);
|
||||
printTableSource(into);
|
||||
}
|
||||
|
||||
SQLTableSource from = x.getFrom();
|
||||
@@ -479,10 +479,10 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
}
|
||||
|
||||
if (x.getSelect() != null) {
|
||||
incrementIndent();
|
||||
this.indentCount++;
|
||||
println();
|
||||
x.getSelect().accept(this);
|
||||
decrementIndent();
|
||||
this.indentCount--;
|
||||
}
|
||||
|
||||
for (SQLCommentHint hint : x.getOptionHints()) {
|
||||
@@ -580,7 +580,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
if (this.parameterized) {
|
||||
this.appender.append('?');
|
||||
incrementReplaceCunt();
|
||||
if (this instanceof ExportParameterVisitor || this.parameters != null) {
|
||||
if (this.parameters != null) {
|
||||
ExportParameterVisitorUtils.exportParameter(this.parameters, x);
|
||||
}
|
||||
return false;
|
||||
@@ -819,14 +819,16 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
x.getUsing().accept(this);
|
||||
}
|
||||
|
||||
if (x.getWhere() != null) {
|
||||
SQLExpr where = x.getWhere();
|
||||
if (where != null) {
|
||||
println();
|
||||
incrementIndent();
|
||||
this.indentCount++;
|
||||
print0(ucase ? "WHERE " : "where ");
|
||||
x.getWhere().accept(this);
|
||||
decrementIndent();
|
||||
printExpr(where);
|
||||
this.indentCount--;
|
||||
}
|
||||
|
||||
|
||||
if (x.getOrderBy() != null) {
|
||||
println();
|
||||
x.getOrderBy().accept(this);
|
||||
@@ -880,7 +882,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
List<SQLExpr> columns = x.getColumns();
|
||||
if (columns.size() > 0) {
|
||||
incrementIndent();
|
||||
this.indentCount++;
|
||||
print0(" (");
|
||||
for (int i = 0, size = columns.size(); i < size; ++i) {
|
||||
if (i != 0) {
|
||||
@@ -890,16 +892,15 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print0(", ");
|
||||
}
|
||||
|
||||
SQLExpr columnn = columns.get(i);
|
||||
if (columnn instanceof SQLIdentifierExpr) {
|
||||
visit((SQLIdentifierExpr) columnn);
|
||||
}
|
||||
else {
|
||||
columnn.accept(this);
|
||||
SQLExpr column = columns.get(i);
|
||||
if (column instanceof SQLIdentifierExpr) {
|
||||
visit((SQLIdentifierExpr) column);
|
||||
} else {
|
||||
printExpr(column);
|
||||
}
|
||||
}
|
||||
print(')');
|
||||
decrementIndent();
|
||||
this.indentCount--;
|
||||
}
|
||||
|
||||
List<SQLInsertStatement.ValuesClause> valuesList = x.getValuesList();
|
||||
@@ -913,17 +914,18 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
x.getQuery().accept(this);
|
||||
}
|
||||
|
||||
if (x.getDuplicateKeyUpdate().size() != 0) {
|
||||
List<SQLExpr> duplicateKeyUpdate = x.getDuplicateKeyUpdate();
|
||||
if (duplicateKeyUpdate.size() != 0) {
|
||||
println();
|
||||
print0(ucase ? "ON DUPLICATE KEY UPDATE " : "on duplicate key update ");
|
||||
for (int i = 0, size = x.getDuplicateKeyUpdate().size(); i < size; ++i) {
|
||||
for (int i = 0, size = duplicateKeyUpdate.size(); i < size; ++i) {
|
||||
if (i != 0) {
|
||||
if (i % 5 == 0) {
|
||||
println();
|
||||
}
|
||||
print0(", ");
|
||||
}
|
||||
x.getDuplicateKeyUpdate().get(i).accept(this);
|
||||
duplicateKeyUpdate.get(i).accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -934,9 +936,9 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
if (this.parameterized) {
|
||||
print0(ucase ? "VALUES " : "values ");
|
||||
incrementIndent();
|
||||
this.indentCount++;
|
||||
valuesList.get(0).accept(this);
|
||||
decrementIndent();
|
||||
this.indentCount--;
|
||||
if (valuesList.size() > 1) {
|
||||
this.incrementReplaceCunt();
|
||||
}
|
||||
@@ -1070,23 +1072,27 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
print0(ucase ? "INTO " : "into ");
|
||||
|
||||
x.getTableName().accept(this);
|
||||
printExpr(x.getTableName());
|
||||
|
||||
if (x.getColumns().size() > 0) {
|
||||
List<SQLExpr> columns = x.getColumns();
|
||||
if (columns.size() > 0) {
|
||||
print0(" (");
|
||||
for (int i = 0, size = x.getColumns().size(); i < size; ++i) {
|
||||
for (int i = 0, size = columns.size(); i < size; ++i) {
|
||||
if (i != 0) {
|
||||
print0(", ");
|
||||
}
|
||||
x.getColumns().get(i).accept(this);
|
||||
|
||||
SQLExpr columnn = columns.get(i);
|
||||
printExpr(columnn);
|
||||
}
|
||||
print(')');
|
||||
}
|
||||
|
||||
if (x.getValuesList().size() != 0) {
|
||||
List<SQLInsertStatement.ValuesClause> valuesClauseList = x.getValuesList();
|
||||
if (valuesClauseList.size() != 0) {
|
||||
println();
|
||||
print0(ucase ? "VALUES " : "values ");
|
||||
int size = x.getValuesList().size();
|
||||
int size = valuesClauseList.size();
|
||||
if (size == 0) {
|
||||
print0("()");
|
||||
} else {
|
||||
@@ -1094,13 +1100,14 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
if (i != 0) {
|
||||
print0(", ");
|
||||
}
|
||||
x.getValuesList().get(i).accept(this);
|
||||
visit(valuesClauseList.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (x.getQuery() != null) {
|
||||
x.getQuery().accept(this);
|
||||
SQLQueryExpr query = x.getQuery();
|
||||
if (query != null) {
|
||||
visit(query);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -1596,13 +1603,14 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print0(ucase ? "QUEUE_ON_PK " : "queue_on_pk ");
|
||||
}
|
||||
|
||||
if (x.getTargetAffectRow() != null) {
|
||||
SQLExpr targetAffectRow = x.getTargetAffectRow();
|
||||
if (targetAffectRow != null) {
|
||||
print0(ucase ? "TARGET_AFFECT_ROW " : "target_affect_row ");
|
||||
x.getTargetAffectRow().accept(this);
|
||||
printExpr(targetAffectRow);
|
||||
print(' ');
|
||||
}
|
||||
|
||||
x.getTableSource().accept(this);
|
||||
printTableSource(x.getTableSource());
|
||||
|
||||
println();
|
||||
print0(ucase ? "SET " : "set ");
|
||||
@@ -1610,25 +1618,29 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
if (i != 0) {
|
||||
print0(", ");
|
||||
}
|
||||
x.getItems().get(i).accept(this);
|
||||
SQLUpdateSetItem item = x.getItems().get(i);
|
||||
visit(item);
|
||||
}
|
||||
|
||||
if (x.getWhere() != null) {
|
||||
SQLExpr where = x.getWhere();
|
||||
if (where != null) {
|
||||
println();
|
||||
incrementIndent();
|
||||
indentCount++;
|
||||
print0(ucase ? "WHERE " : "where ");
|
||||
x.getWhere().accept(this);
|
||||
decrementIndent();
|
||||
printExpr(where);
|
||||
indentCount--;
|
||||
}
|
||||
|
||||
if (x.getOrderBy() != null) {
|
||||
SQLOrderBy orderBy = x.getOrderBy();
|
||||
if (orderBy != null) {
|
||||
println();
|
||||
x.getOrderBy().accept(this);
|
||||
visit(orderBy);
|
||||
}
|
||||
|
||||
if (x.getLimit() != null) {
|
||||
SQLLimit limit = x.getLimit();
|
||||
if (limit != null) {
|
||||
println();
|
||||
x.getLimit().accept(this);
|
||||
visit(limit);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -2356,7 +2368,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print0(ucase ? "ALTER TABLE " : "alter table ");
|
||||
}
|
||||
printTableSourceExpr(x.getName());
|
||||
incrementIndent();
|
||||
this.indentCount++;
|
||||
for (int i = 0; i < x.getItems().size(); ++i) {
|
||||
SQLAlterTableItem item = x.getItems().get(i);
|
||||
if (i != 0) {
|
||||
@@ -2380,7 +2392,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
println();
|
||||
}
|
||||
|
||||
decrementIndent();
|
||||
this.indentCount--;
|
||||
|
||||
int i = 0;
|
||||
for (Map.Entry<String, SQLObject> option : x.getTableOptions().entrySet()) {
|
||||
@@ -2532,9 +2544,10 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
public boolean visit(SQLExprTableSource x) {
|
||||
printTableSourceExpr(x.getExpr());
|
||||
|
||||
if (x.getAlias() != null) {
|
||||
String alias = x.getAlias();
|
||||
if (alias != null) {
|
||||
print(' ');
|
||||
print0(x.getAlias());
|
||||
print0(alias);
|
||||
}
|
||||
|
||||
for (int i = 0; i < x.getHintsSize(); ++i) {
|
||||
@@ -2701,7 +2714,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
if (this.parameterized) {
|
||||
print('?');
|
||||
incrementReplaceCunt();
|
||||
if (this instanceof ExportParameterVisitor || this.parameters != null) {
|
||||
if (this.parameters != null) {
|
||||
ExportParameterVisitorUtils.exportParameter(this.parameters, x);
|
||||
}
|
||||
return false;
|
||||
@@ -2999,7 +3012,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print0(": ");
|
||||
}
|
||||
if (x.getParameters().size() != 0) {
|
||||
incrementIndent();
|
||||
this.indentCount++;
|
||||
if (x.getParent() instanceof SQLCreateProcedureStatement) {
|
||||
printIndent();
|
||||
}
|
||||
@@ -3017,11 +3030,11 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print(';');
|
||||
}
|
||||
|
||||
decrementIndent();
|
||||
this.indentCount--;
|
||||
println();
|
||||
}
|
||||
print0(ucase ? "BEGIN" : "begin");
|
||||
incrementIndent();
|
||||
this.indentCount++;
|
||||
println();
|
||||
for (int i = 0, size = x.getStatementList().size(); i < size; ++i) {
|
||||
if (i != 0) {
|
||||
@@ -3030,7 +3043,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
SQLStatement stmt = x.getStatementList().get(i);
|
||||
stmt.accept(this);
|
||||
}
|
||||
decrementIndent();
|
||||
this.indentCount--;
|
||||
println();
|
||||
print0(ucase ? "END" : "end");
|
||||
if (x.getLabelName() != null && !x.getLabelName().equals("")) {
|
||||
@@ -3045,7 +3058,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print0(ucase ? "IF " : "if ");
|
||||
x.getCondition().accept(this);
|
||||
print0(ucase ? " THEN" : " then");
|
||||
incrementIndent();
|
||||
this.indentCount++;
|
||||
println();
|
||||
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
|
||||
SQLStatement item = x.getStatements().get(i);
|
||||
@@ -3054,7 +3067,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
println();
|
||||
}
|
||||
}
|
||||
decrementIndent();
|
||||
this.indentCount--;
|
||||
println();
|
||||
for (SQLIfStatement.ElseIf iterable_element : x.getElseIfList()) {
|
||||
iterable_element.accept(this);
|
||||
@@ -3071,7 +3084,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print0(ucase ? "ELSE IF " : "else if ");
|
||||
x.getCondition().accept(this);
|
||||
print0(ucase ? " THEN" : " then");
|
||||
incrementIndent();
|
||||
this.indentCount++;
|
||||
println();
|
||||
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
|
||||
SQLStatement item = x.getStatements().get(i);
|
||||
@@ -3080,7 +3093,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
println();
|
||||
}
|
||||
}
|
||||
decrementIndent();
|
||||
this.indentCount--;
|
||||
println();
|
||||
return false;
|
||||
}
|
||||
@@ -3088,7 +3101,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
@Override
|
||||
public boolean visit(SQLIfStatement.Else x) {
|
||||
print0(ucase ? "ELSE " : "else ");
|
||||
incrementIndent();
|
||||
this.indentCount++;
|
||||
println();
|
||||
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
|
||||
SQLStatement item = x.getStatements().get(i);
|
||||
@@ -3097,7 +3110,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
println();
|
||||
}
|
||||
}
|
||||
decrementIndent();
|
||||
this.indentCount--;
|
||||
println();
|
||||
return false;
|
||||
}
|
||||
@@ -3177,7 +3190,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
}
|
||||
|
||||
print0(ucase ? "LOOP " : "loop ");
|
||||
incrementIndent();
|
||||
this.indentCount++;
|
||||
println();
|
||||
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
|
||||
SQLStatement item = x.getStatements().get(i);
|
||||
@@ -3186,7 +3199,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
println();
|
||||
}
|
||||
}
|
||||
decrementIndent();
|
||||
this.indentCount--;
|
||||
println();
|
||||
print0(ucase ? "END LOOP" : "end loop");
|
||||
if (x.getLabelName() != null && !x.getLabelName().equals("")) {
|
||||
@@ -3231,7 +3244,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
}
|
||||
|
||||
print0(ucase ? "REPEAT " : "repeat ");
|
||||
incrementIndent();
|
||||
this.indentCount++;
|
||||
println();
|
||||
for (int i = 0, size = x.getStatements().size(); i < size; ++i) {
|
||||
SQLStatement item = x.getStatements().get(i);
|
||||
@@ -3240,7 +3253,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
println();
|
||||
}
|
||||
}
|
||||
decrementIndent();
|
||||
this.indentCount--;
|
||||
println();
|
||||
print0(ucase ? "UNTIL " : "until ");
|
||||
x.getCondition().accept(this);
|
||||
@@ -3264,10 +3277,10 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print0(ucase ? "DECLARE " : "declare ");
|
||||
print0(x.getCursorName());
|
||||
print0(ucase ? " CURSOR FOR" : " cursor for");
|
||||
incrementIndent();
|
||||
this.indentCount++;
|
||||
println();
|
||||
x.getSelect().accept(this);
|
||||
decrementIndent();
|
||||
this.indentCount--;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -3389,10 +3402,10 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
}
|
||||
|
||||
}
|
||||
incrementIndent();
|
||||
this.indentCount++;
|
||||
println();
|
||||
x.getSpStatement().accept(this);
|
||||
decrementIndent();
|
||||
this.indentCount--;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -3459,7 +3472,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
print0(" (");
|
||||
if (paramSize > 0) {
|
||||
incrementIndent();
|
||||
this.indentCount++;
|
||||
println();
|
||||
|
||||
for (int i = 0; i < paramSize; ++i) {
|
||||
@@ -3471,7 +3484,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
param.accept(this);
|
||||
}
|
||||
|
||||
decrementIndent();
|
||||
this.indentCount--;
|
||||
println();
|
||||
}
|
||||
print(')');
|
||||
@@ -3517,7 +3530,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
if (paramSize > 0) {
|
||||
print0(" (");
|
||||
incrementIndent();
|
||||
this.indentCount++;
|
||||
println();
|
||||
|
||||
for (int i = 0; i < paramSize; ++i) {
|
||||
@@ -3529,7 +3542,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
param.accept(this);
|
||||
}
|
||||
|
||||
decrementIndent();
|
||||
this.indentCount--;
|
||||
println();
|
||||
print(')');
|
||||
}
|
||||
|
||||
+38
-11
@@ -49,16 +49,26 @@ import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlUserName;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement.TableSpaceOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateUserStatement.UserSpecification;
|
||||
import com.alibaba.druid.sql.repository.SchemaRepository;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.stat.TableStat.Mode;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlASTVisitor {
|
||||
|
||||
public MySqlSchemaStatVisitor() {
|
||||
super (JdbcConstants.MYSQL);
|
||||
}
|
||||
|
||||
public boolean visit(SQLSelectStatement x) {
|
||||
if (repository != null) {
|
||||
repository.resolve(x);
|
||||
}
|
||||
|
||||
setAliasMap();
|
||||
getAliasMap().put("DUAL", null);
|
||||
|
||||
@@ -72,6 +82,10 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
// DUAL
|
||||
public boolean visit(MySqlDeleteStatement x) {
|
||||
if (repository != null) {
|
||||
repository.resolve(x);
|
||||
}
|
||||
|
||||
setAliasMap();
|
||||
|
||||
setMode(x, Mode.Delete);
|
||||
@@ -452,11 +466,14 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlExplainStatement x) {
|
||||
if (x.getTableName() != null) {
|
||||
String table = x.getTableName().toString();
|
||||
SQLName tableName = x.getTableName();
|
||||
if (tableName != null) {
|
||||
String table = tableName.toString();
|
||||
getTableStat(table);
|
||||
if (x.getColumnName() != null) {
|
||||
addColumn(table, x.getColumnName().toString());
|
||||
|
||||
SQLName columnName = x.getColumnName();
|
||||
if (columnName != null) {
|
||||
addColumn(table, columnName.getSimpleName(), tableName.name_hash_lower(), columnName.name_hash_lower());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -474,7 +491,6 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlUpdateStatement x) {
|
||||
|
||||
visit((SQLUpdateStatement) x);
|
||||
for (SQLExpr item : x.getReturning()) {
|
||||
item.accept(this);
|
||||
@@ -961,10 +977,13 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
@Override
|
||||
public boolean visit(MySqlAlterTableChangeColumn x) {
|
||||
SQLAlterTableStatement stmt = (SQLAlterTableStatement) x.getParent();
|
||||
String table = stmt.getName().toString();
|
||||
|
||||
String columnName = x.getColumnName().toString();
|
||||
addColumn(table, columnName);
|
||||
SQLName table = stmt.getName();
|
||||
String tableName = table.toString();
|
||||
|
||||
SQLName column = x.getColumnName();
|
||||
String columnName = column.toString();
|
||||
addColumn(tableName, columnName, table.name_hash_lower(), column.name_hash_lower());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -976,10 +995,14 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
@Override
|
||||
public boolean visit(MySqlAlterTableModifyColumn x) {
|
||||
SQLAlterTableStatement stmt = (SQLAlterTableStatement) x.getParent();
|
||||
String table = stmt.getName().toString();
|
||||
|
||||
String columnName = x.getNewColumnDefinition().getName().toString();
|
||||
addColumn(table, columnName);
|
||||
SQLName table = stmt.getName();
|
||||
String tableName = table.toString();
|
||||
|
||||
SQLName column = x.getNewColumnDefinition().getName();
|
||||
String columnName = column.toString();
|
||||
addColumn(tableName, columnName, table.name_hash_lower(), column.name_hash_lower());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1010,6 +1033,10 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlCreateTableStatement x) {
|
||||
if (repository != null) {
|
||||
repository.resolve(x);
|
||||
}
|
||||
|
||||
boolean val = super.visit((SQLCreateTableStatement) x);
|
||||
|
||||
for (SQLObject option : x.getTableOptions().values()) {
|
||||
|
||||
+1
-1
@@ -115,7 +115,7 @@ public class FromSubqueryResolver extends OracleASTVisitorAdapter {
|
||||
stmt.getSubQuery().setWithSubQuery(null);
|
||||
|
||||
for (SQLWithSubqueryClause.Entry entry : withSubqueryClause.getEntries()) {
|
||||
String entryName = entry.getName().getName();
|
||||
String entryName = entry.getAlias();
|
||||
|
||||
SQLCreateViewStatement entryStmt = new SQLCreateViewStatement();
|
||||
entryStmt.setDbType(stmt.getDbType());
|
||||
|
||||
Reference in New Issue
Block a user