Search in sources :

Example 76 with OracleStatementParser

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

the class OracleCreateDbLinkTest method test_0.

public void test_0() throws Exception {
    //
    String sql = "CREATE PUBLIC DATABASE LINK remote USING 'remote'; ";
    OracleStatementParser parser = new OracleStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement statement = statementList.get(0);
    print(statementList);
    Assert.assertEquals("CREATE PUBLIC DATABASE LINK remote USING '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 77 with OracleStatementParser

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

the class OracleCreateDbLinkTest1 method test_0.

public void test_0() throws Exception {
    //
    String sql = //
    "create database link db_link connect to \"xxx\" identified by \"xxx\" using '(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl)))'";
    OracleStatementParser parser = new OracleStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement stmt = statementList.get(0);
    print(statementList);
    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());
    //        System.out.println("orderBy : " + visitor.getOrderByColumns());
    Assert.assertEquals(0, visitor.getTables().size());
    Assert.assertEquals(0, visitor.getColumns().size());
    {
        String text = SQLUtils.toOracleString(stmt);
        Assert.assertEquals("CREATE DATABASE LINK db_link CONNECT TO \"xxx\" IDENTIFIED BY xxx USING '(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl)))'", text);
    }
    {
        String text = SQLUtils.toOracleString(stmt, SQLUtils.DEFAULT_LCASE_FORMAT_OPTION);
        Assert.assertEquals("create database link db_link connect to \"xxx\" identified by xxx using '(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl)))'", text);
    }
// Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("acduser.vw_acd_info", "xzqh")));
// Assert.assertTrue(visitor.getOrderByColumns().contains(new TableStat.Column("employees", "last_name")));
}
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 78 with OracleStatementParser

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

the class OracleCreateTableTest38 method test_types.

public void test_types() throws Exception {
    //
    String sql = "CREATE TABLE list_customers " + "   ( customer_id             NUMBER(6)" + "   , cust_first_name         VARCHAR2(20) " + "   , cust_last_name          VARCHAR2(20)" + "   , cust_address            CUST_ADDRESS_TYP" + "   , nls_territory           VARCHAR2(30)" + "   , cust_email              VARCHAR2(40))" + "   PARTITION BY LIST (nls_territory) (" + "   PARTITION asia VALUES ('CHINA', 'THAILAND')," + "   PARTITION europe VALUES ('GERMANY', 'ITALY', 'SWITZERLAND')," + "   PARTITION west VALUES ('AMERICA')," + "   PARTITION east VALUES ('INDIA')," + "   PARTITION rest VALUES (DEFAULT));";
    OracleStatementParser parser = new OracleStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement stmt = statementList.get(0);
    print(statementList);
    Assert.assertEquals(1, statementList.size());
    Assert.assertEquals("CREATE TABLE list_customers (" + "\n\tcustomer_id NUMBER(6)," + "\n\tcust_first_name VARCHAR2(20)," + "\n\tcust_last_name VARCHAR2(20)," + "\n\tcust_address CUST_ADDRESS_TYP," + "\n\tnls_territory VARCHAR2(30)," + "\n\tcust_email VARCHAR2(40)" + "\n)" + "\nPARTITION BY LIST (nls_territory)" + "\n(" + "\n\tPARTITION asia VALUES ('CHINA', 'THAILAND'), " + "\n\tPARTITION europe VALUES ('GERMANY', 'ITALY', 'SWITZERLAND'), " + "\n\tPARTITION west VALUES ('AMERICA'), " + "\n\tPARTITION east VALUES ('INDIA'), " + "\n\tPARTITION rest VALUES (DEFAULT)" + //
    "\n)", SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
    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());
    System.out.println("orderBy : " + visitor.getOrderByColumns());
    Assert.assertEquals(1, visitor.getTables().size());
    Assert.assertEquals(6, visitor.getColumns().size());
    Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("list_customers", "customer_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 79 with OracleStatementParser

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

the class OracleCreateTableTest4 method test_0.

public void test_0() throws Exception {
    //
    String sql = "create table tbd_qi_xiaq_100961 tablespace tbd_data as select * /*1*/from product where company_id=10239004 ";
    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(2, visitor.getTables().size());
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("product")));
    Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("tbd_qi_xiaq_100961")));
    Assert.assertEquals(2, 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 80 with OracleStatementParser

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

the class OracleCreateTableTest40 method test_types.

public void test_types() throws Exception {
    //
    String sql = "CREATE TABLE customers_part (" + "   customer_id        NUMBER(6)," + "   cust_first_name    VARCHAR2(20)," + "   cust_last_name     VARCHAR2(20)," + "   nls_territory      VARCHAR2(30)," + "   credit_limit       NUMBER(9,2)) " + "   PARTITION BY RANGE (credit_limit)" + "   SUBPARTITION BY LIST (nls_territory)" + "      SUBPARTITION TEMPLATE " + "         (SUBPARTITION east  VALUES " + "            ('CHINA', 'JAPAN', 'INDIA', 'THAILAND')," + "          SUBPARTITION west VALUES " + "             ('AMERICA', 'GERMANY', 'ITALY', 'SWITZERLAND')," + "          SUBPARTITION other VALUES (DEFAULT))" + "      (PARTITION p1 VALUES LESS THAN (1000)," + "       PARTITION p2 VALUES LESS THAN (2500)," + "       PARTITION p3 VALUES LESS THAN (MAXVALUE));";
    OracleStatementParser parser = new OracleStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement stmt = statementList.get(0);
    print(statementList);
    Assert.assertEquals(1, statementList.size());
    Assert.assertEquals("CREATE TABLE customers_part (" + "\n\tcustomer_id NUMBER(6)," + "\n\tcust_first_name VARCHAR2(20)," + "\n\tcust_last_name VARCHAR2(20)," + "\n\tnls_territory VARCHAR2(30)," + "\n\tcredit_limit NUMBER(9, 2)" + "\n)" + "\nPARTITION BY RANGE (credit_limit)" + "\nSUBPARTITION BY HASH (nls_territory)" + "\n\tSUBPARTITION TEMPLATE (" + "\n\t\tSUBPARTITION east VALUES ('CHINA', 'JAPAN', 'INDIA', 'THAILAND')," + "\n\t\tSUBPARTITION west VALUES ('AMERICA', 'GERMANY', 'ITALY', 'SWITZERLAND')," + "\n\t\tSUBPARTITION other VALUES (DEFAULT)" + "\n\t)" + "\n(" + "\n\tPARTITION p1 VALUES LESS THAN (1000)," + "\n\tPARTITION p2 VALUES LESS THAN (2500)," + "\n\tPARTITION p3 VALUES LESS THAN (MAXVALUE)" + //
    "\n)", SQLUtils.toSQLString(stmt, JdbcConstants.ORACLE));
    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());
    System.out.println("orderBy : " + visitor.getOrderByColumns());
    Assert.assertEquals(1, visitor.getTables().size());
    Assert.assertEquals(5, visitor.getColumns().size());
    Assert.assertTrue(visitor.getColumns().contains(new TableStat.Column("customers_part", "customer_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

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