Search in sources :

Example 1 with DB2SchemaStatVisitor

use of com.alibaba.druid.sql.dialect.db2.visitor.DB2SchemaStatVisitor in project druid by alibaba.

the class DB2DropSequenceTest_0 method test_0.

public void test_0() throws Exception {
    String sql = "drop sequence sales1_seq";
    DB2StatementParser parser = new DB2StatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement stmt = statementList.get(0);
    print(statementList);
    Assert.assertEquals(1, statementList.size());
    DB2SchemaStatVisitor visitor = new DB2SchemaStatVisitor();
    stmt.accept(visitor);
    //        System.out.println("Tables : " + visitor.getTables());
    //        System.out.println("fields : " + visitor.getColumns());
    //        System.out.println("coditions : " + visitor.getConditions());
    //        System.out.println("orderBy : " + visitor.getOrderByColumns());
    Assert.assertEquals(0, visitor.getTables().size());
    Assert.assertEquals(0, visitor.getColumns().size());
    Assert.assertEquals(0, visitor.getConditions().size());
    //        Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("A")));
    //         Assert.assertTrue(visitor.getColumns().contains(new Column("A", "F_0201")));
    // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "first_name")));
    // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "full_name")));
    //
    Assert.assertEquals(//
    "DROP SEQUENCE sales1_seq", SQLUtils.toSQLString(stmt, JdbcConstants.DB2));
    //
    Assert.assertEquals(//
    "drop sequence sales1_seq", SQLUtils.toSQLString(stmt, JdbcConstants.DB2, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
}
Also used : DB2StatementParser(com.alibaba.druid.sql.dialect.db2.parser.DB2StatementParser) DB2SchemaStatVisitor(com.alibaba.druid.sql.dialect.db2.visitor.DB2SchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 2 with DB2SchemaStatVisitor

use of com.alibaba.druid.sql.dialect.db2.visitor.DB2SchemaStatVisitor in project druid by alibaba.

the class DB2MergeTest method test_0.

public void test_0() throws Exception {
    String sql = "MERGE INTO product AS T " + "      USING sales AS S" + "    ON S.id = T.id" + "  WHEN MATCHED THEN UPDATE SET inventory = T.inventory - S.sold;";
    DB2StatementParser parser = new DB2StatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement stmt = statementList.get(0);
    print(statementList);
    Assert.assertEquals(1, statementList.size());
    DB2SchemaStatVisitor visitor = new DB2SchemaStatVisitor();
    stmt.accept(visitor);
    //        System.out.println("Tables : " + visitor.getTables());
    //        System.out.println("fields : " + visitor.getColumns());
    //        System.out.println("coditions : " + visitor.getConditions());
    //        System.out.println("orderBy : " + visitor.getOrderByColumns());
    Assert.assertEquals(2, visitor.getTables().size());
    Assert.assertEquals(4, visitor.getColumns().size());
    Assert.assertEquals(2, visitor.getConditions().size());
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("sales")));
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("product")));
    //         Assert.assertTrue(visitor.getColumns().contains(new Column("DSN8B10.EMP", "WORKDEPT")));
    // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "first_name")));
    // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "full_name")));
    Assert.assertEquals("MERGE INTO product T" + "\nUSING sales S ON (S.id = T.id) " + //
    "\nWHEN MATCHED THEN UPDATE SET inventory = T.inventory - S.sold", SQLUtils.toSQLString(stmt, JdbcConstants.DB2));
    Assert.assertEquals("merge into product T" + "\nusing sales S on (S.id = T.id) " + //
    "\nwhen matched then update set inventory = T.inventory - S.sold", SQLUtils.toSQLString(stmt, JdbcConstants.DB2, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
}
Also used : DB2StatementParser(com.alibaba.druid.sql.dialect.db2.parser.DB2StatementParser) DB2SchemaStatVisitor(com.alibaba.druid.sql.dialect.db2.visitor.DB2SchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 3 with DB2SchemaStatVisitor

use of com.alibaba.druid.sql.dialect.db2.visitor.DB2SchemaStatVisitor in project druid by alibaba.

the class DB2SelectTest_6 method test_0.

public void test_0() throws Exception {
    String sql = "SELECT all id FROM DSN81010.EMP;";
    DB2StatementParser parser = new DB2StatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement stmt = statementList.get(0);
    print(statementList);
    Assert.assertEquals(1, statementList.size());
    DB2SchemaStatVisitor visitor = new DB2SchemaStatVisitor();
    stmt.accept(visitor);
    //        System.out.println("Tables : " + visitor.getTables());
    //        System.out.println("fields : " + visitor.getColumns());
    //        System.out.println("coditions : " + visitor.getConditions());
    //        System.out.println("orderBy : " + visitor.getOrderByColumns());
    Assert.assertEquals(1, visitor.getTables().size());
    Assert.assertEquals(1, visitor.getColumns().size());
    Assert.assertEquals(0, visitor.getConditions().size());
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("DSN81010.EMP")));
    // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "last_name")));
    // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "first_name")));
    // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "full_name")));
    Assert.assertEquals(//
    "SELECT ALL id" + //
    "\nFROM DSN81010.EMP", SQLUtils.toSQLString(stmt, JdbcConstants.DB2));
    Assert.assertEquals(//
    "select all id" + //
    "\nfrom DSN81010.EMP", SQLUtils.toSQLString(stmt, JdbcConstants.DB2, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
}
Also used : DB2StatementParser(com.alibaba.druid.sql.dialect.db2.parser.DB2StatementParser) DB2SchemaStatVisitor(com.alibaba.druid.sql.dialect.db2.visitor.DB2SchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 4 with DB2SchemaStatVisitor

use of com.alibaba.druid.sql.dialect.db2.visitor.DB2SchemaStatVisitor in project druid by alibaba.

the class DB2SelectTest_7 method test_0.

public void test_0() throws Exception {
    String sql = "SELECT distinct id FROM DSN81010.EMP;";
    DB2StatementParser parser = new DB2StatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement stmt = statementList.get(0);
    print(statementList);
    Assert.assertEquals(1, statementList.size());
    DB2SchemaStatVisitor visitor = new DB2SchemaStatVisitor();
    stmt.accept(visitor);
    //        System.out.println("Tables : " + visitor.getTables());
    //        System.out.println("fields : " + visitor.getColumns());
    //        System.out.println("coditions : " + visitor.getConditions());
    //        System.out.println("orderBy : " + visitor.getOrderByColumns());
    Assert.assertEquals(1, visitor.getTables().size());
    Assert.assertEquals(1, visitor.getColumns().size());
    Assert.assertEquals(0, visitor.getConditions().size());
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("DSN81010.EMP")));
    // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "last_name")));
    // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "first_name")));
    // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "full_name")));
    Assert.assertEquals(//
    "SELECT DISTINCT id" + //
    "\nFROM DSN81010.EMP", SQLUtils.toSQLString(stmt, JdbcConstants.DB2));
    Assert.assertEquals(//
    "select distinct id" + //
    "\nfrom DSN81010.EMP", SQLUtils.toSQLString(stmt, JdbcConstants.DB2, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
}
Also used : DB2StatementParser(com.alibaba.druid.sql.dialect.db2.parser.DB2StatementParser) DB2SchemaStatVisitor(com.alibaba.druid.sql.dialect.db2.visitor.DB2SchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 5 with DB2SchemaStatVisitor

use of com.alibaba.druid.sql.dialect.db2.visitor.DB2SchemaStatVisitor in project druid by alibaba.

the class DB2TruncateTest method test_0.

public void test_0() throws Exception {
    String sql = "TRUNCATE TASK_AICSFSM_QUERY_BATCH_TEMP IMMEDIATE";
    DB2StatementParser parser = new DB2StatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement stmt = statementList.get(0);
    print(statementList);
    Assert.assertEquals(1, statementList.size());
    DB2SchemaStatVisitor visitor = new DB2SchemaStatVisitor();
    stmt.accept(visitor);
    //        System.out.println("Tables : " + visitor.getTables());
    //        System.out.println("fields : " + visitor.getColumns());
    //        System.out.println("coditions : " + visitor.getConditions());
    //        System.out.println("orderBy : " + visitor.getOrderByColumns());
    Assert.assertEquals(1, visitor.getTables().size());
    Assert.assertEquals(0, visitor.getColumns().size());
    Assert.assertEquals(0, visitor.getConditions().size());
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("TASK_AICSFSM_QUERY_BATCH_TEMP")));
    //         Assert.assertTrue(visitor.getColumns().contains(new Column("A", "F_0201")));
    // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "first_name")));
    // Assert.assertTrue(visitor.getColumns().contains(new Column("mytable", "full_name")));
    //
    Assert.assertEquals(//
    "TRUNCATE TABLE TASK_AICSFSM_QUERY_BATCH_TEMP IMMEDIATE", SQLUtils.toSQLString(stmt, JdbcConstants.DB2));
    //
    Assert.assertEquals(//
    "truncate table TASK_AICSFSM_QUERY_BATCH_TEMP immediate", SQLUtils.toSQLString(stmt, JdbcConstants.DB2, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION));
}
Also used : DB2StatementParser(com.alibaba.druid.sql.dialect.db2.parser.DB2StatementParser) DB2SchemaStatVisitor(com.alibaba.druid.sql.dialect.db2.visitor.DB2SchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Aggregations

SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)33 DB2StatementParser (com.alibaba.druid.sql.dialect.db2.parser.DB2StatementParser)33 DB2SchemaStatVisitor (com.alibaba.druid.sql.dialect.db2.visitor.DB2SchemaStatVisitor)33 Column (com.alibaba.druid.stat.TableStat.Column)8