mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve sql parser
This commit is contained in:
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLGrantStatement extends SQLStatementImpl {
|
||||
|
||||
private final List<SQLExpr> privileges = new ArrayList<SQLExpr>();
|
||||
|
||||
private SQLExpr on;
|
||||
private SQLExpr to;
|
||||
|
||||
// mysql
|
||||
private SQLExpr maxQueriesPerHour;
|
||||
private SQLExpr maxUpdatesPerHour;
|
||||
private SQLExpr maxConnectionsPerHour;
|
||||
private SQLExpr maxUserConnections;
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, on);
|
||||
acceptChild(visitor, to);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExpr getOn() {
|
||||
return on;
|
||||
}
|
||||
|
||||
public void setOn(SQLExpr on) {
|
||||
this.on = on;
|
||||
}
|
||||
|
||||
public SQLExpr getTo() {
|
||||
return to;
|
||||
}
|
||||
|
||||
public void setTo(SQLExpr to) {
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public List<SQLExpr> getPrivileges() {
|
||||
return privileges;
|
||||
}
|
||||
|
||||
public void addPrivileges(String privilege) {
|
||||
SQLIdentifierExpr expr = new SQLIdentifierExpr(privilege);
|
||||
expr.setParent(this);
|
||||
this.privileges.add(expr);
|
||||
}
|
||||
|
||||
public SQLExpr getMaxQueriesPerHour() {
|
||||
return maxQueriesPerHour;
|
||||
}
|
||||
|
||||
public void setMaxQueriesPerHour(SQLExpr maxQueriesPerHour) {
|
||||
this.maxQueriesPerHour = maxQueriesPerHour;
|
||||
}
|
||||
|
||||
public SQLExpr getMaxUpdatesPerHour() {
|
||||
return maxUpdatesPerHour;
|
||||
}
|
||||
|
||||
public void setMaxUpdatesPerHour(SQLExpr maxUpdatesPerHour) {
|
||||
this.maxUpdatesPerHour = maxUpdatesPerHour;
|
||||
}
|
||||
|
||||
public SQLExpr getMaxConnectionsPerHour() {
|
||||
return maxConnectionsPerHour;
|
||||
}
|
||||
|
||||
public void setMaxConnectionsPerHour(SQLExpr maxConnectionsPerHour) {
|
||||
this.maxConnectionsPerHour = maxConnectionsPerHour;
|
||||
}
|
||||
|
||||
public SQLExpr getMaxUserConnections() {
|
||||
return maxUserConnections;
|
||||
}
|
||||
|
||||
public void setMaxUserConnections(SQLExpr maxUserConnections) {
|
||||
this.maxUserConnections = maxUserConnections;
|
||||
}
|
||||
|
||||
}
|
||||
+39
-54
@@ -1,54 +1,39 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.oracle.ast.stmt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
|
||||
|
||||
public class OracleGrantStatement extends OracleStatementImpl implements OracleStatement {
|
||||
|
||||
private List<String> privileges = new ArrayList<String>();
|
||||
|
||||
private SQLExpr on;
|
||||
|
||||
public SQLExpr getOn() {
|
||||
return on;
|
||||
}
|
||||
|
||||
public void setOn(SQLExpr on) {
|
||||
this.on = on;
|
||||
}
|
||||
|
||||
public List<String> getPrivileges() {
|
||||
return privileges;
|
||||
}
|
||||
|
||||
public void setPrivileges(List<String> privileges) {
|
||||
this.privileges = privileges;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept0(OracleASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, on);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.mysql.ast.statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
|
||||
public class MySqlAlterUserStatement extends MySqlStatementImpl {
|
||||
|
||||
private final List<SQLExpr> users = new ArrayList<SQLExpr>();
|
||||
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, users);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public List<SQLExpr> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
}
|
||||
+15
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.mysql.ast.statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
+9
@@ -45,6 +45,7 @@ public class MySqlCreateUserStatement extends MySqlStatementImpl {
|
||||
public static class UserSpecification extends MySqlObjectImpl {
|
||||
|
||||
private SQLExpr user;
|
||||
private boolean passwordHash = false;
|
||||
private SQLExpr password;
|
||||
private SQLExpr authPlugin;
|
||||
|
||||
@@ -56,6 +57,14 @@ public class MySqlCreateUserStatement extends MySqlStatementImpl {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public boolean isPasswordHash() {
|
||||
return passwordHash;
|
||||
}
|
||||
|
||||
public void setPasswordHash(boolean passwordHash) {
|
||||
this.passwordHash = passwordHash;
|
||||
}
|
||||
|
||||
public SQLExpr getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
@@ -406,7 +406,7 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("LANGUAGE");
|
||||
acceptIdentifier("MODE");
|
||||
if (identifierEquals("WITH")) {
|
||||
if (lexer.token() == Token.WITH) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("QUERY");
|
||||
acceptIdentifier("EXPANSION");
|
||||
@@ -421,7 +421,7 @@ public class MySqlExprParser extends SQLExprParser {
|
||||
} else {
|
||||
throw new ParserException("TODO");
|
||||
}
|
||||
} else if (identifierEquals("WITH")) {
|
||||
} else if (lexer.token() == Token.WITH) {
|
||||
throw new ParserException("TODO");
|
||||
}
|
||||
|
||||
|
||||
@@ -242,7 +242,7 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (identifierEquals("WITH")) {
|
||||
if (lexer.token() == Token.WITH) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("ROLLUP");
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableImportTa
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableModifyColumn;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterUserStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAnalyzeStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlBinlogStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCommitStatement;
|
||||
@@ -436,15 +437,14 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
|
||||
if (identifierEquals("PASSWORD")) {
|
||||
lexer.nextToken();
|
||||
userSpec.setPasswordHash(true);
|
||||
}
|
||||
|
||||
SQLCharExpr password = (SQLCharExpr) this.exprParser.expr();
|
||||
userSpec.setPassword(password);
|
||||
} else if (lexer.token() == Token.WITH) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLCharExpr text = (SQLCharExpr) this.exprParser.expr();
|
||||
userSpec.setAuthPlugin(text);
|
||||
userSpec.setAuthPlugin(this.exprParser.expr());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -500,7 +500,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
MySqlAnalyzeStatement stmt = new MySqlAnalyzeStatement();
|
||||
List<SQLName> names = new ArrayList<SQLName>();
|
||||
this.exprParser.names(names, stmt);
|
||||
|
||||
|
||||
for (SQLName name : names) {
|
||||
stmt.getTableSources().add(new SQLExprTableSource(name));
|
||||
}
|
||||
@@ -1450,7 +1450,7 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
|
||||
MySqlStartTransactionStatement stmt = new MySqlStartTransactionStatement();
|
||||
|
||||
if (identifierEquals("WITH")) {
|
||||
if (lexer.token() == Token.WITH) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("CONSISTENT");
|
||||
acceptIdentifier("SNAPSHOT");
|
||||
@@ -2087,6 +2087,10 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
|
||||
public SQLStatement parseAlter() {
|
||||
accept(Token.ALTER);
|
||||
|
||||
if (lexer.token() == Token.USER) {
|
||||
return parseAlterUser();
|
||||
}
|
||||
|
||||
boolean ignore = false;
|
||||
|
||||
@@ -2536,6 +2540,26 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
}
|
||||
}
|
||||
|
||||
public MySqlAlterUserStatement parseAlterUser() {
|
||||
accept(Token.USER);
|
||||
|
||||
MySqlAlterUserStatement stmt = new MySqlAlterUserStatement();
|
||||
for (;;) {
|
||||
SQLExpr user = this.exprParser.expr();
|
||||
acceptIdentifier("PASSWORD");
|
||||
acceptIdentifier("EXPIRE");
|
||||
stmt.getUsers().add(user);
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
return stmt;
|
||||
}
|
||||
|
||||
public MySqlExprParser getExprParser() {
|
||||
return (MySqlExprParser) exprParser;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableImportTa
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableModifyColumn;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterUserStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAnalyzeStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlBinlogStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCommitStatement;
|
||||
@@ -557,4 +558,8 @@ public interface MySqlASTVisitor extends SQLASTVisitor {
|
||||
boolean visit(MySqlAnalyzeStatement x);
|
||||
|
||||
void endVisit(MySqlAnalyzeStatement x);
|
||||
|
||||
boolean visit(MySqlAlterUserStatement x);
|
||||
|
||||
void endVisit(MySqlAlterUserStatement x);
|
||||
} //
|
||||
|
||||
@@ -40,6 +40,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableImportTa
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableModifyColumn;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterUserStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAnalyzeStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlBinlogStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCommitStatement;
|
||||
@@ -1236,4 +1237,14 @@ public class MySqlASTVisitorAdapter extends SQLASTVisitorAdapter implements MySq
|
||||
public void endVisit(MySqlAnalyzeStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlAlterUserStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlAlterUserStatement x) {
|
||||
|
||||
}
|
||||
} //
|
||||
|
||||
@@ -62,6 +62,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableImportTa
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableModifyColumn;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterUserStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAnalyzeStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlBinlogStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCommitStatement;
|
||||
@@ -1454,6 +1455,9 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
if (x.getPassword() != null) {
|
||||
print(" IDENTIFIED BY ");
|
||||
if (x.isPasswordHash()) {
|
||||
print("PASSWORD ");
|
||||
}
|
||||
x.getPassword().accept(this);
|
||||
}
|
||||
|
||||
@@ -3017,5 +3021,21 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
public void endVisit(MySqlAnalyzeStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlAlterUserStatement x) {
|
||||
print("ALTER USER");
|
||||
for (SQLExpr user : x.getUsers()) {
|
||||
print(' ');
|
||||
user.accept(this);
|
||||
print(" PASSWORD EXPIRE");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlAlterUserStatement x) {
|
||||
|
||||
}
|
||||
|
||||
} //
|
||||
|
||||
+12
-1
@@ -53,6 +53,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableImportTa
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableModifyColumn;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterUserStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAnalyzeStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlBinlogStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCommitStatement;
|
||||
@@ -515,7 +516,7 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlCreateUserStatement x) {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1319,5 +1320,15 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
public void endVisit(MySqlAnalyzeStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlAlterUserStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlAlterUserStatement x) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,7 +50,6 @@ public class OracleLexer extends Lexer {
|
||||
map.put("EXCLUSIVE", Token.EXCLUSIVE);
|
||||
map.put("EXTRACT", Token.EXTRACT);
|
||||
map.put("GOTO", Token.GOTO);
|
||||
map.put("GRANT", Token.GRANT);
|
||||
map.put("IF", Token.IF);
|
||||
|
||||
map.put("LIMIT", Token.LIMIT);
|
||||
|
||||
@@ -89,7 +89,6 @@ import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleFetchStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleFileSpecification;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleForStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleGotoStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleGrantStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleIfStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleLabelStatement;
|
||||
@@ -558,58 +557,6 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
public SQLStatement parseGrant() {
|
||||
accept(Token.GRANT);
|
||||
OracleGrantStatement stmt = new OracleGrantStatement();
|
||||
|
||||
for (;;) {
|
||||
if (lexer.token() == Token.ALL) {
|
||||
lexer.nextToken();
|
||||
if (identifierEquals("PRIVILEGES")) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
stmt.getPrivileges().add("ALL");
|
||||
} else if (lexer.token() == Token.SELECT) {
|
||||
stmt.getPrivileges().add("SELECT");
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == Token.UPDATE) {
|
||||
stmt.getPrivileges().add("UPDATE");
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == Token.DELETE) {
|
||||
stmt.getPrivileges().add("DELETE");
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == Token.INSERT) {
|
||||
stmt.getPrivileges().add("INSERT");
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == Token.CREATE) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.TABLE) {
|
||||
stmt.getPrivileges().add("CREATE TABLE");
|
||||
lexer.nextToken();
|
||||
} else if (identifierEquals("SYNONYM")) {
|
||||
stmt.getPrivileges().add("CREATE SYNONYM");
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
|
||||
}
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.ON) {
|
||||
lexer.nextToken();
|
||||
stmt.setOn(this.exprParser.expr());
|
||||
}
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
public SQLStatement parseSet() {
|
||||
accept(Token.SET);
|
||||
acceptIdentifier("TRANSACTION");
|
||||
|
||||
@@ -89,7 +89,6 @@ import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleFileSpecification;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleForStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleForeignKey;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleGotoStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleGrantStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleIfStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleIfStatement.Else;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleIfStatement.ElseIf;
|
||||
@@ -392,10 +391,6 @@ public interface OracleASTVisitor extends SQLASTVisitor {
|
||||
|
||||
void endVisit(OracleSetTransactionStatement x);
|
||||
|
||||
boolean visit(OracleGrantStatement x);
|
||||
|
||||
void endVisit(OracleGrantStatement x);
|
||||
|
||||
boolean visit(OracleExplainStatement x);
|
||||
|
||||
void endVisit(OracleExplainStatement x);
|
||||
|
||||
-11
@@ -97,7 +97,6 @@ import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleFileSpecification;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleForStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleForeignKey;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleGotoStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleGrantStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleIfStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleIfStatement.Else;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleIfStatement.ElseIf;
|
||||
@@ -836,16 +835,6 @@ public class OracleASTVisitorAdapter extends SQLASTVisitorAdapter implements Ora
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleGrantStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OracleGrantStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleExplainStatement x) {
|
||||
return true;
|
||||
|
||||
@@ -130,7 +130,6 @@ import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleFileSpecification;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleForStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleForeignKey;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleGotoStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleGrantStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleIfStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleIfStatement.Else;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleIfStatement.ElseIf;
|
||||
@@ -1841,28 +1840,6 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleGrantStatement x) {
|
||||
print("GRANT ");
|
||||
for (int i = 0, size = x.getPrivileges().size(); i < size; ++i) {
|
||||
if (i != 0) {
|
||||
print(", ");
|
||||
}
|
||||
print(x.getPrivileges().get(i));
|
||||
}
|
||||
|
||||
if (x.getOn() != null) {
|
||||
print(" ON ");
|
||||
x.getOn().accept(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OracleGrantStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleExplainStatement x) {
|
||||
print("EXPLAIN PLAN");
|
||||
|
||||
-11
@@ -121,7 +121,6 @@ import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleFileSpecification;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleForStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleForeignKey;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleGotoStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleGrantStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleIfStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleIfStatement.Else;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleIfStatement.ElseIf;
|
||||
@@ -1218,16 +1217,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleGrantStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OracleGrantStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleExplainStatement x) {
|
||||
return false;
|
||||
|
||||
@@ -58,7 +58,6 @@ public class PGLexer extends Lexer {
|
||||
|
||||
map.put("USING", Token.USING);
|
||||
map.put("WINDOW", Token.WINDOW);
|
||||
map.put("WITH", Token.WITH);
|
||||
|
||||
DEFAULT_PG_KEYWORDS = new Keywords(map);
|
||||
}
|
||||
|
||||
@@ -128,6 +128,8 @@ public class Keywords {
|
||||
|
||||
map.put("COMMENT", Token.COMMENT);
|
||||
map.put("COMPUTE", Token.COMPUTE);
|
||||
map.put("WITH", Token.WITH);
|
||||
map.put("GRANT", Token.GRANT);
|
||||
|
||||
DEFAULT_KEYWORDS = new Keywords(map);
|
||||
}
|
||||
|
||||
@@ -95,7 +95,15 @@ public class SQLExprParser extends SQLParser {
|
||||
if (lexer.token() == Token.STAR) {
|
||||
lexer.nextToken();
|
||||
|
||||
return new SQLAllColumnExpr();
|
||||
SQLExpr expr = new SQLAllColumnExpr();
|
||||
|
||||
if (lexer.token() == Token.DOT) {
|
||||
lexer.nextToken();
|
||||
accept(Token.STAR);
|
||||
return new SQLPropertyExpr(expr, "*");
|
||||
}
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
SQLExpr expr = primary();
|
||||
@@ -246,6 +254,8 @@ public class SQLExprParser extends SQLParser {
|
||||
case SEQUENCE:
|
||||
case USER:
|
||||
case EXPLAIN:
|
||||
case WITH:
|
||||
case GRANT:
|
||||
sqlExpr = new SQLIdentifierExpr(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
break;
|
||||
@@ -1352,7 +1362,7 @@ public class SQLExprParser extends SQLParser {
|
||||
column.getConstaints().add(ref);
|
||||
return parseColumnRest(column);
|
||||
}
|
||||
|
||||
|
||||
if (lexer.token() == Token.NOT) {
|
||||
lexer.nextToken();
|
||||
accept(Token.NULL);
|
||||
@@ -1361,7 +1371,7 @@ public class SQLExprParser extends SQLParser {
|
||||
column.getConstaints().add(notNull);
|
||||
return parseColumnRest(column);
|
||||
}
|
||||
|
||||
|
||||
if (lexer.token == Token.CHECK) {
|
||||
SQLColumnCheck check = parseColumnCheck();
|
||||
check.setName(name);
|
||||
@@ -1369,7 +1379,7 @@ public class SQLExprParser extends SQLParser {
|
||||
column.getConstaints().add(check);
|
||||
return parseColumnRest(column);
|
||||
}
|
||||
|
||||
|
||||
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
|
||||
}
|
||||
|
||||
@@ -1386,7 +1396,7 @@ public class SQLExprParser extends SQLParser {
|
||||
lexer.nextToken();
|
||||
SQLExpr expr = this.expr();
|
||||
SQLColumnCheck check = new SQLColumnCheck(expr);
|
||||
|
||||
|
||||
if (lexer.token() == Token.DISABLE) {
|
||||
lexer.nextToken();
|
||||
check.setEnable(false);
|
||||
@@ -1478,7 +1488,7 @@ public class SQLExprParser extends SQLParser {
|
||||
|
||||
return constraint;
|
||||
}
|
||||
|
||||
|
||||
public SQLCheck parseCheck() {
|
||||
accept(Token.CHECK);
|
||||
SQLCheck check = createCheck();
|
||||
|
||||
@@ -102,6 +102,7 @@ public class SQLParser {
|
||||
case SEQUENCE:
|
||||
case USER:
|
||||
case ANALYZE:
|
||||
case GRANT:
|
||||
alias = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
return alias;
|
||||
|
||||
@@ -50,6 +50,7 @@ import com.alibaba.druid.sql.ast.statement.SQLDropUserStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropViewStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExplainStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLGrantStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertInto;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLPrimaryKey;
|
||||
@@ -136,7 +137,7 @@ public class SQLStatementParser extends SQLParser {
|
||||
statementList.add(parseDeleteStatement());
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (lexer.token() == (Token.EXPLAIN)) {
|
||||
statementList.add(parseExplain());
|
||||
continue;
|
||||
@@ -194,6 +195,12 @@ public class SQLStatementParser extends SQLParser {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.GRANT) {
|
||||
SQLStatement stmt = parseGrant();
|
||||
statementList.add(stmt);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.LBRACE || identifierEquals("CALL")) {
|
||||
SQLCallStatement stmt = parseCall();
|
||||
statementList.add(stmt);
|
||||
@@ -306,6 +313,100 @@ public class SQLStatementParser extends SQLParser {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
public SQLGrantStatement parseGrant() {
|
||||
accept(Token.GRANT);
|
||||
SQLGrantStatement stmt = new SQLGrantStatement();
|
||||
|
||||
for (;;) {
|
||||
if (lexer.token() == Token.ALL) {
|
||||
lexer.nextToken();
|
||||
if (identifierEquals("PRIVILEGES")) {
|
||||
lexer.nextToken();
|
||||
stmt.addPrivileges("ALL PRIVILEGES");
|
||||
} else {
|
||||
stmt.addPrivileges("ALL");
|
||||
}
|
||||
} else if (lexer.token() == Token.SELECT) {
|
||||
stmt.addPrivileges("SELECT");
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == Token.UPDATE) {
|
||||
stmt.addPrivileges("UPDATE");
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == Token.DELETE) {
|
||||
stmt.addPrivileges("DELETE");
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == Token.INSERT) {
|
||||
stmt.addPrivileges("INSERT");
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == Token.CREATE) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (lexer.token() == Token.TABLE) {
|
||||
stmt.addPrivileges("CREATE TABLE");
|
||||
lexer.nextToken();
|
||||
} else if (identifierEquals("SYNONYM")) {
|
||||
stmt.addPrivileges("CREATE SYNONYM");
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
|
||||
}
|
||||
} else if (identifierEquals("USAGE")) {
|
||||
stmt.addPrivileges("USAGE");
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.ON) {
|
||||
lexer.nextToken();
|
||||
stmt.setOn(this.exprParser.expr());
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.TO) {
|
||||
lexer.nextToken();
|
||||
stmt.setTo(this.exprParser.expr());
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.WITH) {
|
||||
lexer.nextToken();
|
||||
|
||||
for (;;) {
|
||||
if (identifierEquals("MAX_QUERIES_PER_HOUR")) {
|
||||
lexer.nextToken();
|
||||
stmt.setMaxQueriesPerHour(this.exprParser.primary());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identifierEquals("MAX_UPDATES_PER_HOUR")) {
|
||||
lexer.nextToken();
|
||||
stmt.setMaxUpdatesPerHour(this.exprParser.primary());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identifierEquals("MAX_CONNECTIONS_PER_HOUR")) {
|
||||
lexer.nextToken();
|
||||
stmt.setMaxConnectionsPerHour(this.exprParser.primary());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identifierEquals("MAX_USER_CONNECTIONS")) {
|
||||
lexer.nextToken();
|
||||
stmt.setMaxUserConnections(this.exprParser.primary());
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
public SQLStatement parseSavePoint() {
|
||||
acceptIdentifier("SAVEPOINT");
|
||||
SQLSavePointStatement stmt = new SQLSavePointStatement();
|
||||
@@ -1030,11 +1131,11 @@ public class SQLStatementParser extends SQLParser {
|
||||
if (identifierEquals("PLAN")) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
|
||||
if (lexer.token() == Token.FOR) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
|
||||
SQLExplainStatement explain = new SQLExplainStatement();
|
||||
explain.setStatement(parseStatement());
|
||||
|
||||
|
||||
@@ -106,6 +106,7 @@ import com.alibaba.druid.sql.ast.statement.SQLExprHint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLForeignKeyConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLForeignKeyImpl;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLGrantStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement.ValuesClause;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLJoinTableSource;
|
||||
@@ -795,7 +796,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
} else {
|
||||
print("DROP TABLE ");
|
||||
}
|
||||
|
||||
|
||||
if (x.isIfExists()) {
|
||||
print("IF EXISTS ");
|
||||
}
|
||||
@@ -823,11 +824,11 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
|
||||
public boolean visit(SQLDropViewStatement x) {
|
||||
print("DROP VIEW ");
|
||||
|
||||
|
||||
if (x.isIfExists()) {
|
||||
print("IF EXISTS ");
|
||||
}
|
||||
|
||||
|
||||
printAndAccept(x.getTableSources(), ", ");
|
||||
|
||||
if (x.isCascade()) {
|
||||
@@ -1706,7 +1707,7 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
printAndAccept(x.getUsers(), ", ");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLExplainStatement x) {
|
||||
print("EXPLAIN");
|
||||
@@ -1714,4 +1715,59 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
x.getStatement().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLGrantStatement x) {
|
||||
print("GRANT ");
|
||||
printAndAccept(x.getPrivileges(), ", ");
|
||||
|
||||
if (x.getOn() != null) {
|
||||
print(" ON ");
|
||||
x.getOn().accept(this);
|
||||
}
|
||||
|
||||
if (x.getTo() != null) {
|
||||
print(" TO ");
|
||||
x.getTo().accept(this);
|
||||
}
|
||||
|
||||
boolean with = false;
|
||||
if (x.getMaxQueriesPerHour() != null) {
|
||||
if (!with) {
|
||||
print(" WITH");
|
||||
with = true;
|
||||
}
|
||||
print(" MAX_QUERIES_PER_HOUR ");
|
||||
x.getMaxQueriesPerHour().accept(this);
|
||||
}
|
||||
|
||||
if (x.getMaxUpdatesPerHour() != null) {
|
||||
if (!with) {
|
||||
print(" WITH");
|
||||
with = true;
|
||||
}
|
||||
print(" MAX_UPDATES_PER_HOUR ");
|
||||
x.getMaxUpdatesPerHour().accept(this);
|
||||
}
|
||||
|
||||
if (x.getMaxConnectionsPerHour() != null) {
|
||||
if (!with) {
|
||||
print(" WITH");
|
||||
with = true;
|
||||
}
|
||||
print(" MAX_CONNECTIONS_PER_HOUR ");
|
||||
x.getMaxConnectionsPerHour().accept(this);
|
||||
}
|
||||
|
||||
if (x.getMaxUserConnections() != null) {
|
||||
if (!with) {
|
||||
print(" WITH");
|
||||
with = true;
|
||||
}
|
||||
print(" MAX_USER_CONNECTIONS ");
|
||||
x.getMaxUserConnections().accept(this);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ import com.alibaba.druid.sql.ast.statement.SQLExplainStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprHint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLForeignKeyImpl;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLGrantStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLJoinTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLPrimaryKeyImpl;
|
||||
@@ -504,4 +505,8 @@ public interface SQLASTVisitor {
|
||||
void endVisit(SQLExplainStatement x);
|
||||
|
||||
boolean visit(SQLExplainStatement x);
|
||||
|
||||
void endVisit(SQLGrantStatement x);
|
||||
|
||||
boolean visit(SQLGrantStatement x);
|
||||
}
|
||||
|
||||
@@ -90,6 +90,7 @@ import com.alibaba.druid.sql.ast.statement.SQLExplainStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprHint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLForeignKeyImpl;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLGrantStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement.ValuesClause;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLJoinTableSource;
|
||||
@@ -975,4 +976,14 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
public boolean visit(SQLExplainStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLGrantStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLGrantStatement x) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ import com.alibaba.druid.sql.ast.statement.SQLDropUserStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDropViewStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLForeignKeyImpl;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLGrantStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLJoinTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLRollbackStatement;
|
||||
@@ -1257,12 +1258,12 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLDropUserStatement x) {
|
||||
|
||||
public boolean visit(SQLDropUserStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLDropUserStatement x) {
|
||||
return true;
|
||||
public boolean visit(SQLGrantStatement x) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,11 +27,9 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableStatemen
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlBinlogStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement.TableSpaceOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateUserStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateUserStatement.UserSpecification;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDeleteStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlExecuteStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlHelpStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlKillStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLoadXmlStatement;
|
||||
@@ -130,7 +128,6 @@ public class MySqlASTVisitorAdapterTest extends TestCase {
|
||||
new MySqlKillStatement().accept(adapter);
|
||||
new MySqlBinlogStatement().accept(adapter);
|
||||
new MySqlResetStatement().accept(adapter);
|
||||
new MySqlCreateUserStatement().accept(adapter);
|
||||
new UserSpecification().accept(adapter);
|
||||
new MySqlPartitionByKey().accept(adapter);
|
||||
new MySqlOutFileExpr().accept(adapter);
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
|
||||
public class MySqlAlterUserTest extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "ALTER USER 'jeffrey'@'localhost' PASSWORD EXPIRE;";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("ALTER USER 'jeffrey'@'localhost' PASSWORD EXPIRE", //
|
||||
output);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
Assert.assertEquals(0, visitor.getTables().size());
|
||||
Assert.assertEquals(0, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("City")));
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t2")));
|
||||
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("t2", "id")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
|
||||
public class MySqlCreateUserTest_1 extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "CREATE USER 'jeffrey'@'localhost';";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("CREATE USER 'jeffrey'@'localhost'", //
|
||||
output);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
Assert.assertEquals(0, visitor.getTables().size());
|
||||
Assert.assertEquals(0, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("City")));
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t2")));
|
||||
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("t2", "id")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
|
||||
public class MySqlCreateUserTest_2 extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'mypass';";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'mypass'", //
|
||||
output);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
Assert.assertEquals(0, visitor.getTables().size());
|
||||
Assert.assertEquals(0, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("City")));
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t2")));
|
||||
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("t2", "id")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
|
||||
public class MySqlCreateUserTest_3 extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "CREATE USER 'jeffrey'@'localhost'"
|
||||
+ " IDENTIFIED BY PASSWORD '*90E462C37378CED12064BB3388827D2BA3A9B689';";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY PASSWORD '*90E462C37378CED12064BB3388827D2BA3A9B689'", //
|
||||
output);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
Assert.assertEquals(0, visitor.getTables().size());
|
||||
Assert.assertEquals(0, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("City")));
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t2")));
|
||||
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("t2", "id")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
|
||||
public class MySqlCreateUserTest_4 extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "CREATE USER 'jeffrey'@'localhost'"
|
||||
+ " IDENTIFIED WITH my_auth_plugin;";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("CREATE USER 'jeffrey'@'localhost' IDENTIFIED WITH my_auth_plugin", //
|
||||
output);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
Assert.assertEquals(0, visitor.getTables().size());
|
||||
Assert.assertEquals(0, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("City")));
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t2")));
|
||||
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("t2", "id")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
|
||||
public class MySqlDropUserTest extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "DROP USER 'jeffrey'@'localhost';";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("DROP USER 'jeffrey'@'localhost'", //
|
||||
output);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
Assert.assertEquals(0, visitor.getTables().size());
|
||||
Assert.assertEquals(0, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("City")));
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t2")));
|
||||
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("t2", "id")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
|
||||
public class MySqlGrantTest extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "GRANT ALL ON db1.* TO 'jeffrey'@'localhost';";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("GRANT ALL ON db1.* TO 'jeffrey'@'localhost'", //
|
||||
output);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
Assert.assertEquals(0, visitor.getTables().size());
|
||||
Assert.assertEquals(0, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("City")));
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t2")));
|
||||
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("t2", "id")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
|
||||
public class MySqlGrantTest_1 extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "GRANT SELECT ON db2.invoice TO 'jeffrey'@'localhost';";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("GRANT SELECT ON db2.invoice TO 'jeffrey'@'localhost'", //
|
||||
output);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
Assert.assertEquals(0, visitor.getTables().size());
|
||||
Assert.assertEquals(0, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("City")));
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t2")));
|
||||
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("t2", "id")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.mysql;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.MysqlTest;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor;
|
||||
|
||||
public class MySqlGrantTest_2 extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "GRANT USAGE ON *.* TO 'jeffrey'@'localhost' WITH MAX_QUERIES_PER_HOUR 90";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
print(statementList);
|
||||
|
||||
Assert.assertEquals(1, statementList.size());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
Assert.assertEquals("GRANT USAGE ON *.* TO 'jeffrey'@'localhost' WITH MAX_QUERIES_PER_HOUR 90", //
|
||||
output);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
Assert.assertEquals(0, visitor.getTables().size());
|
||||
Assert.assertEquals(0, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("City")));
|
||||
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("t2")));
|
||||
|
||||
// Assert.assertTrue(visitor.getColumns().contains(new Column("t2", "id")));
|
||||
}
|
||||
}
|
||||
-2
@@ -78,7 +78,6 @@ import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleFetchStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleFileSpecification;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleForStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleGotoStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleGrantStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleIfStatement;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleIfStatement.Else;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleIfStatement.ElseIf;
|
||||
@@ -180,7 +179,6 @@ public class OracleASTVisitorAdapterTest extends TestCase {
|
||||
new OracleExceptionStatement.Item().accept(adapter);
|
||||
new OracleArgumentExpr().accept(adapter);
|
||||
new OracleSetTransactionStatement().accept(adapter);
|
||||
new OracleGrantStatement().accept(adapter);
|
||||
new SQLDropSequenceStatement().accept(adapter);
|
||||
new OracleDataTypeIntervalDay().accept(adapter);
|
||||
new OracleDataTypeIntervalYear().accept(adapter);
|
||||
|
||||
Reference in New Issue
Block a user