Fix the conversion rules from string/datetime to enum/set
This commit is contained in:
committed by
wangzelin.wzl
parent
44f28e92b6
commit
f51c7afe86
@ -4006,7 +4006,8 @@ static int string_enum(const ObExpectType& expect_type, ObObjCastParams& params,
|
||||
int32_t no_sp_len = 0;
|
||||
ObString no_sp_val;
|
||||
ObString in_str;
|
||||
if (OB_UNLIKELY(ObEnumType != expect_type.get_type()) || OB_UNLIKELY(ObStringTC != in.get_type_class()) ||
|
||||
if (OB_UNLIKELY(ObEnumType != expect_type.get_type()) ||
|
||||
OB_UNLIKELY(ObStringTC != in.get_type_class() && ObTextTC != in.get_type_class()) ||
|
||||
OB_ISNULL(type_infos = expect_type.get_type_infos())) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(expect_type), K(in), K(ret));
|
||||
@ -4022,35 +4023,22 @@ static int string_enum(const ObExpectType& expect_type, ObObjCastParams& params,
|
||||
if (OB_FAIL(find_type(*type_infos, cs_type, no_sp_val, pos))) {
|
||||
LOG_WARN("fail to find type", KPC(type_infos), K(cs_type), K(no_sp_val), K(in_str), K(pos), K(ret));
|
||||
} else if (OB_UNLIKELY(pos < 0)) {
|
||||
if (CM_IS_WARN_ON_FAIL(cast_mode)) {
|
||||
params.warning_ = OB_ERR_DATA_TRUNCATED;
|
||||
value = 0;
|
||||
LOG_INFO("input value out of range, and set out value zero", K(in), K(expect_type));
|
||||
} else {
|
||||
if (!in_str.is_numeric()) {
|
||||
ret = OB_ERR_DATA_TRUNCATED;
|
||||
LOG_WARN("input value out of range", K(in), K(expect_type), K(ret));
|
||||
// Bug30666903: check implicit cast logic to handle number cases
|
||||
if (in_str.is_numeric()) {
|
||||
int err = 0;
|
||||
value = ObCharset::strntoull(in_str.ptr(), in_str.length(), 10, &err);
|
||||
if (err == 0) {
|
||||
ret = OB_SUCCESS;
|
||||
uint32_t val_cnt = type_infos->count();
|
||||
if (OB_UNLIKELY(val_cnt <= 0)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpect val_cnt", K(in), K(out), K(expect_type), K(ret));
|
||||
} else if (value > val_cnt) {
|
||||
value = 0;
|
||||
ret = OB_ERR_DATA_TRUNCATED;
|
||||
LOG_WARN("input value out of range", K(in), K(val_cnt), K(ret));
|
||||
}
|
||||
if (OB_FAIL(ret) && CM_IS_WARN_ON_FAIL(cast_mode)) {
|
||||
params.warning_ = OB_ERR_DATA_TRUNCATED;
|
||||
ret = OB_SUCCESS;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int err = 0;
|
||||
int64_t val_cnt = type_infos->count();
|
||||
value = ObCharset::strntoull(in_str.ptr(), in_str.length(), 10, &err);
|
||||
if (err != 0 || value > val_cnt) {
|
||||
value = 0;
|
||||
ret = OB_ERR_DATA_TRUNCATED;
|
||||
LOG_WARN("input value out of range", K(in), K(val_cnt), K(ret), K(err));
|
||||
}
|
||||
}
|
||||
if (OB_FAIL(ret) && CM_IS_WARN_ON_FAIL(cast_mode)) {
|
||||
params.warning_ = OB_ERR_DATA_TRUNCATED;
|
||||
ret = OB_SUCCESS;
|
||||
}
|
||||
} else {
|
||||
value = pos + 1; // enum start from 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user