Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(common): limit min signed int64 value to -9223372036854775806 #1206 #1349

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions mysql-test/suite/tianmu/r/signed_boundary.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Test signed boundary
#
DROP DATABASE IF EXISTS signed_boundary;
CREATE TABLE int32_(c_max int, c_min int) engine = tianmu;
INSERT INTO int32_ values(-2147483647, 2147483647);
INSERT INTO int32_ values(-2147483648, 2147483647);
ERROR 22003: Out of range[-2147483647, 2147483647] for column 'c_max' value: -2147483648
INSERT INTO int32_ values(-2147483647, 2147483648);
ERROR 22003: Out of range value for column 'c_min' at row 1
DROP TABLE int32_;
CREATE TABLE int64_(c_max bigint, c_min bigint) engine = tianmu;
INSERT INTO int64_ values(-9223372036854775806, 9223372036854775807);
INSERT INTO int64_ values(-9223372036854775807, 9223372036854775807);
ERROR 22003: Out of range[-9223372036854775807, 9223372036854775807] for column 'c_max' value: -9223372036854775807
INSERT INTO int64_ values(-9223372036854775806, 9223372036854775808);
ERROR 22003: Out of range value for column 'c_min' at row 1
DROP TABLE int64_;
27 changes: 27 additions & 0 deletions mysql-test/suite/tianmu/t/signed_boundary.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--source include/have_tianmu.inc

--echo #
--echo # Test signed boundary
--echo #

--disable_warnings
DROP DATABASE IF EXISTS signed_boundary;
--enable_warnings

# int32 limit
CREATE TABLE int32_(c_max int, c_min int) engine = tianmu;
INSERT INTO int32_ values(-2147483647, 2147483647);
--error 1264
INSERT INTO int32_ values(-2147483648, 2147483647);
--error 1264
INSERT INTO int32_ values(-2147483647, 2147483648);
DROP TABLE int32_;

# int64 limit
CREATE TABLE int64_(c_max bigint, c_min bigint) engine = tianmu;
INSERT INTO int64_ values(-9223372036854775806, 9223372036854775807);
--error 1264
INSERT INTO int64_ values(-9223372036854775807, 9223372036854775807);
--error 1264
INSERT INTO int64_ values(-9223372036854775806, 9223372036854775808);
DROP TABLE int64_;
2 changes: 1 addition & 1 deletion storage/tianmu/common/common_definitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void PushWarningIfOutOfRange(THD *thd, std::string col_name, int64_t v, int type
PushWarning(thd, Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE,
getErrMsg(col_name, 0, TIANMU_BIGINT_MAX, unsigned_flag, v).c_str());
throw std::exception();
} else if (v > TIANMU_BIGINT_MAX || v < TIANMU_BIGINT_MIN) {
} else if (v > TIANMU_BIGINT_MAX || v <= TIANMU_BIGINT_MIN) {
PushWarning(thd, Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE,
getErrMsg(col_name, TIANMU_BIGINT_MIN, TIANMU_BIGINT_MAX, unsigned_flag, v).c_str());
throw std::exception();
Expand Down