From 4f58bd7e94b86bc88215a68fd896fba5a2b5f909 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 18 May 2005 17:30:11 +0500 Subject: [PATCH] a fix (bug #10539: When inserting out of range value in BIT, different engines behaves differently). sql/field.cc: a fix (bug #10539: When inserting out of range value in BIT, different engines behaves differently). we have to set the first byte only if there is(are) uneven bit(s). --- mysql-test/r/type_bit.result | 8 ++++++++ mysql-test/t/type_bit.test | 9 +++++++++ sql/field.cc | 5 +++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/type_bit.result b/mysql-test/r/type_bit.result index 64c9a11b3cd..4d9bc0c7fe1 100644 --- a/mysql-test/r/type_bit.result +++ b/mysql-test/r/type_bit.result @@ -458,3 +458,11 @@ select h from t1; h a drop table t1; +create table t1 (a bit(8)) engine=heap; +insert into t1 values ('1111100000'); +Warnings: +Warning 1264 Out of range value adjusted for column 'a' at row 1 +select a+0 from t1; +a+0 +255 +drop table t1; diff --git a/mysql-test/t/type_bit.test b/mysql-test/t/type_bit.test index 19d16f95990..2df5f0ed05d 100644 --- a/mysql-test/t/type_bit.test +++ b/mysql-test/t/type_bit.test @@ -162,3 +162,12 @@ create table t1 (a int, b time, c tinyint, d bool, e char(10), f bit(1), insert into t1 set a=1; select h from t1; drop table t1; + +# +# Bug #10539 +# + +create table t1 (a bit(8)) engine=heap; +insert into t1 values ('1111100000'); +select a+0 from t1; +drop table t1; diff --git a/sql/field.cc b/sql/field.cc index 34c5210b43c..0b4445d45c2 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -7821,7 +7821,7 @@ int Field_bit::store(const char *from, uint length, CHARSET_INFO *cs) int Field_bit::store(double nr) { - return (Field_bit::store((longlong) nr)); + return store((longlong) nr); } @@ -8004,7 +8004,8 @@ int Field_bit_as_char::store(const char *from, uint length, CHARSET_INFO *cs) (delta == 0 && bits && (uint) (uchar) *from >= (uint) (1 << bits))) { memset(ptr, 0xff, field_length); - *ptr&= ((1 << bits) - 1); /* set first byte */ + if (bits) + *ptr&= ((1 << bits) - 1); /* set first byte */ set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1); return 1; }