diff options
author | unknown <jimw@mysql.com> | 2006-04-04 17:54:58 -0700 |
---|---|---|
committer | unknown <jimw@mysql.com> | 2006-04-04 17:54:58 -0700 |
commit | e13642dcacc02c30aac981360d390bc6c6a23f25 (patch) | |
tree | 470f8546a50589e9c092da9005875129175816e0 /sql/field.h | |
parent | e65726c6c9af1087baf4a5b9ba328cadb606b99c (diff) | |
download | mariadb-git-e13642dcacc02c30aac981360d390bc6c6a23f25.tar.gz |
Bug #13601: Wrong int type for bit
The wrong value was being reported as the field_length for BIT
fields, resulting in confusion for at least Connector/J. The
field_length is now always the number of bits in the field, as
it should be.
mysql-test/r/type_bit.result:
Add new results
mysql-test/r/type_bit_innodb.result:
Add new results
mysql-test/t/type_bit.test:
Add new regression test
mysql-test/t/type_bit_innodb.test:
Add new regression test
sql/field.cc:
Fix Field_bit->field_length to actually report the display width, and
store the bytes stored in the rec in the new bytes_in_rec member.
sql/field.h:
Fix Field_bit::field_length to store the correct value, adding
Field_bit::bytes_in_rec to remember the number of bytes used for
storing the value. Remove Field_bit_as_char::create_length, as it
is now redundant.
sql/ha_ndbcluster.cc:
Handle field_length of Field_bit actually being the display width (# of bits).
sql/key.cc:
Fix inappropriate use of field->field_length for BIT field.
Diffstat (limited to 'sql/field.h')
-rw-r--r-- | sql/field.h | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/sql/field.h b/sql/field.h index e8dd7f05f99..891e8e392f7 100644 --- a/sql/field.h +++ b/sql/field.h @@ -1303,17 +1303,18 @@ public: uchar *bit_ptr; // position in record where 'uneven' bits store uchar bit_ofs; // offset to 'uneven' high bits uint bit_len; // number of 'uneven' high bits + uint bytes_in_rec; Field_bit(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar *bit_ptr_arg, uchar bit_ofs_arg, enum utype unireg_check_arg, const char *field_name_arg, struct st_table *table_arg); enum_field_types type() const { return FIELD_TYPE_BIT; } enum ha_base_keytype key_type() const { return HA_KEYTYPE_BIT; } - uint32 key_length() const { return (uint32) field_length + (bit_len > 0); } - uint32 max_length() { return (uint32) field_length * 8 + bit_len; } + uint32 key_length() const { return (uint32) (field_length + 7) / 8; } + uint32 max_length() { return field_length; } uint size_of() const { return sizeof(*this); } Item_result result_type () const { return INT_RESULT; } - void reset(void) { bzero(ptr, field_length); } + void reset(void) { bzero(ptr, bytes_in_rec); } int store(const char *to, uint length, CHARSET_INFO *charset); int store(double nr); int store(longlong nr, bool unsigned_val); @@ -1335,9 +1336,8 @@ public: { Field_bit::store(buff, length, &my_charset_bin); } void sort_string(char *buff, uint length) { get_key_image(buff, length, itRAW); } - uint32 pack_length() const - { return (uint32) field_length + (bit_len > 0); } - uint32 pack_length_in_rec() const { return field_length; } + uint32 pack_length() const { return (uint32) (field_length + 7) / 8; } + uint32 pack_length_in_rec() const { return bytes_in_rec; } void sql_type(String &str) const; char *pack(char *to, const char *from, uint max_length=~(uint) 0); const char *unpack(char* to, const char *from); @@ -1354,13 +1354,11 @@ public: class Field_bit_as_char: public Field_bit { public: - uchar create_length; Field_bit_as_char(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, const char *field_name_arg, struct st_table *table_arg); enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; } - uint32 max_length() { return (uint32) create_length; } uint size_of() const { return sizeof(*this); } int store(const char *to, uint length, CHARSET_INFO *charset); int store(double nr) { return Field_bit::store(nr); } |