Exemple #1
0
 static int bool_int(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObBoolType);
     out.set_int(static_cast<int64_t> (in.get_bool()));
     return OB_SUCCESS;
 }
Exemple #2
0
 static int mtime_int(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObModifyTimeType);
     out.set_int(static_cast<int64_t> (in.get_mtime()));
     return OB_SUCCESS;
 }
Exemple #3
0
 static int pdatetime_int(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObPreciseDateTimeType);
     out.set_int(static_cast<int64_t> (in.get_precise_datetime()));
     return OB_SUCCESS;
 }
Exemple #4
0
 static int varchar_int(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     int ret = OB_SUCCESS;
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObVarcharType);
     int64_t value = 0;
     ret = varchar_scanf(in, 1, "%ld", &value);
     if (OB_SUCCESS == ret)
     {
         out.set_int(value);
     }
     else
     {
         out.set_int(0);
         ret = OB_SUCCESS;
     }
     return ret;
 }
Exemple #5
0
 static int decimal_int(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     int ret = OB_SUCCESS;
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObDecimalType);
     int64_t i64 = 0;
     if (OB_SUCCESS != (ret = in.get_decimal().cast_to_int64(i64)))
     {
         jlog(WARNING, "failed to cast to int64, err=%d", ret);
     }
     else
     {
         out.set_int(i64);
     }
     return ret;
 }
TEST_F(ObObjCastTest, int_to_xxx)
{
    ObExprObj in;
    char buf[128];
    for (int64_t i = -1; i < 2; ++i)
    {
        in.set_int(i);
        snprintf(buf, 128, "%ld", i);
        MY_EXPECT(ObIntType, in, ObNullType, i, buf);
        MY_EXPECT(ObIntType, in, ObIntType, i, buf);
        MY_EXPECT(ObIntType, in, ObFloatType, i, buf);
        MY_EXPECT(ObIntType, in, ObDoubleType, i, buf);
        MY_EXPECT(ObIntType, in, ObDateTimeType, i, buf);
        MY_EXPECT(ObIntType, in, ObPreciseDateTimeType, i, buf);
        MY_EXPECT(ObIntType, in, ObVarcharType, i, buf);
        MY_EXPECT(ObIntType, in, ObSeqType, i, buf);
        MY_EXPECT(ObIntType, in, ObCreateTimeType, i, buf);
        MY_EXPECT(ObIntType, in, ObModifyTimeType, i, buf);
        MY_EXPECT(ObIntType, in, ObExtendType, i, buf);
        MY_EXPECT(ObIntType, in, ObBoolType, i, buf);
        MY_EXPECT(ObIntType, in, ObDecimalType, i, buf);
    }
}