本文整理汇总了C++中ObExprObj::set_varchar方法的典型用法代码示例。如果您正苦于以下问题:C++ ObExprObj::set_varchar方法的具体用法?C++ ObExprObj::set_varchar怎么用?C++ ObExprObj::set_varchar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObExprObj
的用法示例。
在下文中一共展示了ObExprObj::set_varchar方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST_F(ObObjCastTest, varchar_to_xxx)
{
ObExprObj in;
const char* cases[] = {"1970-1-1 8:0:0", "2012-9-24 16:59:60.000000", "-123456", "-123.456", "true", "false"};
int64_t int_expected[ARRAYSIZEOF(cases)] = {1970, 2012, -123456, -123, 0, 0};
float float_expected[ARRAYSIZEOF(cases)] = {1970.0f, 2012.0f, -123456.0f, -123.456f, 0.0f, 0.0f};
double double_expected[ARRAYSIZEOF(cases)] = {1970.0, 2012.0, -123456.0, -123.456, 0.0, 0.0};
int64_t pdt_expected[ARRAYSIZEOF(cases)] = {0, 1348477200000000, 0, 0, 0, 0};
bool bool_expected[ARRAYSIZEOF(cases)] = {false, false, false, false, true, false};
const char *dec_expected[ARRAYSIZEOF(cases)] = {"0", "0", "-123456", "-123.456", "0", "0"};
for (int64_t i = 0; i < static_cast<int64_t>(ARRAYSIZEOF(cases)); ++i)
{
ObString v;
v.assign_ptr(const_cast<char*>(cases[i]), static_cast<int32_t>(strlen(cases[i])));
in.set_varchar(v);
//printf("case %ld: %s\n", i, cases[i]);
MY_EXPECT(ObVarcharType, in, ObNullType, int_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObIntType, int_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObFloatType, float_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObDoubleType, double_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObDateTimeType, (pdt_expected[i]/1000000L), cases[i]);
MY_EXPECT(ObVarcharType, in, ObPreciseDateTimeType, pdt_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObVarcharType, int_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObSeqType, int_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObCreateTimeType, pdt_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObModifyTimeType, pdt_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObExtendType, int_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObBoolType, bool_expected[i], cases[i]);
MY_EXPECT(ObVarcharType, in, ObDecimalType, int_expected[i], dec_expected[i]);
}
}
示例2: bool_varchar
static int bool_varchar(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out)
{
UNUSED(params);
OB_ASSERT(in.get_type() == ObBoolType);
string varchar;
if (in.get_bool())
{
varchar.assign("true");
}
else
{
varchar.assign("false");
}
out.set_varchar(varchar);
return OB_SUCCESS;
}
示例3: decimal_varchar
static int decimal_varchar(const ObObjCastParams ¶ms, 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;
}
示例4: varchar_printf
static int varchar_printf(ObExprObj &out, const char* format, ...)
{
int ret = OB_SUCCESS;
string varchar = out.get_varchar();
if (NULL == varchar.data() || varchar.length() <= 0)
{
jlog(WARNING, "output buffer for varchar not enough, buf_len=%u", varchar.length());
ret = OB_INVALID_ARGUMENT;
}
else
{
va_list args;
va_start(args, format);
int length = vsnprintf((char*) varchar.data(), varchar.length(), format, args);
va_end(args);
/*qinbo*/
//string varchar2(varchar.length(), length, varchar.data());
string varchar2(varchar);
out.set_varchar(varchar2);
}
return ret;
}