Search in sources :

Example 1 with SQLGrantStatement

use of com.alibaba.druid.sql.ast.statement.SQLGrantStatement in project druid by alibaba.

the class MySqlGrantTest_ads method test_doc_3.

public void test_doc_3() throws Exception {
    String sql = "GRANT describe, select (col1, col2) ON db_name.table_name TO 'ALIYUN$account_name';";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLGrantStatement stmt = (SQLGrantStatement) statementList.get(0);
    assertEquals(1, statementList.size());
    assertEquals(// 
    "GRANT DESCRIBE, SELECT(col1, col2) ON db_name.table_name TO 'ALIYUN$account_name';", stmt.toString());
}
Also used : MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SQLGrantStatement(com.alibaba.druid.sql.ast.statement.SQLGrantStatement)

Example 2 with SQLGrantStatement

use of com.alibaba.druid.sql.ast.statement.SQLGrantStatement in project druid by alibaba.

the class MySqlGrantTest_ads method test_doc_0.

public void test_doc_0() throws Exception {
    String sql = "GRANT describe, select ON db_name.table_group_name TO 'ALIYUN$account_name'@'%';";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLGrantStatement stmt = (SQLGrantStatement) statementList.get(0);
    assertEquals(1, statementList.size());
    assertEquals(// 
    "GRANT DESCRIBE, SELECT ON db_name.table_group_name TO 'ALIYUN$account_name'@'%';", stmt.toString());
}
Also used : MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SQLGrantStatement(com.alibaba.druid.sql.ast.statement.SQLGrantStatement)

Example 3 with SQLGrantStatement

use of com.alibaba.druid.sql.ast.statement.SQLGrantStatement in project druid by alibaba.

the class MySqlGrantTest_ads method test_doc_1.

public void test_doc_1() throws Exception {
    String sql = "GRANT all ON db_name.table_group_name TO 'ALIYUN$account_name'@'%';";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLGrantStatement stmt = (SQLGrantStatement) statementList.get(0);
    assertEquals(1, statementList.size());
    assertEquals(// 
    "GRANT ALL ON db_name.table_group_name TO 'ALIYUN$account_name'@'%';", stmt.toString());
}
Also used : MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SQLGrantStatement(com.alibaba.druid.sql.ast.statement.SQLGrantStatement)

Example 4 with SQLGrantStatement

use of com.alibaba.druid.sql.ast.statement.SQLGrantStatement in project druid by alibaba.

the class MySqlGrantTest_ads method test_doc_2.

public void test_doc_2() throws Exception {
    String sql = "GRANT describe, select (col1, col2) ON db_name.* TO 'ALIYUN$account_name';";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLGrantStatement stmt = (SQLGrantStatement) statementList.get(0);
    assertEquals(1, statementList.size());
    assertEquals(// 
    "GRANT DESCRIBE, SELECT(col1, col2) ON db_name.* TO 'ALIYUN$account_name';", stmt.toString());
}
Also used : MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SQLGrantStatement(com.alibaba.druid.sql.ast.statement.SQLGrantStatement)

Example 5 with SQLGrantStatement

use of com.alibaba.druid.sql.ast.statement.SQLGrantStatement in project druid by alibaba.

the class MySqlGrantTest_35 method test_6.

public void test_6() throws Exception {
    String sql = "grant all on *.* to 'xx'@'localhost' with grant option";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLGrantStatement stmt = (SQLGrantStatement) statementList.get(0);
    assertEquals(1, statementList.size());
    assertTrue(stmt.getWithGrantOption());
    MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
    stmt.accept(visitor);
    assertEquals(// 
    "GRANT ALL ON *.* TO 'xx'@'localhost' WITH GRANT OPTION", stmt.toString());
    assertEquals(// 
    "grant ALL on *.* to 'xx'@'localhost' with grant option", stmt.toLowerCaseString());
    assertEquals(1, visitor.getTables().size());
    assertEquals(0, visitor.getColumns().size());
    assertEquals(0, visitor.getConditions().size());
}
Also used : MySqlSchemaStatVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) SQLGrantStatement(com.alibaba.druid.sql.ast.statement.SQLGrantStatement)

Aggregations

SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)8 SQLGrantStatement (com.alibaba.druid.sql.ast.statement.SQLGrantStatement)8 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)8 MySqlSchemaStatVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor)4 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)1 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)1