示例#1
0
 static int mtime_bool(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObModifyTimeType);
     out.set_bool(static_cast<bool> (in.get_mtime()));
     return OB_SUCCESS;
 }
示例#2
0
 static int pdatetime_bool(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObPreciseDateTimeType);
     out.set_bool(static_cast<bool> (in.get_precise_datetime()));
     return OB_SUCCESS;
 }
示例#3
0
 static int float_bool(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObFloatType);
     out.set_bool(static_cast<bool> (in.get_float()));
     return OB_SUCCESS;
 }
示例#4
0
 static int decimal_bool(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObDecimalType);
     out.set_bool(!in.get_decimal().is_zero());
     return OB_SUCCESS;
 }
TEST_F(ObObjCastTest, bool_to_xxx)
{
    ObExprObj in;
    bool cases[] = {true, false};
    const char *varchar_expected[] = {"true", "false"};
    const char *dec_expected[] = {"1", "0"};
    for (int64_t i = 0; i < static_cast<int64_t>(ARRAYSIZEOF(cases)); ++i)
    {
        bool v = cases[i];
        in.set_bool(v);

        MY_EXPECT(ObBoolType, in, ObNullType, v, varchar_expected[i]);
        MY_EXPECT(ObBoolType, in, ObIntType, v, varchar_expected[i]);
        MY_EXPECT(ObBoolType, in, ObFloatType, v, varchar_expected[i]);
        MY_EXPECT(ObBoolType, in, ObDoubleType, v, varchar_expected[i]);
        MY_EXPECT(ObBoolType, in, ObDateTimeType, v, varchar_expected[i]);
        MY_EXPECT(ObBoolType, in, ObPreciseDateTimeType, v, varchar_expected[i]);
        MY_EXPECT(ObBoolType, in, ObVarcharType, v, varchar_expected[i]);
        MY_EXPECT(ObBoolType, in, ObSeqType, v, varchar_expected[i]);
        MY_EXPECT(ObBoolType, in, ObCreateTimeType, v, varchar_expected[i]);
        MY_EXPECT(ObBoolType, in, ObModifyTimeType, v, varchar_expected[i]);
        MY_EXPECT(ObBoolType, in, ObExtendType, v, varchar_expected[i]);
        MY_EXPECT(ObBoolType, in, ObBoolType, v, varchar_expected[i]);
        MY_EXPECT(ObBoolType, in, ObDecimalType, v, dec_expected[i]);
    }
}
示例#6
0
 static int varchar_bool(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObVarcharType);
     const string &varchar = in.get_varchar();
     bool value = false;
     if (varchar.data() != NULL && varchar.length() > 0)
     {
         static const int64_t len_true = strlen("true");
         static const int64_t len_t = strlen("T");
         static const int64_t len_yes = strlen("yes");
         static const int64_t len_y = strlen("y");
         if (varchar.length() == len_true
                 && 0 == strncasecmp(varchar.data(), "true", len_true))
         {
             value = true;
         }
         else if (varchar.length() == len_t
                 && 0 == strncasecmp(varchar.data(), "T", len_t))
         {
             value = true;
         }
         else if (varchar.length() == len_yes
                 && 0 == strncasecmp(varchar.data(), "yes", len_yes))
         {
             value = true;
         }
         else if (varchar.length() == len_y
                 && 0 == strncasecmp(varchar.data(), "y", len_y))
         {
             value = true;
         }
     }
     out.set_bool(value);
     return OB_SUCCESS;
 }