1809
To use Field_bit::cmp_binary() you need to copy the bits stored in
1810
the beginning of the record (the NULL bytes) to each memory you
1811
want to compare (where the arguments point).
1814
- Field_bit::cmp_binary() is only implemented in the base class
1815
(Field::cmp_binary()).
1816
- Field::cmp_binary() currenly use pack_length() to calculate how
1818
- pack_length() includes size of the bits stored in the NULL bytes
1821
class Field_bit :public Field {
1823
uchar *bit_ptr; // position in record where 'uneven' bits store
1824
uchar bit_ofs; // offset to 'uneven' high bits
1825
uint bit_len; // number of 'uneven' high bits
1827
Field_bit(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1828
uchar null_bit_arg, uchar *bit_ptr_arg, uchar bit_ofs_arg,
1829
enum utype unireg_check_arg, const char *field_name_arg);
1830
enum_field_types type() const { return MYSQL_TYPE_BIT; }
1831
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BIT; }
1832
uint32 key_length() const { return (uint32) (field_length + 7) / 8; }
1833
uint32 max_data_length() const { return (field_length + 7) / 8; }
1834
uint32 max_display_length() { return field_length; }
1835
uint size_of() const { return sizeof(*this); }
1836
Item_result result_type () const { return INT_RESULT; }
1837
int reset(void) { bzero(ptr, bytes_in_rec); return 0; }
1838
int store(const char *to, uint length, CHARSET_INFO *charset);
1839
int store(double nr);
1840
int store(longlong nr, bool unsigned_val);
1841
int store_decimal(const my_decimal *);
1842
double val_real(void);
1843
longlong val_int(void);
1844
String *val_str(String*, String *);
1845
virtual bool str_needs_quotes() { return TRUE; }
1846
my_decimal *val_decimal(my_decimal *);
1847
int cmp(const uchar *a, const uchar *b)
1849
DBUG_ASSERT(ptr == a);
1850
return Field_bit::key_cmp(b, bytes_in_rec+test(bit_len));
1852
int cmp_binary_offset(uint row_offset)
1853
{ return cmp_offset(row_offset); }
1854
int cmp_max(const uchar *a, const uchar *b, uint max_length);
1855
int key_cmp(const uchar *a, const uchar *b)
1856
{ return cmp_binary((uchar *) a, (uchar *) b); }
1857
int key_cmp(const uchar *str, uint length);
1858
int cmp_offset(uint row_offset);
1859
void get_image(uchar *buff, uint length, CHARSET_INFO *cs)
1860
{ get_key_image(buff, length, itRAW); }
1861
void set_image(const uchar *buff,uint length, CHARSET_INFO *cs)
1862
{ Field_bit::store((char *) buff, length, cs); }
1863
uint get_key_image(uchar *buff, uint length, imagetype type);
1864
void set_key_image(const uchar *buff, uint length)
1865
{ Field_bit::store((char*) buff, length, &my_charset_bin); }
1866
void sort_string(uchar *buff, uint length)
1867
{ get_key_image(buff, length, itRAW); }
1868
uint32 pack_length() const { return (uint32) (field_length + 7) / 8; }
1869
uint32 pack_length_in_rec() const { return bytes_in_rec; }
1870
uint pack_length_from_metadata(uint field_metadata);
1871
uint row_pack_length()
1872
{ return (bytes_in_rec + ((bit_len > 0) ? 1 : 0)); }
1873
int compatible_field_size(uint field_metadata);
1874
void sql_type(String &str) const;
1875
virtual uchar *pack(uchar *to, const uchar *from,
1876
uint max_length, bool low_byte_first);
1877
virtual const uchar *unpack(uchar *to, const uchar *from,
1878
uint param_data, bool low_byte_first);
1879
virtual void set_default();
1881
Field *new_key_field(MEM_ROOT *root, struct st_table *new_table,
1882
uchar *new_ptr, uchar *new_null_ptr,
1884
void set_bit_ptr(uchar *bit_ptr_arg, uchar bit_ofs_arg)
1886
bit_ptr= bit_ptr_arg;
1887
bit_ofs= bit_ofs_arg;
1889
bool eq(Field *field)
1891
return (Field::eq(field) &&
1892
field->type() == type() &&
1893
bit_ptr == ((Field_bit *)field)->bit_ptr &&
1894
bit_ofs == ((Field_bit *)field)->bit_ofs);
1896
uint is_equal(Create_field *new_field);
1897
void move_field_offset(my_ptrdiff_t ptr_diff)
1899
Field::move_field_offset(ptr_diff);
1900
bit_ptr= ADD_TO_PTR(bit_ptr, ptr_diff, uchar*);
1902
void hash(ulong *nr, ulong *nr2);
1905
virtual size_t do_last_null_byte() const;
1906
int do_save_field_metadata(uchar *first_byte);
1911
BIT field represented as chars for non-MyISAM tables.
1913
@todo The inheritance relationship is backwards since Field_bit is
1914
an extended version of Field_bit_as_char and not the other way
1915
around. Hence, we should refactor it to fix the hierarchy order.
1917
class Field_bit_as_char: public Field_bit {
1919
Field_bit_as_char(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
1921
enum utype unireg_check_arg, const char *field_name_arg);
1922
enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
1923
uint size_of() const { return sizeof(*this); }
1924
int store(const char *to, uint length, CHARSET_INFO *charset);
1925
int store(double nr) { return Field_bit::store(nr); }
1926
int store(longlong nr, bool unsigned_val)
1927
{ return Field_bit::store(nr, unsigned_val); }
1928
void sql_type(String &str) const;
1933
1808
Create field class for CREATE TABLE