Search in sources :

Example 36 with SQLCharExpr

use of com.alibaba.druid.sql.ast.expr.SQLCharExpr in project Mycat-Server by MyCATApache.

the class MycatSchemaStatVisitor method visit.

@Override
public boolean visit(SQLBetweenExpr x) {
    String begin = null;
    if (x.beginExpr instanceof SQLCharExpr) {
        begin = (String) ((SQLCharExpr) x.beginExpr).getValue();
    } else {
        begin = x.beginExpr.toString();
    }
    String end = null;
    if (x.endExpr instanceof SQLCharExpr) {
        end = (String) ((SQLCharExpr) x.endExpr).getValue();
    } else {
        end = x.endExpr.toString();
    }
    Column column = getColumn(x);
    if (column == null) {
        return true;
    }
    Condition condition = null;
    for (Condition item : this.getConditions()) {
        if (item.getColumn().equals(column) && item.getOperator().equals("between")) {
            condition = item;
            break;
        }
    }
    if (condition == null) {
        condition = new Condition();
        condition.setColumn(column);
        condition.setOperator("between");
        this.conditions.add(condition);
    }
    condition.getValues().add(begin);
    condition.getValues().add(end);
    return true;
}
Also used : Condition(com.alibaba.druid.stat.TableStat.Condition) SQLCharExpr(com.alibaba.druid.sql.ast.expr.SQLCharExpr) Column(com.alibaba.druid.stat.TableStat.Column)

Example 37 with SQLCharExpr

use of com.alibaba.druid.sql.ast.expr.SQLCharExpr in project Mycat-Server by MyCATApache.

the class RouterUtil method changeCreateTable.

private static String changeCreateTable(SchemaConfig schema, String tableName, String sql) {
    if (schema.getTables().containsKey(tableName)) {
        MySqlStatementParser parser = new MySqlStatementParser(sql);
        SQLStatement insertStatement = parser.parseStatement();
        if (insertStatement instanceof MySqlCreateTableStatement) {
            TableConfig tableConfig = schema.getTables().get(tableName);
            AbstractPartitionAlgorithm algorithm = tableConfig.getRule().getRuleAlgorithm();
            if (algorithm instanceof SlotFunction) {
                SQLColumnDefinition column = new SQLColumnDefinition();
                column.setDataType(new SQLCharacterDataType("int"));
                column.setName(new SQLIdentifierExpr("_slot"));
                column.setComment(new SQLCharExpr("自动迁移算法slot,禁止修改"));
                ((SQLCreateTableStatement) insertStatement).getTableElementList().add(column);
                return insertStatement.toString();
            }
        }
    }
    return sql;
}
Also used : AbstractPartitionAlgorithm(io.mycat.route.function.AbstractPartitionAlgorithm) SQLCharExpr(com.alibaba.druid.sql.ast.expr.SQLCharExpr) SQLCharacterDataType(com.alibaba.druid.sql.ast.statement.SQLCharacterDataType) TableConfig(io.mycat.config.model.TableConfig) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) MySqlCreateTableStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement) SQLColumnDefinition(com.alibaba.druid.sql.ast.statement.SQLColumnDefinition) SlotFunction(io.mycat.route.function.SlotFunction)

Aggregations

SQLCharExpr (com.alibaba.druid.sql.ast.expr.SQLCharExpr)37 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)16 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)15 SQLIntegerExpr (com.alibaba.druid.sql.ast.expr.SQLIntegerExpr)8 SQLLiteralExpr (com.alibaba.druid.sql.ast.expr.SQLLiteralExpr)8 SQLColumnDefinition (com.alibaba.druid.sql.ast.statement.SQLColumnDefinition)8 SQLCharacterDataType (com.alibaba.druid.sql.ast.statement.SQLCharacterDataType)7 SQLMethodInvokeExpr (com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr)6 TableConfig (io.mycat.config.model.TableConfig)6 AbstractPartitionAlgorithm (io.mycat.route.function.AbstractPartitionAlgorithm)6 SlotFunction (io.mycat.route.function.SlotFunction)6 SQLNonTransientException (java.sql.SQLNonTransientException)6 ParserException (com.alibaba.druid.sql.parser.ParserException)5 SQLName (com.alibaba.druid.sql.ast.SQLName)4 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)4 MySqlCreateTableStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement)4 RouteResultsetNode (io.mycat.route.RouteResultsetNode)4 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)3 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)3 SQLNCharExpr (com.alibaba.druid.sql.ast.expr.SQLNCharExpr)3