示例#1
0
 static int bool_double(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObBoolType);
     out.set_double(static_cast<double> (in.get_bool()));
     return OB_SUCCESS;
 }
示例#2
0
 static int mtime_double(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObModifyTimeType);
     out.set_double(static_cast<double> (in.get_mtime()));
     return OB_SUCCESS;
 }
示例#3
0
 static int pdatetime_double(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObPreciseDateTimeType);
     out.set_double(static_cast<double> (in.get_precise_datetime()));
     return OB_SUCCESS;
 }
TEST_F(ObObjCastTest, double_to_xxx)
{
    ObExprObj in;
    char buf[128];
    double cases[] = {-1.1, 0.0, 1.1};
    const char *dec_expected[] = {"-1.100000", "0", "1.100000"};
    for (int64_t i = 0; i < static_cast<int64_t>(ARRAYSIZEOF(cases)); ++i)
    {
        double v = cases[i];
        in.set_double(v);
        snprintf(buf, 128, "%lf", v);

        MY_EXPECT(ObDoubleType, in, ObNullType, v, buf);
        MY_EXPECT(ObDoubleType, in, ObIntType, v, buf);
        MY_EXPECT(ObDoubleType, in, ObFloatType, v, buf);
        MY_EXPECT(ObDoubleType, in, ObDoubleType, v, buf);
        MY_EXPECT(ObDoubleType, in, ObDateTimeType, v, buf);
        MY_EXPECT(ObDoubleType, in, ObPreciseDateTimeType, v, buf);
        MY_EXPECT(ObDoubleType, in, ObVarcharType, v, buf);
        MY_EXPECT(ObDoubleType, in, ObSeqType, v, buf);
        MY_EXPECT(ObDoubleType, in, ObCreateTimeType, v, buf);
        MY_EXPECT(ObDoubleType, in, ObModifyTimeType, v, buf);
        MY_EXPECT(ObDoubleType, in, ObExtendType, v, buf);
        MY_EXPECT(ObDoubleType, in, ObBoolType, v, buf);
        MY_EXPECT(ObDoubleType, in, ObDecimalType, v, dec_expected[i]);
    }
}
示例#5
0
 static int varchar_double(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     int ret = OB_SUCCESS;
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObVarcharType);
     double value = 0.0;
     ret = varchar_scanf(in, 1, "%lf", &value);
     if (OB_SUCCESS == ret)
     {
         out.set_double(value);
     }
     else
     {
         out.set_double(0.0);
         ret = OB_SUCCESS;
     }
     return ret;
 }
示例#6
0
 static int decimal_double(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObDecimalType);
     // decimal -> string -> float
     char buf[ObNumber::MAX_PRINTABLE_SIZE];
     memset(buf, 0, ObNumber::MAX_PRINTABLE_SIZE);
     in.get_decimal().to_string(buf, ObNumber::MAX_PRINTABLE_SIZE);
     double v = 0.0;
     if (1 == sscanf(buf, "%lf", &v))
     {
         out.set_double(v);
     }
     else
     {
         out.set_double(0.0);
     }
     return OB_SUCCESS;
 }