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