fix: json column default value(3.1_opensource)
This commit is contained in:
7
deps/oblib/src/common/object/ob_object.cpp
vendored
7
deps/oblib/src/common/object/ob_object.cpp
vendored
@ -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;
|
||||
|
||||
34
deps/oblib/src/lib/mysqlclient/ob_mysql_result.h
vendored
34
deps/oblib/src/lib/mysqlclient/ob_mysql_result.h
vendored
@ -686,7 +686,34 @@
|
||||
} \
|
||||
ret = (class_obj).set_##column_name(dest_obj); \
|
||||
} \
|
||||
} 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()); \
|
||||
} \
|
||||
ret = (class_obj).set_##column_name(dest_obj); \
|
||||
} \
|
||||
} \
|
||||
|
||||
Reference in New Issue
Block a user