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:
@@ -686,7 +686,14 @@ public class SQLStatementParser extends SQLParser {
|
||||
lexer.nextToken(); // sql server
|
||||
}
|
||||
|
||||
SQLExpr expr = this.exprParser.expr();
|
||||
SQLExpr expr;
|
||||
if (lexer.token == Token.DOT) {
|
||||
expr = new SQLAllColumnExpr();
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
expr = this.exprParser.expr();
|
||||
}
|
||||
|
||||
if (stmt.getObjectType() == SQLObjectType.TABLE || stmt.getObjectType() == null) {
|
||||
stmt.setOn(new SQLExprTableSource(expr));
|
||||
} else {
|
||||
@@ -842,6 +849,8 @@ public class SQLStatementParser extends SQLParser {
|
||||
lexer.nextToken();
|
||||
accept(Token.TABLE);
|
||||
privilege = "CREATE TEMPORARY TABLE";
|
||||
} else if (lexer.token == Token.ON) {
|
||||
privilege = "CREATE";
|
||||
} else {
|
||||
throw new ParserException("TODO : " + lexer.token + " " + lexer.stringVal());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 1999-2017 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.grant;
|
||||
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MySqlGrantTest_35 extends MysqlTest {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
String sql = "GRANT CREATE ON . TO hello@'%'; ";
|
||||
|
||||
MySqlStatementParser parser = new MySqlStatementParser(sql);
|
||||
List<SQLStatement> statementList = parser.parseStatementList();
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
// print(statementList);
|
||||
|
||||
assertEquals(1, statementList.size());
|
||||
|
||||
MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
String output = SQLUtils.toMySqlString(stmt);
|
||||
assertEquals("GRANT CREATE ON * TO hello@'%';", //
|
||||
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());
|
||||
|
||||
assertEquals(0, visitor.getTables().size());
|
||||
assertEquals(0, visitor.getColumns().size());
|
||||
assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
// assertTrue(visitor.getTables().containsKey(new TableStat.Name("City")));
|
||||
// assertTrue(visitor.getTables().containsKey(new TableStat.Name("t2")));
|
||||
|
||||
// assertTrue(visitor.getColumns().contains(new Column("t2", "id")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user