Search in sources :

Example 6 with MycatSchemaStatVisitor

use of io.mycat.route.parser.druid.MycatSchemaStatVisitor in project Mycat-Server by MyCATApache.

the class MycatSchemaStatVisitorTest method getConditionList.

private List<List<Condition>> getConditionList(String sql) {
    SQLStatementParser parser = null;
    parser = new MySqlStatementParser(sql);
    MycatSchemaStatVisitor visitor = null;
    SQLStatement statement = null;
    //解析出现问题统一抛SQL语法错误
    try {
        statement = parser.parseStatement();
        visitor = new MycatSchemaStatVisitor();
    } catch (Exception e) {
        e.printStackTrace();
    }
    statement.accept(visitor);
    List<List<Condition>> mergedConditionList = new ArrayList<List<Condition>>();
    if (visitor.hasOrCondition()) {
        //包含or语句
        //TODO
        //根据or拆分
        mergedConditionList = visitor.splitConditions();
    } else {
        //不包含OR语句
        mergedConditionList.add(visitor.getConditions());
    }
    return mergedConditionList;
}
Also used : Condition(com.alibaba.druid.stat.TableStat.Condition) SQLStatementParser(com.alibaba.druid.sql.parser.SQLStatementParser) MycatSchemaStatVisitor(io.mycat.route.parser.druid.MycatSchemaStatVisitor) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Aggregations

SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)6 SQLStatementParser (com.alibaba.druid.sql.parser.SQLStatementParser)6 MycatSchemaStatVisitor (io.mycat.route.parser.druid.MycatSchemaStatVisitor)6 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)5 DruidShardingParseInfo (io.mycat.route.parser.druid.DruidShardingParseInfo)3 MycatStatementParser (io.mycat.route.parser.druid.MycatStatementParser)3 RouteResultset (io.mycat.route.RouteResultset)2 RouteCalculateUnit (io.mycat.route.parser.druid.RouteCalculateUnit)2 SQLSyntaxErrorException (java.sql.SQLSyntaxErrorException)2 SQLDeleteStatement (com.alibaba.druid.sql.ast.statement.SQLDeleteStatement)1 SQLInsertStatement (com.alibaba.druid.sql.ast.statement.SQLInsertStatement)1 SQLSelectStatement (com.alibaba.druid.sql.ast.statement.SQLSelectStatement)1 SQLUpdateStatement (com.alibaba.druid.sql.ast.statement.SQLUpdateStatement)1 MySqlInsertStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlInsertStatement)1 MySqlReplaceStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlReplaceStatement)1 SchemaStatVisitor (com.alibaba.druid.sql.visitor.SchemaStatVisitor)1 Condition (com.alibaba.druid.stat.TableStat.Condition)1 LayerCachePool (io.mycat.cache.LayerCachePool)1 SchemaConfig (io.mycat.config.model.SchemaConfig)1 UserConfig (io.mycat.config.model.UserConfig)1