当前位置: 首页>>代码示例>>C++>>正文


C++ ObExprObj::get_decimal方法代码示例

本文整理汇总了C++中ObExprObj::get_decimal方法的典型用法代码示例。如果您正苦于以下问题:C++ ObExprObj::get_decimal方法的具体用法?C++ ObExprObj::get_decimal怎么用?C++ ObExprObj::get_decimal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ObExprObj的用法示例。


在下文中一共展示了ObExprObj::get_decimal方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: decimal_bool

 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;
 }
开发者ID:b-xiang,项目名称:sql_parser-1,代码行数:7,代码来源:ob_obj_cast.cpp

示例2: decimal_mtime

 static int decimal_mtime(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_mtime(static_cast<ObModifyTime> (i64));
     }
     return ret;
 }
开发者ID:b-xiang,项目名称:sql_parser-1,代码行数:16,代码来源:ob_obj_cast.cpp

示例3: decimal_double

 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;
 }
开发者ID:b-xiang,项目名称:sql_parser-1,代码行数:19,代码来源:ob_obj_cast.cpp

示例4: decimal_varchar

 static int decimal_varchar(const ObObjCastParams &params, const ObExprObj &in, ObExprObj &out)
 {
     int ret = OB_SUCCESS;
     UNUSED(params);
     OB_ASSERT(in.get_type() == ObDecimalType);
     string varchar = out.get_varchar();
     if (varchar.length() < ObNumber::MAX_PRINTABLE_SIZE)
     {
         jlog(WARNING, "output buffer for varchar not enough, buf_len=%d", varchar.length());
         ret = OB_INVALID_ARGUMENT;
     }
     else
     {
         int64_t length = in.get_decimal().to_string((char*) varchar.data(), varchar.length());
         string varchar2(varchar);
         out.set_varchar(varchar2);
     }
     return ret;
 }
开发者ID:b-xiang,项目名称:sql_parser-1,代码行数:19,代码来源:ob_obj_cast.cpp

示例5:

  BLOCK_FUNC()
  {
    ObExprObj t1;
    ObExprObj t2;
    ObExprObj res;
    int64_t i1 = 0;
    int64_t i2 = 0;
    const int64_t buf_len = ObNumber::MAX_PRINTABLE_SIZE;
    char res_buf[buf_len];
    int err = OB_SUCCESS;

    // int add int
    t1.set_int(1);
    t2.set_int(2);
    EXPECT_EQ(OB_SUCCESS, t1.add(t2, res));
    ASSERT_EQ(OB_SUCCESS, res.get_int(i2));
    ASSERT_EQ(3, i2);
    // int add dec
    t1.set_int(1);
    t2.set_decimal("2.2");
    EXPECT_EQ(OB_SUCCESS, t1.add(t2, res));
    ASSERT_EQ(OB_SUCCESS, res.get_decimal(res_buf, buf_len));
    ASSERT_STREQ("3.2", res_buf);
    // dec add dec
    t1.set_decimal("10");
    t2.set_decimal("2.2");
    EXPECT_EQ(OB_SUCCESS, t1.add(t2, res));
    ASSERT_EQ(OB_SUCCESS, res.get_decimal(res_buf, buf_len));
    ASSERT_STREQ("12.2", res_buf);

    // int sub int
    t1.set_int(4);
    t2.set_int(2);
    EXPECT_EQ(OB_SUCCESS, t1.sub(t2, res));
    ASSERT_EQ(OB_SUCCESS, res.get_int(i2));
    ASSERT_EQ(2, i2);
    // int sub dec
    t1.set_int(4);
    t2.set_decimal("3.0");
    EXPECT_EQ(OB_SUCCESS, t1.sub(t2, res));
    EXPECT_EQ(OB_SUCCESS, t1.sub(t2, res));
    ASSERT_EQ(OB_SUCCESS, res.get_decimal(res_buf, buf_len));
    ASSERT_STREQ("1.0", res_buf);
    // dec sub dec
    t1.set_decimal("4");
    t2.set_decimal("2.0");
    EXPECT_EQ(OB_SUCCESS, t1.sub(t2, res));
    ASSERT_EQ(OB_SUCCESS, res.get_decimal(res_buf, buf_len));
    ASSERT_STREQ("2.0", res_buf);

    // int mul int
    t1.set_int(4);
    t2.set_int(2);
    EXPECT_EQ(OB_SUCCESS, t1.mul(t2, res));
    ASSERT_EQ(OB_SUCCESS, res.get_int(i2));
    ASSERT_EQ(8, i2);
    // int mul dec
    t1.set_int(4);
    t2.set_decimal("2.0");
    EXPECT_EQ(OB_SUCCESS, t1.mul(t2, res));
    ASSERT_EQ(OB_SUCCESS, res.get_decimal(res_buf, buf_len));
    ASSERT_STREQ("8.0", res_buf);
    // dec mul dec
    t1.set_decimal("4");
    t2.set_decimal("2.0");
    EXPECT_EQ(OB_SUCCESS, t1.mul(t2, res));
    ASSERT_EQ(OB_SUCCESS, res.get_decimal(res_buf, buf_len));
    ASSERT_STREQ("8.0", res_buf);

    // int div int
    t1.set_int(6);
    t2.set_int(2);
    EXPECT_EQ(OB_SUCCESS, t1.div(t2, res, false));
    ASSERT_EQ(OB_SUCCESS, res.get_decimal(res_buf, buf_len));
    ASSERT_STREQ("3.00000000000000000000000000000000000000", res_buf);
    EXPECT_EQ(OB_SUCCESS, t1.div(t2, res, true));
    double d = 0.0;
    ASSERT_EQ(OB_SUCCESS, res.get_double(d));
    ASSERT_EQ(3.0, d);
    // int div dec
    t1.set_int(6);
    t2.set_decimal("2.0");
    EXPECT_EQ(OB_SUCCESS, t1.div(t2, res, false));
    ASSERT_EQ(OB_SUCCESS, res.get_decimal(res_buf, buf_len));
    ASSERT_STREQ("3.00000000000000000000000000000000000000", res_buf);
    // dec div dec
    t1.set_decimal("6");
    t2.set_decimal("2.0");
    EXPECT_EQ(OB_SUCCESS, t1.div(t2, res, false));
    ASSERT_EQ(OB_SUCCESS, res.get_decimal(res_buf, buf_len));
    ASSERT_STREQ("3.00000000000000000000000000000000000000", res_buf);

    t1.set_int(5);
    t2.set_int(0);
    EXPECT_TRUE(OB_SUCCESS != t1.div(t2, res, false));
    EXPECT_TRUE(true == res.is_null());

    t1.set_decimal("5.0");
    t2.set_int(0);
    EXPECT_TRUE(OB_SUCCESS != t1.div(t2, res, false));
//.........这里部分代码省略.........
开发者ID:Abioy,项目名称:oceanbase,代码行数:101,代码来源:ob_expr_obj_test.cpp


注:本文中的ObExprObj::get_decimal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。