diff --git a/deps/oblib/src/common/object/ob_object.cpp b/deps/oblib/src/common/object/ob_object.cpp index 4794b04d3f5e0eedb6f09861435dc6ec3553073c..18e0a9284609e3bb3e143ca42255f60d19fd9808 100644 --- a/deps/oblib/src/common/object/ob_object.cpp +++ b/deps/oblib/src/common/object/ob_object.cpp @@ -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; diff --git a/deps/oblib/src/lib/mysqlclient/ob_mysql_result.h b/deps/oblib/src/lib/mysqlclient/ob_mysql_result.h index d3afdce7fe072eca7bea2a1c3f717e823204b9af..91c3b1369ed4a2a9175f3c85bb58b559ae610ab6 100644 --- a/deps/oblib/src/lib/mysqlclient/ob_mysql_result.h +++ b/deps/oblib/src/lib/mysqlclient/ob_mysql_result.h @@ -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); \ } \ } \