Search in sources :

Example 1 with OracleParameterizedOutputVisitor

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

the class MySqlParameterizedOutputVisitorTest method validateOracle.

void validateOracle(String sql, String expect) {
    OracleStatementParser parser = new OracleStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement stmt = statementList.get(0);
    Assert.assertEquals(1, statementList.size());
    StringBuilder out = new StringBuilder();
    OracleParameterizedOutputVisitor visitor = new OracleParameterizedOutputVisitor(out, false);
    stmt.accept(visitor);
    Assert.assertTrue(visitor.getReplaceCount() > 0);
    Assert.assertEquals(expect, out.toString());
}
Also used : OracleParameterizedOutputVisitor(com.alibaba.druid.sql.dialect.oracle.visitor.OracleParameterizedOutputVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) OracleStatementParser(com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)

Example 2 with OracleParameterizedOutputVisitor

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

the class MySqlParameterizedOutputVisitorTest2 method validateOracle.

void validateOracle(String sql, String expect) {
    OracleStatementParser parser = new OracleStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement stmt = statementList.get(0);
    Assert.assertEquals(1, statementList.size());
    StringBuilder out = new StringBuilder();
    OracleParameterizedOutputVisitor visitor = new OracleParameterizedOutputVisitor(out, false);
    stmt.accept(visitor);
    Assert.assertEquals(expect, out.toString());
}
Also used : OracleParameterizedOutputVisitor(com.alibaba.druid.sql.dialect.oracle.visitor.OracleParameterizedOutputVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) OracleStatementParser(com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)

Example 3 with OracleParameterizedOutputVisitor

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

the class OnlineSQLTest method validateOracle.

void validateOracle(int id, String sql) throws Exception {
    sql = sql.trim();
    boolean sqlFlag = false;
    String lowerSql = sql.toLowerCase();
    if (lowerSql.startsWith("insert") || lowerSql.startsWith("select") || lowerSql.startsWith("upate") || lowerSql.startsWith("delete") || lowerSql.startsWith("create") || lowerSql.startsWith("drop")) {
        sqlFlag = true;
    }
    if (!sqlFlag) {
        update(id, sql, 2);
        return;
    }
    OracleStatementParser parser = new OracleStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement statemen = statementList.get(0);
    Assert.assertEquals(1, statementList.size());
    StringBuilder out = new StringBuilder();
    OracleParameterizedOutputVisitor visitor = new OracleParameterizedOutputVisitor(out);
    statemen.accept(visitor);
    update(id, out.toString(), 1);
    System.out.println(sql);
    System.out.println(out.toString());
}
Also used : OracleParameterizedOutputVisitor(com.alibaba.druid.sql.dialect.oracle.visitor.OracleParameterizedOutputVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) OracleStatementParser(com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)

Aggregations

SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)3 OracleStatementParser (com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)3 OracleParameterizedOutputVisitor (com.alibaba.druid.sql.dialect.oracle.visitor.OracleParameterizedOutputVisitor)3