本文整理汇总了C++中ObExprObj::set_datetime方法的典型用法代码示例。如果您正苦于以下问题:C++ ObExprObj::set_datetime方法的具体用法?C++ ObExprObj::set_datetime怎么用?C++ ObExprObj::set_datetime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObExprObj
的用法示例。
在下文中一共展示了ObExprObj::set_datetime方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: varchar_datetime
static int varchar_datetime(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out)
{
int ret = OB_SUCCESS;
UNUSED(params);
OB_ASSERT(in.get_type() == ObVarcharType);
int year = 0;
int month = 0;
int day = 0;
int hour = 0;
int minute = 0;
int second = 0;
ret = varchar_scanf(in, 6, "%4d-%2d-%2d %2d:%2d:%2d",
&year, &month, &day,
&hour, &minute, &second);
if (OB_SUCCESS != ret)
{
year = month = day = hour = minute = second = 0;
ret = varchar_scanf(in, 3, "%4d-%2d-%2d",
&year, &month, &day);
}
if (OB_SUCCESS != ret)
{
year = month = day = hour = minute = second = 0;
ret = varchar_scanf(in, 3, "%2d:%2d:%2d",
&hour, &minute, &second);
}
if (OB_SUCCESS == ret)
{
struct tm gtm;
memset(>m, 0, sizeof (gtm));
gtm.tm_year = year - 1900;
gtm.tm_mon = month - 1;
gtm.tm_mday = day;
gtm.tm_hour = hour;
gtm.tm_min = minute;
gtm.tm_sec = second;
time_t t = mktime(>m);
out.set_datetime(static_cast<ObDateTime> (t));
}
else
{
const string& varchar = in.get_varchar();
jlog(WARNING, "failed to convert string `%.*s' to datetime type",
varchar.length(), varchar.data());
out.set_datetime(static_cast<ObDateTime> (0));
ret = OB_SUCCESS;
}
return ret;
}
示例2: bool_datetime
static int bool_datetime(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out)
{
UNUSED(params);
OB_ASSERT(in.get_type() == ObBoolType);
out.set_datetime(static_cast<ObDateTime> (in.get_bool()));
return OB_SUCCESS;
}
示例3: mtime_datetime
static int mtime_datetime(const ObObjCastParams ¶ms, const ObExprObj &in, ObExprObj &out)
{
UNUSED(params);
OB_ASSERT(in.get_type() == ObModifyTimeType);
out.set_datetime(static_cast<ObDateTime> (in.get_mtime() / 1000000L));
return OB_SUCCESS;
}
示例4: memset
TEST_F(ObObjCastTest, datetime_to_xxx)
{
ObExprObj in;
//tzset();
//printf("timezone=%s %s\n", tzname[0], tzname[1]);
const char* cases_str[] = {"1970-1-1 8:0:0", "1970-1-1 0:0:0", "2012-9-24 16:59:60"};
time_t cases[ARRAYSIZEOF(cases_str)];
const char *varchar_expected[] = {"1970-01-01 08:00:00", "1970-01-01 00:00:00", "2012-09-24 17:00:00"};
const char *dec_expected[] = {"0", "-28800", "1348477200"};
for (int64_t i = 0; i < static_cast<int64_t>(ARRAYSIZEOF(cases)); ++i)
{
struct tm tm;
memset(&tm, 0, sizeof(tm));
strptime(cases_str[i], "%Y-%m-%d %H:%M:%S", &tm);
cases[i] = mktime(&tm);
time_t v = cases[i];
//printf("v=%s", ctime(&v));
int64_t pv = v * 1000000L;
in.set_datetime(v);
MY_EXPECT(ObDateTimeType, in, ObNullType, v, varchar_expected[i]);
MY_EXPECT(ObDateTimeType, in, ObIntType, v, varchar_expected[i]);
MY_EXPECT(ObDateTimeType, in, ObFloatType, v, varchar_expected[i]);
MY_EXPECT(ObDateTimeType, in, ObDoubleType, v, varchar_expected[i]);
MY_EXPECT(ObDateTimeType, in, ObDateTimeType, v, varchar_expected[i]);
MY_EXPECT(ObDateTimeType, in, ObPreciseDateTimeType, pv, varchar_expected[i]);
MY_EXPECT(ObDateTimeType, in, ObVarcharType, v, varchar_expected[i]);
MY_EXPECT(ObDateTimeType, in, ObSeqType, v, varchar_expected[i]);
MY_EXPECT(ObDateTimeType, in, ObCreateTimeType, pv, varchar_expected[i]);
MY_EXPECT(ObDateTimeType, in, ObModifyTimeType, pv, varchar_expected[i]);
MY_EXPECT(ObDateTimeType, in, ObExtendType, v, varchar_expected[i]);
MY_EXPECT(ObDateTimeType, in, ObBoolType, v, varchar_expected[i]);
MY_EXPECT(ObDateTimeType, in, ObDecimalType, v, dec_expected[i]);
}
}
示例5: decimal_datetime
static int decimal_datetime(const ObObjCastParams ¶ms, 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_datetime(static_cast<ObDateTime> (i64));
}
return ret;
}