implement sql_mode NO_UNSIGNED_SUBTRACTION
This commit is contained in:
32
deps/oblib/src/common/object/ob_obj_type.h
vendored
32
deps/oblib/src/common/object/ob_obj_type.h
vendored
@ -1228,6 +1228,38 @@ inline bool ob_is_unsigned_type(ObObjType type)
|
|||||||
ObUDoubleType == type || ObUNumberType == type;
|
ObUDoubleType == type || ObUNumberType == type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void convert_unsigned_type_to_signed(ObObjType &type)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case (ObUTinyIntType):
|
||||||
|
type = ObTinyIntType;
|
||||||
|
break;
|
||||||
|
case (ObUSmallIntType):
|
||||||
|
type = ObSmallIntType;
|
||||||
|
break;
|
||||||
|
case (ObUMediumIntType):
|
||||||
|
type = ObMediumIntType;
|
||||||
|
break;
|
||||||
|
case (ObUInt32Type):
|
||||||
|
type = ObInt32Type;
|
||||||
|
break;
|
||||||
|
case (ObUInt64Type):
|
||||||
|
type = ObIntType;
|
||||||
|
break;
|
||||||
|
case (ObUFloatType):
|
||||||
|
type = ObFloatType;
|
||||||
|
break;
|
||||||
|
case (ObUDoubleType):
|
||||||
|
type = ObDoubleType;
|
||||||
|
break;
|
||||||
|
case (ObUNumberType):
|
||||||
|
type = ObNumberType;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline bool ob_is_oracle_numeric_type(ObObjType type)
|
inline bool ob_is_oracle_numeric_type(ObObjType type)
|
||||||
{
|
{
|
||||||
return ObIntType == type || ob_is_number_tc(type) || ObFloatType == type || ObDoubleType == type;
|
return ObIntType == type || ob_is_number_tc(type) || ObFloatType == type || ObDoubleType == type;
|
||||||
|
|||||||
@ -60,7 +60,7 @@ ObSqlModeMap SQL_MODE_MAP[] = {{SMO_REAL_AS_FLOAT, STR_REAL_AS_FLOAT},
|
|||||||
|
|
||||||
ObSQLMode SUPPORT_MODE = SMO_STRICT_ALL_TABLES | SMO_STRICT_TRANS_TABLES | SMO_PAD_CHAR_TO_FULL_LENGTH |
|
ObSQLMode SUPPORT_MODE = SMO_STRICT_ALL_TABLES | SMO_STRICT_TRANS_TABLES | SMO_PAD_CHAR_TO_FULL_LENGTH |
|
||||||
SMO_ONLY_FULL_GROUP_BY | SMO_NO_AUTO_VALUE_ON_ZERO | SMO_PIPES_AS_CONCAT |
|
SMO_ONLY_FULL_GROUP_BY | SMO_NO_AUTO_VALUE_ON_ZERO | SMO_PIPES_AS_CONCAT |
|
||||||
SMO_HIGH_NOT_PRECEDENCE | SMO_ERROR_ON_RESOLVE_CAST;
|
SMO_HIGH_NOT_PRECEDENCE | SMO_ERROR_ON_RESOLVE_CAST | SMO_NO_UNSIGNED_SUBTRACTION;
|
||||||
|
|
||||||
bool is_sql_mode_supported(ObSQLMode mode)
|
bool is_sql_mode_supported(ObSQLMode mode)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -45,6 +45,12 @@ inline bool is_no_zero_date(ObSQLMode mode)
|
|||||||
{
|
{
|
||||||
return (SMO_NO_ZERO_DATE & mode);
|
return (SMO_NO_ZERO_DATE & mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool is_no_unsigned_subtraction(ObSQLMode mode)
|
||||||
|
{
|
||||||
|
return (SMO_NO_UNSIGNED_SUBTRACTION & mode);
|
||||||
|
}
|
||||||
|
|
||||||
inline bool is_mysql_compatible(ObCompatibilityMode mode)
|
inline bool is_mysql_compatible(ObCompatibilityMode mode)
|
||||||
{
|
{
|
||||||
return OCEANBASE_MODE == mode || MYSQL_MODE == mode;
|
return OCEANBASE_MODE == mode || MYSQL_MODE == mode;
|
||||||
|
|||||||
@ -42,8 +42,12 @@ int ObExprMinus::calc_result_type2(
|
|||||||
static const int64_t CARRY_OFFSET = 1;
|
static const int64_t CARRY_OFFSET = 1;
|
||||||
ObScale scale = SCALE_UNKNOWN_YET;
|
ObScale scale = SCALE_UNKNOWN_YET;
|
||||||
ObPrecision precision = PRECISION_UNKNOWN_YET;
|
ObPrecision precision = PRECISION_UNKNOWN_YET;
|
||||||
|
const ObSQLSessionInfo *session = nullptr;
|
||||||
bool is_oracle = share::is_oracle_mode();
|
bool is_oracle = share::is_oracle_mode();
|
||||||
if (OB_FAIL(ObArithExprOperator::calc_result_type2(type, type1, type2, type_ctx))) {
|
if (OB_ISNULL(session = type_ctx.get_session())) {
|
||||||
|
ret = OB_ERR_UNEXPECTED;
|
||||||
|
LOG_WARN("failed to get mysession", K(ret));
|
||||||
|
} else if (OB_FAIL(ObArithExprOperator::calc_result_type2(type, type1, type2, type_ctx))) {
|
||||||
LOG_WARN("fail to calc result type", K(ret), K(type), K(type1), K(type2));
|
LOG_WARN("fail to calc result type", K(ret), K(type), K(type1), K(type2));
|
||||||
} else if (is_oracle && type.is_oracle_decimal()) {
|
} else if (is_oracle && type.is_oracle_decimal()) {
|
||||||
type.set_scale(ORA_NUMBER_SCALE_UNKNOWN_YET);
|
type.set_scale(ORA_NUMBER_SCALE_UNKNOWN_YET);
|
||||||
@ -78,6 +82,11 @@ int ObExprMinus::calc_result_type2(
|
|||||||
} else {
|
} else {
|
||||||
type.set_precision(precision);
|
type.set_precision(precision);
|
||||||
}
|
}
|
||||||
|
if (share::is_mysql_mode() && is_no_unsigned_subtraction(session->get_sql_mode())) {
|
||||||
|
ObObjType convert_type = type.get_type();
|
||||||
|
convert_unsigned_type_to_signed(convert_type);
|
||||||
|
type.set_type(convert_type);
|
||||||
|
}
|
||||||
LOG_DEBUG("calc_result_type2", K(scale), K(type1), K(type2), K(type), K(precision));
|
LOG_DEBUG("calc_result_type2", K(scale), K(type1), K(type2), K(type), K(precision));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
Reference in New Issue
Block a user