Search in sources :

Example 1 with ItemCharTypecast

use of com.actiontech.dble.plan.common.item.function.castfunc.ItemCharTypecast in project dble by actiontech.

the class MySQLItemVisitor method endVisit.

@Override
public void endVisit(SQLCastExpr x) {
    Item a = getItem(x.getExpr());
    SQLDataType dataType = x.getDataType();
    if (dataType instanceof SQLCharacterDataType) {
        SQLCharacterDataType charType = (SQLCharacterDataType) dataType;
        String upType = charType.getName().toUpperCase();
        List<Integer> args = changeExprListToInt(charType.getArguments());
        String charSetName = charType.getCharSetName();
        if (upType.equals("CHAR")) {
            int len = -1;
            if (args.size() > 0) {
                len = args.get(0);
            }
            item = new ItemCharTypecast(a, len, charSetName);
        } else if (charSetName == null) {
            int len = -1;
            if (args.size() > 0) {
                len = args.get(0);
            }
            item = new ItemNCharTypecast(a, len);
        } else {
            throw new MySQLOutPutException(ErrorCode.ER_PARSE_ERROR, "", "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'character set " + charSetName + ")'");
        }
    } else {
        CastType castType = getCastType((SQLDataTypeImpl) dataType);
        item = ItemCreate.getInstance().createFuncCast(a, castType);
    }
    initName(x);
}
Also used : ItemNCharTypecast(com.actiontech.dble.plan.common.item.function.castfunc.ItemNCharTypecast) SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem) ItemCharTypecast(com.actiontech.dble.plan.common.item.function.castfunc.ItemCharTypecast) SQLCharacterDataType(com.alibaba.druid.sql.ast.statement.SQLCharacterDataType) CastType(com.actiontech.dble.plan.common.CastType) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Aggregations

CastType (com.actiontech.dble.plan.common.CastType)1 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)1 ItemCharTypecast (com.actiontech.dble.plan.common.item.function.castfunc.ItemCharTypecast)1 ItemNCharTypecast (com.actiontech.dble.plan.common.item.function.castfunc.ItemNCharTypecast)1 SQLCharacterDataType (com.alibaba.druid.sql.ast.statement.SQLCharacterDataType)1 SQLSelectOrderByItem (com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem)1