mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved mysql parser, bug fixed for mysql grant syntax support. for issue #2338
This commit is contained in:
@@ -27,6 +27,7 @@ public class MySqlUserName extends MySqlExprImpl implements SQLName, Cloneable {
|
||||
|
||||
private String userName;
|
||||
private String host;
|
||||
private String identifiedBy;
|
||||
|
||||
private long userNameHashCod64;
|
||||
private long hashCode64;
|
||||
@@ -63,6 +64,14 @@ public class MySqlUserName extends MySqlExprImpl implements SQLName, Cloneable {
|
||||
return userName + '@' + host;
|
||||
}
|
||||
|
||||
public String getIdentifiedBy() {
|
||||
return identifiedBy;
|
||||
}
|
||||
|
||||
public void setIdentifiedBy(String identifiedBy) {
|
||||
this.identifiedBy = identifiedBy;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getSimpleName();
|
||||
}
|
||||
@@ -70,8 +79,9 @@ public class MySqlUserName extends MySqlExprImpl implements SQLName, Cloneable {
|
||||
public MySqlUserName clone() {
|
||||
MySqlUserName x = new MySqlUserName();
|
||||
|
||||
x.userName = userName;
|
||||
x.host = host;
|
||||
x.userName = userName;
|
||||
x.host = host;
|
||||
x.identifiedBy = identifiedBy;
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
@@ -348,6 +348,14 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
userName.setHost(lexer.stringVal());
|
||||
}
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.IDENTIFIED) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
userName.setIdentifiedBy(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
return userName;
|
||||
}
|
||||
|
||||
@@ -696,6 +704,14 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
userName.setHost(lexer.stringVal());
|
||||
}
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.IDENTIFIED) {
|
||||
lexer.nextToken();
|
||||
accept(Token.BY);
|
||||
userName.setIdentifiedBy(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
return userName;
|
||||
}
|
||||
return super.nameRest(name);
|
||||
|
||||
@@ -2047,10 +2047,19 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
@Override
|
||||
public boolean visit(MySqlUserName x) {
|
||||
print0(x.getUserName());
|
||||
if (x.getHost() != null) {
|
||||
|
||||
String host = x.getHost();
|
||||
if (host != null) {
|
||||
print('@');
|
||||
print0(x.getHost());
|
||||
print0(host);
|
||||
}
|
||||
|
||||
String identifiedBy = x.getIdentifiedBy();
|
||||
if (identifiedBy != null) {
|
||||
print0(ucase ? " IDENTIFIED BY " : " identified by ");
|
||||
print0(identifiedBy);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -693,7 +693,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
} else {
|
||||
expr = this.exprParser.expr();
|
||||
}
|
||||
|
||||
|
||||
if (stmt.getObjectType() == SQLObjectType.TABLE || stmt.getObjectType() == null) {
|
||||
stmt.setOn(new SQLExprTableSource(expr));
|
||||
} else {
|
||||
@@ -709,6 +709,11 @@ public class SQLStatementParser extends SQLParser {
|
||||
if (lexer.token == Token.WITH) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token == Token.GRANT) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("OPTION");
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (lexer.identifierEquals("MAX_QUERIES_PER_HOUR")) {
|
||||
lexer.nextToken();
|
||||
@@ -862,6 +867,9 @@ public class SQLStatementParser extends SQLParser {
|
||||
} else if (lexer.token == Token.SESSION) {
|
||||
privilege = "ALTER SESSION";
|
||||
lexer.nextToken();
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.ROUTINE)) {
|
||||
privilege = "ALTER ROUTINE";
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token == Token.ANY) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -875,6 +883,8 @@ public class SQLStatementParser extends SQLParser {
|
||||
} else {
|
||||
throw new ParserException("TODO : " + lexer.token + " " + lexer.stringVal());
|
||||
}
|
||||
} else if (lexer.token == Token.ON) {
|
||||
privilege = "ALTER";
|
||||
} else {
|
||||
throw new ParserException("TODO : " + lexer.token + " " + lexer.stringVal());
|
||||
}
|
||||
|
||||
@@ -639,5 +639,6 @@ public final class FnvHash {
|
||||
long COMPRESSION = fnv1a_64_lower("COMPRESSION");
|
||||
long KEY_BLOCK_SIZE = fnv1a_64_lower("KEY_BLOCK_SIZE");
|
||||
long CHECKSUM = fnv1a_64_lower("CHECKSUM");
|
||||
long ROUTINE = fnv1a_64_lower("ROUTINE");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user