Search in sources :

Example 91 with OracleStatementParser

use of com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser in project druid by alibaba.

the class OracleAlterTriggerTest2 method test_0.

public void test_0() throws Exception {
    //
    String sql = "alter TRIGGER RETL.TRG_COMPANY_SYNC compile";
    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("cdc.en_complaint_ipr_stat_fdt0")));
    Assert.assertEquals(0, visitor.getColumns().size());
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "*")));
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "YEAR")));
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "order_mode")));
}
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 92 with OracleStatementParser

use of com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser in project druid by alibaba.

the class OracleAlterViewTest method test_0.

public void test_0() throws Exception {
    //
    String sql = "alter VIEW ALIBABA1949.COMPANY_VIEW_2 compile";
    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("cdc.en_complaint_ipr_stat_fdt0")));
    Assert.assertEquals(0, visitor.getColumns().size());
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "*")));
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "YEAR")));
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("pivot_table", "order_mode")));
}
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 93 with OracleStatementParser

use of com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser in project druid by alibaba.

the class OracleBlockTest method test_0.

public void test_0() throws Exception {
    String sql = "BEGIN :RESULT := \"SYS\".\"DBMS_AQ_IMPORT_INTERNAL\".\"AQ_EXPORT_CHECK\"(:arg);  END;";
    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("departments")));
    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)

Example 94 with OracleStatementParser

use of com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser in project druid by alibaba.

the class OracleBlockTest12 method test_0.

public void test_0() throws Exception {
    String sql = "DECLARE" + "  emp_id        NUMBER(6);" + "  emp_lastname  VARCHAR2(25);" + "  emp_salary    NUMBER(8,2);" + "  emp_jobid     VARCHAR2(10);" + "BEGIN" + "  SELECT employee_id, last_name, salary, job_id" + "  INTO emp_id, emp_lastname, emp_salary, emp_jobid" + "  FROM employees" + "  WHERE employee_id = 120;" + "" + "  INSERT INTO emp_name (employee_id, last_name)" + "  VALUES (emp_id, emp_lastname); " + "  INSERT INTO emp_sal (employee_id, salary) " + "  VALUES (emp_id, emp_salary);" + "" + "  INSERT INTO emp_job (employee_id, job_id)" + "  VALUES (emp_id, emp_jobid);" + " " + "EXCEPTION" + "  WHEN DUP_VAL_ON_INDEX THEN" + "    ROLLBACK;" + "    DBMS_OUTPUT.PUT_LINE('Inserts were rolled back');" + //
    "END;";
    OracleStatementParser parser = new OracleStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    print(statementList);
    Assert.assertEquals(1, statementList.size());
    OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
    for (SQLStatement statement : statementList) {
        statement.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(4, visitor.getTables().size());
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("employees")));
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("emp_name")));
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("emp_sal")));
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("emp_job")));
    Assert.assertEquals(11, visitor.getColumns().size());
    Assert.assertEquals(1, visitor.getConditions().size());
//        Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("employees", "salary")));
}
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 95 with OracleStatementParser

use of com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser in project druid by alibaba.

the class OracleBlockTest14 method test_0.

public void test_0() throws Exception {
    String sql = //
    "DECLARE" + //
    "  emp_id        employees.employee_id%TYPE;" + //
    "  emp_lastname  employees.last_name%TYPE;" + //
    "  emp_salary    employees.salary%TYPE;" + //
    "" + //
    "BEGIN" + //
    "  SELECT employee_id, last_name, salary" + //
    "  INTO emp_id, emp_lastname, emp_salary" + //
    "  FROM employees" + //
    "  WHERE employee_id = 120;" + //
    "  SAVEPOINT my_savepoint;" + //
    " " + //
    "  UPDATE emp_name" + //
    "  SET salary = salary * 1.1" + //
    "  WHERE employee_id = emp_id;" + //
    " " + //
    "  DELETE FROM emp_name" + //
    "  WHERE employee_id = 130;" + //
    " " + //
    "  SAVEPOINT my_savepoint;" + //
    " " + //
    "  INSERT INTO emp_name (employee_id, last_name, salary)" + //
    "  VALUES (emp_id, emp_lastname, emp_salary);" + //
    "" + //
    "EXCEPTION" + //
    "  WHEN DUP_VAL_ON_INDEX THEN" + //
    "    ROLLBACK TO my_savepoint;" + //
    "    DBMS_OUTPUT.PUT_LINE('Transaction rolled back.');" + //
    "END;";
    OracleStatementParser parser = new OracleStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    print(statementList);
    Assert.assertEquals(1, statementList.size());
    OracleSchemaStatVisitor visitor = new OracleSchemaStatVisitor();
    for (SQLStatement statement : statementList) {
        statement.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(2, visitor.getTables().size());
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("employees")));
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("emp_name")));
    Assert.assertEquals(7, visitor.getColumns().size());
    Assert.assertEquals(3, visitor.getConditions().size());
    Assert.assertEquals(1, visitor.getRelationships().size());
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("employees", "salary")));
}
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

OracleStatementParser (com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser)313 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)273 OracleSchemaStatVisitor (com.alibaba.druid.sql.dialect.oracle.visitor.OracleSchemaStatVisitor)254 SQLSelectStatement (com.alibaba.druid.sql.ast.statement.SQLSelectStatement)39 Column (com.alibaba.druid.stat.TableStat.Column)19 OracleOutputVisitor (com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor)11 SQLStatementParser (com.alibaba.druid.sql.parser.SQLStatementParser)4 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)3 SQLSelectQueryBlock (com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock)3 OracleParameterizedOutputVisitor (com.alibaba.druid.sql.dialect.oracle.visitor.OracleParameterizedOutputVisitor)3 SQLMergeStatement (com.alibaba.druid.sql.ast.statement.SQLMergeStatement)2 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)2 Condition (com.alibaba.druid.stat.TableStat.Condition)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 ArrayList (java.util.ArrayList)2 SQLOrderBy (com.alibaba.druid.sql.ast.SQLOrderBy)1 SQLInListExpr (com.alibaba.druid.sql.ast.expr.SQLInListExpr)1 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)1