Search in sources :

Example 56 with DbType

use of com.alibaba.druid.DbType in project druid by alibaba.

the class JdbcUtils_driver method test_log4jdbc_derby.

public void test_log4jdbc_derby() throws Exception {
    String jdbcUrl = "jdbc:log4jdbc:derby://localhost:1527//db-derby-10.2.2.0-bin/databases/MyDatabase";
    DbType dbType = JdbcUtils.getDbTypeRaw(jdbcUrl, "net.sf.log4jdbc.sql.jdbcapi.DriverSpy");
    assertEquals("not support log4jdbc mysql, url like jdbc:log4jdbc:derby:...", DbType.derby, dbType);
}
Also used : DbType(com.alibaba.druid.DbType)

Example 57 with DbType

use of com.alibaba.druid.DbType in project druid by alibaba.

the class JdbcUtils_driver method test_log4jdbc_mysql.

public void test_log4jdbc_mysql() {
    String jdbcUrl = "jdbc:log4jdbc:mysql://localhost:8066/test";
    DbType dbType = JdbcUtils.getDbTypeRaw(jdbcUrl, null);
    assertEquals("not support log4jdbc mysql, url like jdbc:log4jdbc:mysql:...", DbType.mysql, dbType);
}
Also used : DbType(com.alibaba.druid.DbType)

Example 58 with DbType

use of com.alibaba.druid.DbType in project druid by alibaba.

the class JdbcUtils_driver method test_log4jdbc_mysql2.

public void test_log4jdbc_mysql2() throws Exception {
    String jdbcUrl = "jdbc:log4jdbc:mysql://localhost:8066/test";
    DbType dbType = JdbcUtils.getDbTypeRaw(jdbcUrl, "net.sf.log4jdbc.DriverSpy");
    assertEquals("not support log4jdbc mysql, url like jdbc:log4jdbc:mysql:...", DbType.mysql, dbType);
}
Also used : DbType(com.alibaba.druid.DbType)

Example 59 with DbType

use of com.alibaba.druid.DbType in project druid by alibaba.

the class SchemaStatTest method test_schemaStat.

public void test_schemaStat() throws Exception {
    String sql = "select " + " create_time_dd          as  来电日期" + " from alisec_app.adl_tb_wing_rubbish_laidian_new_reason_realname_fdt  " + " order by   来电日期  desc  limit  30;";
    DbType dbType = JdbcConstants.ODPS;
    SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
    SQLStatement stmt = parser.parseStatementList().get(0);
    SchemaStatVisitor statVisitor = SQLUtils.createSchemaStatVisitor(dbType);
    stmt.accept(statVisitor);
    System.out.println(statVisitor.getColumns());
    Assert.assertEquals(1, statVisitor.getColumns().size());
}
Also used : SQLStatementParser(com.alibaba.druid.sql.parser.SQLStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) DbType(com.alibaba.druid.DbType) SchemaStatVisitor(com.alibaba.druid.sql.visitor.SchemaStatVisitor)

Example 60 with DbType

use of com.alibaba.druid.DbType in project druid by alibaba.

the class SchemaStatTest11 method test_schemaStat.

public void test_schemaStat() throws Exception {
    String sql = "select a.id, b.name from (select * from table1) a inner join table2 b on a.id = b.id";
    DbType dbType = JdbcConstants.ORACLE;
    SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
    SQLStatement stmt = parser.parseStatementList().get(0);
    System.out.println(stmt);
    SchemaStatVisitor statVisitor = SQLUtils.createSchemaStatVisitor(dbType);
    stmt.accept(statVisitor);
    Set<TableStat.Relationship> relationships = statVisitor.getRelationships();
    for (TableStat.Relationship relationship : relationships) {
        // table1.id = table2.id
        System.out.println(relationship);
    }
    System.out.println(statVisitor.getColumns());
    // group by
    System.out.println(statVisitor.getGroupByColumns());
    // group by
    System.out.println("relationships : " + statVisitor.getRelationships());
    System.out.println(statVisitor.getConditions());
    assertEquals(1, relationships.size());
    assertEquals(4, statVisitor.getColumns().size());
    assertEquals(2, statVisitor.getConditions().size());
    assertEquals(0, statVisitor.getFunctions().size());
    assertTrue(statVisitor.containsColumn("table1", "*"));
    assertTrue(statVisitor.containsColumn("table1", "id"));
    assertTrue(statVisitor.containsColumn("table2", "id"));
    assertTrue(statVisitor.containsColumn("table2", "name"));
}
Also used : SQLStatementParser(com.alibaba.druid.sql.parser.SQLStatementParser) TableStat(com.alibaba.druid.stat.TableStat) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) DbType(com.alibaba.druid.DbType) SchemaStatVisitor(com.alibaba.druid.sql.visitor.SchemaStatVisitor)

Aggregations

DbType (com.alibaba.druid.DbType)114 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)76 SQLStatementParser (com.alibaba.druid.sql.parser.SQLStatementParser)70 ArrayList (java.util.ArrayList)50 SQLASTOutputVisitor (com.alibaba.druid.sql.visitor.SQLASTOutputVisitor)45 SchemaStatVisitor (com.alibaba.druid.sql.visitor.SchemaStatVisitor)21 TableStat (com.alibaba.druid.stat.TableStat)10 JSONArray (com.alibaba.fastjson.JSONArray)10 MySqlExportParameterVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlExportParameterVisitor)5 ExportParameterVisitor (com.alibaba.druid.sql.visitor.ExportParameterVisitor)5 ParserException (com.alibaba.druid.sql.parser.ParserException)4 Map (java.util.Map)4 JdbcParameter (com.alibaba.druid.proxy.jdbc.JdbcParameter)2 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)2 SQLDeleteStatement (com.alibaba.druid.sql.ast.statement.SQLDeleteStatement)2 SQLSelectQueryBlock (com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock)2 SQLSelectStatement (com.alibaba.druid.sql.ast.statement.SQLSelectStatement)2 SQLUpdateStatement (com.alibaba.druid.sql.ast.statement.SQLUpdateStatement)2 MySqlSchemaStatVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor)2 OracleSQLObject (com.alibaba.druid.sql.dialect.oracle.ast.OracleSQLObject)2