Search in sources :

Example 96 with MySqlSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.

the class MySqlGrantTest_5 method test_0.

public void test_0() throws Exception {
    String sql = "GRANT ALL ON mydb.mytbl TO 'someuser'@'somehost';";
    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 mydb.mytbl TO 'someuser'@'somehost'", 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(1, 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")));
}
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)

Example 97 with MySqlSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.

the class MySqlGrantTest_6 method test_0.

public void test_0() throws Exception {
    String sql = "GRANT SELECT, INSERT ON mydb.mytbl TO 'someuser'@'somehost';";
    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, INSERT ON mydb.mytbl TO 'someuser'@'somehost'", 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(1, 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")));
}
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)

Example 98 with MySqlSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.

the class MySqlGrantTest_7 method test_0.

public void test_0() throws Exception {
    String sql = "GRANT SELECT (col1), INSERT (col1,col2) ON mydb.mytbl TO 'someuser'@'somehost';";
    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(col1), INSERT(col1, col2) ON mydb.mytbl TO 'someuser'@'somehost'", 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(1, 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")));
}
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)

Example 99 with MySqlSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.

the class MySqlInsertTest_1 method test_0.

public void test_0() throws Exception {
    String sql = "INSERT INTO tbl_name () VALUES();";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement stmt = statementList.get(0);
    SQLInsertStatement insertStmt = (SQLInsertStatement) stmt;
    Assert.assertEquals(0, insertStmt.getValues().getValues().size());
    Assert.assertEquals(0, insertStmt.getColumns().size());
    Assert.assertEquals(1, statementList.size());
    MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
    stmt.accept(visitor);
    Assert.assertEquals(//
    "INSERT INTO tbl_name" + "\nVALUES ()", SQLUtils.toMySqlString(insertStmt));
}
Also used : MySqlSchemaStatVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor) SQLInsertStatement(com.alibaba.druid.sql.ast.statement.SQLInsertStatement) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 100 with MySqlSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor in project druid by alibaba.

the class MySqlGrantTest_1 method test_0.

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(1, 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")));
}
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)

Aggregations

MySqlSchemaStatVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor)345 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)344 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)341 Column (com.alibaba.druid.stat.TableStat.Column)74 MysqlTest (com.alibaba.druid.sql.MysqlTest)29 Test (org.junit.Test)29 SQLSelect (com.alibaba.druid.sql.ast.statement.SQLSelect)15 SQLSelectStatement (com.alibaba.druid.sql.ast.statement.SQLSelectStatement)15 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)15 MySqlInsertStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlInsertStatement)12 SQLInsertStatement (com.alibaba.druid.sql.ast.statement.SQLInsertStatement)5 MySqlCreateTableStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement)4 SQLCreateTableStatement (com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement)3 SQLCreateViewStatement (com.alibaba.druid.sql.ast.statement.SQLCreateViewStatement)3 SQLStatementParser (com.alibaba.druid.sql.parser.SQLStatementParser)2 SchemaStatVisitor (com.alibaba.druid.sql.visitor.SchemaStatVisitor)2 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)1 SQLName (com.alibaba.druid.sql.ast.SQLName)1 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)1 SQLCharExpr (com.alibaba.druid.sql.ast.expr.SQLCharExpr)1