Search in sources :

Example 1 with FieldTypes

use of com.actiontech.dble.plan.common.item.FieldTypes in project dble by actiontech.

the class UnionHandler method unionFieldPacket.

private FieldPacket unionFieldPacket(FieldPacket fp1, FieldPacket fp2) {
    FieldPacket union = new FieldPacket();
    union.setCatalog(fp1.getCatalog());
    union.setCharsetIndex(fp1.getCharsetIndex());
    union.setDb(fp1.getDb());
    union.setDecimals((byte) Math.max(fp1.getDecimals(), fp2.getDecimals()));
    union.setDefinition(fp1.getDefinition());
    union.setFlags(fp1.getFlags() | fp2.getFlags());
    union.setLength(Math.max(fp1.getLength(), fp2.getLength()));
    FieldTypes fieldType1 = FieldTypes.valueOf(fp1.getType());
    FieldTypes fieldType2 = FieldTypes.valueOf(fp2.getType());
    FieldTypes mergeFieldType = FieldUtil.fieldTypeMerge(fieldType1, fieldType2);
    union.setType(mergeFieldType.numberValue());
    return union;
}
Also used : FieldTypes(com.actiontech.dble.plan.common.item.FieldTypes) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 2 with FieldTypes

use of com.actiontech.dble.plan.common.item.FieldTypes in project dble by actiontech.

the class GetDatetimeValue method get.

@Override
public long get(Item item, Item warnItem, BoolPtr isNull) {
    long value = 0;
    String str = null;
    if (item.isTemporal()) {
        value = item.valDateTemporal();
        isNull.set(item.isNullValue());
    } else {
        str = item.valStr();
        isNull.set(item.isNullValue());
    }
    if (isNull.get())
        return 0;
    if (str != null) {
        BoolPtr error = new BoolPtr(false);
        FieldTypes fType = warnItem.fieldType();
        MySQLTimestampType tType = fType == FieldTypes.MYSQL_TYPE_DATE ? MySQLTimestampType.MYSQL_TIMESTAMP_DATE : MySQLTimestampType.MYSQL_TIMESTAMP_DATETIME;
        value = MySQLcom.getDateFromStr(str, tType, error);
    }
    return value;
}
Also used : FieldTypes(com.actiontech.dble.plan.common.item.FieldTypes) BoolPtr(com.actiontech.dble.plan.common.ptr.BoolPtr) MySQLTimestampType(com.actiontech.dble.plan.common.time.MySQLTimestampType)

Example 3 with FieldTypes

use of com.actiontech.dble.plan.common.item.FieldTypes in project dble by actiontech.

the class ItemFuncMinMax method getTime.

@Override
public boolean getTime(MySQLTime ltime) {
    assert (fixed);
    if (compareAsDates) {
        LongPtr result = new LongPtr(0);
        cmpDatetimes(result);
        if (nullValue)
            return true;
        MyTime.timeFromLonglongPacked(ltime, datetimeItem.fieldType(), result.get());
        MyTime.datetimeToTime(ltime);
        return false;
    }
    FieldTypes i = fieldType();
    if (i == FieldTypes.MYSQL_TYPE_TIME) {
        LongPtr result = new LongPtr(0);
        cmpTimes(result);
        if (nullValue)
            return true;
        MyTime.timeFromLonglongTimePacked(ltime, result.get());
        return false;
    } else if (i == FieldTypes.MYSQL_TYPE_DATE || i == FieldTypes.MYSQL_TYPE_TIMESTAMP || i == FieldTypes.MYSQL_TYPE_DATETIME) {
        // Should have been processed in "compare_as_dates"
        assert (false);
        return getTimeFromNonTemporal(ltime);
    } else {
        return getTimeFromNonTemporal(ltime);
    }
}
Also used : LongPtr(com.actiontech.dble.plan.common.ptr.LongPtr) FieldTypes(com.actiontech.dble.plan.common.item.FieldTypes)

Example 4 with FieldTypes

use of com.actiontech.dble.plan.common.item.FieldTypes in project dble by actiontech.

the class ItemFuncMinMax method getDate.

@Override
public boolean getDate(MySQLTime ltime, long fuzzydate) {
    assert (fixed);
    if (compareAsDates) {
        LongPtr result = new LongPtr(0);
        cmpDatetimes(result);
        if (nullValue)
            return true;
        MyTime.timeFromLonglongPacked(ltime, datetimeItem.fieldType(), result.get());
        LongPtr warnings = new LongPtr(0);
        return MyTime.checkDate(ltime, ltime.isNonZeroDate(), fuzzydate, warnings);
    }
    FieldTypes i = fieldType();
    if (i == FieldTypes.MYSQL_TYPE_TIME) {
        return getDateFromTime(ltime);
    } else if (i == FieldTypes.MYSQL_TYPE_DATETIME || i == FieldTypes.MYSQL_TYPE_TIMESTAMP || i == FieldTypes.MYSQL_TYPE_DATE) {
        // Should have been processed in "compare_as_dates"
        assert (false);
        return getDateFromNonTemporal(ltime, fuzzydate);
    } else {
        return getDateFromNonTemporal(ltime, fuzzydate);
    }
}
Also used : LongPtr(com.actiontech.dble.plan.common.ptr.LongPtr) FieldTypes(com.actiontech.dble.plan.common.item.FieldTypes)

Example 5 with FieldTypes

use of com.actiontech.dble.plan.common.item.FieldTypes in project dble by actiontech.

the class ItemFuncNumhybrid method valStr.

@Override
public String valStr() {
    String str = null;
    if (hybridType == ItemResult.DECIMAL_RESULT) {
        BigDecimal val = decimalOp();
        if (val == null)
            // null is setstr = val.toString();
            return null;
    } else if (hybridType == ItemResult.INT_RESULT) {
        BigInteger nr = intOp();
        if (nullValue)
            return null;
        /* purecov: inspected */
        str = nr.toString();
    } else if (hybridType == ItemResult.REAL_RESULT) {
        BigDecimal nr = realOp();
        if (nullValue)
            return null;
        /* purecov: inspected */
        str = nr.toString();
    } else if (hybridType == ItemResult.STRING_RESULT) {
        FieldTypes i = fieldType();
        if (i == FieldTypes.MYSQL_TYPE_DATETIME || i == FieldTypes.MYSQL_TYPE_TIMESTAMP) {
            return valStringFromDatetime();
        } else if (i == FieldTypes.MYSQL_TYPE_DATE) {
            return valStringFromDate();
        } else if (i == FieldTypes.MYSQL_TYPE_TIME) {
            return valStringFromTime();
        }
        return strOp();
    }
    return str;
}
Also used : FieldTypes(com.actiontech.dble.plan.common.item.FieldTypes) BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal)

Aggregations

FieldTypes (com.actiontech.dble.plan.common.item.FieldTypes)8 LongPtr (com.actiontech.dble.plan.common.ptr.LongPtr)2 BigDecimal (java.math.BigDecimal)2 BigInteger (java.math.BigInteger)2 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)1 Item (com.actiontech.dble.plan.common.item.Item)1 BoolPtr (com.actiontech.dble.plan.common.ptr.BoolPtr)1 MySQLTimestampType (com.actiontech.dble.plan.common.time.MySQLTimestampType)1