Search in sources :

Example 51 with Column

use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.

the class OracleSchemaStatVisitorTest_Update method test_0.

public void test_0() throws Exception {
    String sql = "update users set loginCount = loginCount + 1 where id = ?";
    OracleStatementParser parser = new OracleStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement statemen = statementList.get(0);
    Assert.assertEquals(1, statementList.size());
    OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
    statemen.accept(visitor);
    System.out.println(sql);
    System.out.println("Tables : " + visitor.getTables());
    System.out.println("fields : " + visitor.getColumns());
    Assert.assertEquals(1, visitor.getTables().size());
    Assert.assertEquals(true, visitor.containsTable("users"));
    Assert.assertEquals(2, visitor.getColumns().size());
    Assert.assertEquals(true, visitor.getColumns().contains(new Column("users", "id")));
    Assert.assertEquals(true, visitor.getColumns().contains(new Column("users", "loginCount")));
}
Also used : Column(com.alibaba.druid.stat.TableStat.Column) OracleSchemaStatVisitor(com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) OracleStatementParser(com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)

Example 52 with Column

use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.

the class OracleOutputVisitorTest_forupdate method test_0.

public void test_0() throws Exception {
    String sql = "SELECT salary from employee for update";
    OracleStatementParser parser = new OracleStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement stmt = statementList.get(0);
    Assert.assertEquals(1, statementList.size());
    OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
    stmt.accept(visitor);
    Assert.assertEquals(1, visitor.getTables().size());
    Assert.assertEquals(true, visitor.containsTable("employee"));
    Assert.assertEquals(1, visitor.getColumns().size());
    Assert.assertEquals(true, visitor.getColumns().contains(new Column("employee", "salary")));
    StringBuilder buf = new StringBuilder();
    OracleOutputVisitor outputVisitor = new OracleOutputVisitor(buf);
    stmt.accept(outputVisitor);
    Assert.assertEquals("SELECT salary\nFROM employee\nFOR UPDATE;\n", buf.toString());
}
Also used : OracleOutputVisitor(com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor) Column(com.alibaba.druid.stat.TableStat.Column) OracleSchemaStatVisitor(com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) OracleStatementParser(com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)

Example 53 with Column

use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.

the class OracleOutputVisitorTest_orderBy method test_0.

public void test_0() throws Exception {
    String sql = "SELECT salary from employee order by name";
    OracleStatementParser parser = new OracleStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement stmt = statementList.get(0);
    Assert.assertEquals(1, statementList.size());
    OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
    stmt.accept(visitor);
    Assert.assertEquals(1, visitor.getTables().size());
    Assert.assertEquals(true, visitor.containsTable("employee"));
    Assert.assertEquals(2, visitor.getColumns().size());
    Assert.assertEquals(true, visitor.getColumns().contains(new Column("employee", "salary")));
    Assert.assertEquals(true, visitor.getColumns().contains(new Column("employee", "name")));
    StringBuilder buf = new StringBuilder();
    OracleOutputVisitor outputVisitor = new OracleOutputVisitor(buf);
    stmt.accept(outputVisitor);
    Assert.assertEquals("SELECT salary\nFROM employee\nORDER BY name;\n", buf.toString());
}
Also used : OracleOutputVisitor(com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor) Column(com.alibaba.druid.stat.TableStat.Column) OracleSchemaStatVisitor(com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) OracleStatementParser(com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)

Example 54 with Column

use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.

the class OracleSchemaStatVisitorTest2 method test_2.

public void test_2() throws Exception {
    String sql = "select id, name FROM users a";
    OracleStatementParser parser = new OracleStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement statemen = statementList.get(0);
    Assert.assertEquals(1, statementList.size());
    OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
    statemen.accept(visitor);
    System.out.println(sql);
    System.out.println("Tables : " + visitor.getTables());
    System.out.println("fields : " + visitor.getColumns());
    Assert.assertEquals(1, visitor.getTables().size());
    Assert.assertEquals(true, visitor.containsTable("users"));
    Assert.assertEquals(2, visitor.getColumns().size());
    Assert.assertEquals(true, visitor.getColumns().contains(new Column("users", "id")));
    Assert.assertEquals(true, visitor.getColumns().contains(new Column("users", "name")));
}
Also used : Column(com.alibaba.druid.stat.TableStat.Column) OracleSchemaStatVisitor(com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) OracleStatementParser(com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)

Example 55 with Column

use of com.alibaba.druid.stat.TableStat.Column in project druid by alibaba.

the class OracleSchemaStatVisitorTest3 method test_0.

public void test_0() throws Exception {
    String sql = "insert into users2 (id2, name2) select id, name FROM users where loginCount > 1";
    OracleStatementParser parser = new OracleStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement statemen = statementList.get(0);
    Assert.assertEquals(1, statementList.size());
    OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
    statemen.accept(visitor);
    System.out.println(sql);
    System.out.println("Tables : " + visitor.getTables());
    System.out.println("fields : " + visitor.getColumns());
    Assert.assertEquals(2, visitor.getTables().size());
    Assert.assertEquals(true, visitor.containsTable("users"));
    Assert.assertEquals(true, visitor.containsTable("users2"));
    Assert.assertEquals(5, visitor.getColumns().size());
    Assert.assertEquals(true, visitor.getColumns().contains(new Column("users", "id")));
    Assert.assertEquals(true, visitor.getColumns().contains(new Column("users", "name")));
    Assert.assertEquals(true, visitor.getColumns().contains(new Column("users", "loginCount")));
    Assert.assertEquals(true, visitor.getColumns().contains(new Column("users2", "name2")));
    Assert.assertEquals(true, visitor.getColumns().contains(new Column("users2", "id2")));
}
Also used : Column(com.alibaba.druid.stat.TableStat.Column) OracleSchemaStatVisitor(com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) OracleStatementParser(com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)

Aggregations

Column (com.alibaba.druid.stat.TableStat.Column)134 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)122 MySqlSchemaStatVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor)74 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)73 OracleStatementParser (com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)19 OracleSchemaStatVisitor (com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor)19 SQLServerStatementParser (com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser)12 SQLServerSchemaStatVisitor (com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor)12 SQLCreateTableStatement (com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement)10 DB2StatementParser (com.alibaba.druid.sql.dialect.db2.parser.DB2StatementParser)8 DB2SchemaStatVisitor (com.alibaba.druid.sql.dialect.db2.visitor.DB2SchemaStatVisitor)8 SchemaStatVisitor (com.alibaba.druid.sql.visitor.SchemaStatVisitor)8 OracleOutputVisitor (com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor)6 MysqlTest (com.alibaba.druid.sql.MysqlTest)5 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)5 SQLObject (com.alibaba.druid.sql.ast.SQLObject)5 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)5 Test (org.junit.Test)5 SQLCreateViewStatement (com.alibaba.druid.sql.ast.statement.SQLCreateViewStatement)4 MySqlCreateTableStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement)4