提交 1b88c270 编写于 作者: O obdev 提交者: wangzelin.wzl

fix: json column default value(3.1_opensource)

上级 af654e3a
......@@ -276,6 +276,7 @@ DEF_TO_STRING(ObLobLocator)
const char* ObObj::MIN_OBJECT_VALUE_STR = "__OB__MIN__";
const char* ObObj::MAX_OBJECT_VALUE_STR = "__OB__MAX__";
const char* ObObj::NOP_VALUE_STR = "__OB__NOP__";
const char OB_JSON_NULL[2] = {'\0', '\0'}; // binary json null
OB_SERIALIZE_MEMBER(ObDataType, meta_, accuracy_, is_zero_fill_);
OB_SERIALIZE_MEMBER(ObEnumSetInnerValue, numberic_value_, string_value_);
......@@ -458,12 +459,14 @@ int ObObj::build_not_strict_default_value()
case ObTinyTextType:
case ObTextType:
case ObMediumTextType:
case ObLongTextType:
case ObJsonType: {
case ObLongTextType: {
ObString null_str;
set_string(data_type, null_str);
meta_.set_lob_inrow();
} break;
case ObJsonType: {
set_json_value(data_type, OB_JSON_NULL, 2);
} break;
case ObBitType:
set_bit(0);
break;
......
......@@ -686,7 +686,34 @@
} \
ret = (class_obj).set_##column_name(dest_obj); \
} \
} else { \
} else if (ob_is_json(data_type) && share::is_mysql_mode()) \
{ /* MySQL json does not support default value except null, */ \
/* need this defensive to compatible a bug in old version */ \
ObObj def_obj; \
ObObj default_value; \
default_value.set_type(data_type); \
ObArenaAllocator allocator(ObModIds::OB_SCHEMA); \
ObObj dest_obj; \
ObCastCtx cast_ctx(&allocator, NULL, CM_NONE, column.get_collation_type()); \
if (OB_FAIL(default_value.build_not_strict_default_value())) { \
SQL_LOG(WARN, "failed to build not strict default json value", K(ret)); \
} else { \
def_obj.set_json_value(data_type, \
default_value.get_string().ptr(), \
default_value.get_string().length()); \
if (OB_FAIL(ObObjCaster::to_type(data_type, cast_ctx, def_obj, dest_obj))) \
{ \
SQL_LOG(WARN, "cast obj failed, ", "src type", def_obj.get_type(), "dest type", data_type); \
} \
else \
{ \
dest_obj.set_lob_inrow(); \
dest_obj.meta_.set_collation_level(CS_LEVEL_IMPLICIT); \
ret = (class_obj).set_##column_name(dest_obj); \
} \
} \
} \
else { \
ObObj def_obj; \
def_obj.set_varchar(str_value); \
ObArenaAllocator allocator(ObModIds::OB_SCHEMA); \
......@@ -699,14 +726,7 @@
} else if (OB_FAIL(ObObjCaster::to_type(data_type, cast_ctx, def_obj, dest_obj))) { \
SQL_LOG(WARN, "cast obj failed, ", "src type", def_obj.get_type(), "dest type", data_type); \
} else { \
if (ob_is_json(data_type)) { \
dest_obj.set_lob_inrow(); \
dest_obj.meta_.set_collation_level(CS_LEVEL_IMPLICIT); \
} \
else \
{ \
dest_obj.set_scale(column.get_data_scale()); \
} \
dest_obj.set_scale(column.get_data_scale()); \
ret = (class_obj).set_##column_name(dest_obj); \
} \
} \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册