Search in sources :

Example 16 with OracleSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor in project druid by alibaba.

the class OracleDeleteTest_2 method test_0.

public void test_0() throws Exception {
    String sql = "DELETE FROM (SELECT * FROM ABC WHERE ID=6000)";
    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);
    System.out.println("Tables : " + visitor.getTables());
    System.out.println("fields : " + visitor.getColumns());
    System.out.println("coditions : " + visitor.getConditions());
    System.out.println("relationships : " + visitor.getRelationships());
    Assert.assertEquals(1, visitor.getTables().size());
    Assert.assertEquals(1, visitor.getColumns().size());
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("ABC")));
    //
    Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("ABC", "ID")));
    // Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("employees", "salary")));
    // Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("employees", "commission_pct")));
    {
        String output = SQLUtils.toOracleString(stmt);
        Assert.assertEquals("DELETE FROM (\n" + "\tSELECT *\n" + "\tFROM ABC\n" + "\tWHERE ID = 6000\n" + //
        ")", output);
    }
    {
        String output = SQLUtils.toOracleString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
        Assert.assertEquals("delete from (\n" + "\tselect *\n" + "\tfrom ABC\n" + "\twhere ID = 6000\n" + //
        ")", output);
    }
}
Also used : 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 17 with OracleSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor in project druid by alibaba.

the class OracleDropDbLinkTest method test_1.

public void test_1() throws Exception {
    //
    String sql = "DROP DATABASE LINK local;";
    OracleStatementParser parser = new OracleStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement statement = statementList.get(0);
    print(statementList);
    Assert.assertEquals("DROP DATABASE LINK local", SQLUtils.toSQLString(statement, JdbcConstants.ORACLE));
    OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
    statement.accept(visitor);
    Assert.assertEquals(0, visitor.getTables().size());
}
Also used : 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 18 with OracleSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor in project druid by alibaba.

the class OracleDropDbLinkTest method test_0.

public void test_0() throws Exception {
    //
    String sql = "DROP PUBLIC DATABASE LINK remote";
    OracleStatementParser parser = new OracleStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement statement = statementList.get(0);
    print(statementList);
    Assert.assertEquals("DROP PUBLIC DATABASE LINK remote", SQLUtils.toSQLString(statement, JdbcConstants.ORACLE));
    OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
    statement.accept(visitor);
    Assert.assertEquals(0, visitor.getTables().size());
}
Also used : 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 19 with OracleSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor in project druid by alibaba.

the class OracleSchemaStatVisitorTest method test_0.

public void test_0() throws Exception {
    String sql = //
    "SELECT id, name name from department d" + "   WHERE d.id = ? order by name desc";
    OracleStatementParser parser = new OracleStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement statemen = statementList.get(0);
    print(statementList);
    Assert.assertEquals(1, statementList.size());
    List<Object> parameters = new ArrayList<Object>();
    parameters.add(23456);
    OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
    visitor.setParameters(parameters);
    statemen.accept(visitor);
    System.out.println("Tables : " + visitor.getTables());
    System.out.println("fields : " + visitor.getColumns());
    System.out.println("coditions : " + visitor.getConditions());
    System.out.println("relationships : " + visitor.getRelationships());
    Assert.assertEquals(1, visitor.getTables().size());
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("department")));
    Assert.assertEquals(2, visitor.getColumns().size());
    Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("department", "id")));
    Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("department", "name")));
    Assert.assertEquals(1, visitor.getConditions().size());
    Condition condition = visitor.getConditions().get(0);
    Assert.assertSame(parameters.get(0), condition.getValues().get(0));
    Column orderByColumn = visitor.getOrderByColumns().iterator().next();
    Assert.assertEquals(SQLOrderingSpecification.DESC, orderByColumn.getAttributes().get("orderBy.type"));
}
Also used : Condition(com.alibaba.druid.stat.TableStat.Condition) Column(com.alibaba.druid.stat.TableStat.Column) OracleSchemaStatVisitor(com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor) ArrayList(java.util.ArrayList) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) OracleStatementParser(com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)

Example 20 with OracleSchemaStatVisitor

use of com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor in project druid by alibaba.

the class OracleSetTransactionTest method test_0.

public void test_0() throws Exception {
    String sql = "set transaction name 'IGNORED_TRANS'  ";
    OracleStatementParser parser = new OracleStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement statemen = statementList.get(0);
    print(statementList);
    Assert.assertEquals(1, statementList.size());
    OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
    statemen.accept(visitor);
    System.out.println("Tables : " + visitor.getTables());
    System.out.println("fields : " + visitor.getColumns());
    System.out.println("coditions : " + visitor.getConditions());
    System.out.println("relationships : " + visitor.getRelationships());
    System.out.println("orderBy : " + visitor.getOrderByColumns());
    Assert.assertEquals(0, visitor.getTables().size());
    //        Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("employees")));
    Assert.assertEquals(0, visitor.getColumns().size());
//        Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("departments", "department_id")));
}
Also used : 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

SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)254 OracleStatementParser (com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)254 OracleSchemaStatVisitor (com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor)254 Column (com.alibaba.druid.stat.TableStat.Column)19 OracleOutputVisitor (com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor)6 Condition (com.alibaba.druid.stat.TableStat.Condition)2 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)1 SQLSelect (com.alibaba.druid.sql.ast.statement.SQLSelect)1 SQLSelectQueryBlock (com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1