~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/blob.h

  • Committer: Monty Taylor
  • Date: 2008-08-04 22:01:39 UTC
  • mto: (261.1.4 drizzle)
  • mto: This revision was merged to the branch mainline in revision 262.
  • Revision ID: monty@inaugust.com-20080804220139-fy862jc9lykayvka
Moved libdrizzle.ver.in to libdrizzle.ver.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
4
 *  Copyright (C) 2008 MySQL
21
21
#ifndef DRIZZLE_SERVER_FIELD_BLOB
22
22
#define DRIZZLE_SERVER_FIELD_BLOB
23
23
 
 
24
#include <drizzled/mysql_priv.h>
 
25
 
24
26
class Field_blob :public Field_longstr {
25
27
protected:
26
 
  uint32_t packlength;
 
28
  uint packlength;
27
29
  String value;                         // For temporaries
28
30
public:
29
 
  Field_blob(unsigned char *ptr_arg, unsigned char *null_ptr_arg, unsigned char null_bit_arg,
 
31
  Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
30
32
             enum utype unireg_check_arg, const char *field_name_arg,
31
 
             TABLE_SHARE *share, uint32_t blob_pack_length, const CHARSET_INFO * const cs);
 
33
             TABLE_SHARE *share, uint blob_pack_length, CHARSET_INFO *cs);
32
34
  Field_blob(uint32_t len_arg,bool maybe_null_arg, const char *field_name_arg,
33
 
             const CHARSET_INFO * const cs)
34
 
    :Field_longstr((unsigned char*) 0, len_arg, maybe_null_arg ? (unsigned char*) "": 0, 0,
 
35
             CHARSET_INFO *cs)
 
36
    :Field_longstr((uchar*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
35
37
                   NONE, field_name_arg, cs),
36
38
    packlength(4)
37
39
  {
38
40
    flags|= BLOB_FLAG;
39
41
  }
40
42
  Field_blob(uint32_t len_arg,bool maybe_null_arg, const char *field_name_arg,
41
 
             const CHARSET_INFO * const cs, bool set_packlength)
42
 
    :Field_longstr((unsigned char*) 0,len_arg, maybe_null_arg ? (unsigned char*) "": 0, 0,
 
43
             CHARSET_INFO *cs, bool set_packlength)
 
44
    :Field_longstr((uchar*) 0,len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
43
45
                   NONE, field_name_arg, cs)
44
46
  {
45
47
    flags|= BLOB_FLAG;
53
55
    }
54
56
  }
55
57
  Field_blob(uint32_t packlength_arg)
56
 
    :Field_longstr((unsigned char*) 0, 0, (unsigned char*) "", 0, NONE, "temp", system_charset_info),
 
58
    :Field_longstr((uchar*) 0, 0, (uchar*) "", 0, NONE, "temp", system_charset_info),
57
59
    packlength(packlength_arg) {}
58
60
  enum_field_types type() const { return DRIZZLE_TYPE_BLOB;}
59
61
  enum ha_base_keytype key_type() const
60
62
    { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
61
 
  int  store(const char *to,uint32_t length, const CHARSET_INFO * const charset);
 
63
  int  store(const char *to,uint length,CHARSET_INFO *charset);
62
64
  int  store(double nr);
63
65
  int  store(int64_t nr, bool unsigned_val);
64
66
  double val_real(void);
65
67
  int64_t val_int(void);
66
68
  String *val_str(String*,String *);
67
69
  my_decimal *val_decimal(my_decimal *);
68
 
  int cmp_max(const unsigned char *, const unsigned char *, uint32_t max_length);
69
 
  int cmp(const unsigned char *a,const unsigned char *b)
70
 
    { return cmp_max(a, b, UINT32_MAX); }
71
 
  int cmp(const unsigned char *a, uint32_t a_length, const unsigned char *b, uint32_t b_length);
72
 
  int cmp_binary(const unsigned char *a,const unsigned char *b, uint32_t max_length=UINT32_MAX);
73
 
  int key_cmp(const unsigned char *,const unsigned char*);
74
 
  int key_cmp(const unsigned char *str, uint32_t length);
 
70
  int cmp_max(const uchar *, const uchar *, uint max_length);
 
71
  int cmp(const uchar *a,const uchar *b)
 
72
    { return cmp_max(a, b, ~0L); }
 
73
  int cmp(const uchar *a, uint32_t a_length, const uchar *b, uint32_t b_length);
 
74
  int cmp_binary(const uchar *a,const uchar *b, uint32_t max_length=~0L);
 
75
  int key_cmp(const uchar *,const uchar*);
 
76
  int key_cmp(const uchar *str, uint length);
75
77
  uint32_t key_length() const { return 0; }
76
 
  void sort_string(unsigned char *buff,uint32_t length);
 
78
  void sort_string(uchar *buff,uint length);
77
79
  uint32_t pack_length() const
78
80
  { return (uint32_t) (packlength+table->s->blob_ptr_size); }
79
81
 
87
89
  */
88
90
  uint32_t pack_length_no_ptr() const
89
91
  { return (uint32_t) (packlength); }
90
 
  uint32_t row_pack_length() { return pack_length_no_ptr(); }
 
92
  uint row_pack_length() { return pack_length_no_ptr(); }
91
93
  uint32_t sort_length() const;
92
94
  virtual uint32_t max_data_length() const
93
95
  {
94
96
    return (uint32_t) (((uint64_t) 1 << (packlength*8)) -1);
95
97
  }
96
 
  int reset(void) { memset(ptr, 0, packlength+sizeof(unsigned char*)); return 0; }
97
 
  void reset_fields() { memset(&value, 0, sizeof(value)); }
 
98
  int reset(void) { memset(ptr, 0, packlength+sizeof(uchar*)); return 0; }
 
99
  void reset_fields() { memset((uchar*) &value, 0, sizeof(value)); }
98
100
#ifndef WORDS_BIGENDIAN
99
101
  static
100
102
#endif
101
 
  void store_length(unsigned char *i_ptr, uint32_t i_packlength, uint32_t i_number, bool low_byte_first);
102
 
  void store_length(unsigned char *i_ptr, uint32_t i_packlength, uint32_t i_number)
 
103
  void store_length(uchar *i_ptr, uint i_packlength, uint32_t i_number, bool low_byte_first);
 
104
  void store_length(uchar *i_ptr, uint i_packlength, uint32_t i_number)
103
105
  {
104
106
    store_length(i_ptr, i_packlength, i_number, table->s->db_low_byte_first);
105
107
  }
116
118
 
117
119
     @returns The length in the row plus the size of the data.
118
120
  */
119
 
  uint32_t get_packed_size(const unsigned char *ptr_arg, bool low_byte_first)
 
121
  uint32_t get_packed_size(const uchar *ptr_arg, bool low_byte_first)
120
122
    {return packlength + get_length(ptr_arg, packlength, low_byte_first);}
121
123
 
122
 
  inline uint32_t get_length(uint32_t row_offset= 0)
 
124
  inline uint32_t get_length(uint row_offset= 0)
123
125
  { return get_length(ptr+row_offset, this->packlength, table->s->db_low_byte_first); }
124
 
  uint32_t get_length(const unsigned char *ptr, uint32_t packlength, bool low_byte_first);
125
 
  uint32_t get_length(const unsigned char *ptr_arg)
 
126
  uint32_t get_length(const uchar *ptr, uint packlength, bool low_byte_first);
 
127
  uint32_t get_length(const uchar *ptr_arg)
126
128
  { return get_length(ptr_arg, this->packlength, table->s->db_low_byte_first); }
127
 
  void put_length(unsigned char *pos, uint32_t length);
128
 
  inline void get_ptr(unsigned char **str)
129
 
    {
130
 
      memcpy(str,ptr+packlength,sizeof(unsigned char*));
131
 
    }
132
 
  inline void get_ptr(unsigned char **str, uint32_t row_offset)
133
 
    {
134
 
      memcpy(str,ptr+packlength+row_offset,sizeof(char*));
135
 
    }
136
 
  inline void set_ptr(unsigned char *length, unsigned char *data)
 
129
  void put_length(uchar *pos, uint32_t length);
 
130
  inline void get_ptr(uchar **str)
 
131
    {
 
132
      memcpy((uchar*) str,ptr+packlength,sizeof(uchar*));
 
133
    }
 
134
  inline void get_ptr(uchar **str, uint row_offset)
 
135
    {
 
136
      memcpy((uchar*) str,ptr+packlength+row_offset,sizeof(char*));
 
137
    }
 
138
  inline void set_ptr(uchar *length, uchar *data)
137
139
    {
138
140
      memcpy(ptr,length,packlength);
139
141
      memcpy(ptr+packlength,&data,sizeof(char*));
140
142
    }
141
 
  void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32_t length, unsigned char *data)
 
143
  void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32_t length, uchar *data)
142
144
    {
143
 
      unsigned char *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,unsigned char*);
 
145
      uchar *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,uchar*);
144
146
      store_length(ptr_ofs, packlength, length);
145
147
      memcpy(ptr_ofs+packlength,&data,sizeof(char*));
146
148
    }
147
 
  inline void set_ptr(uint32_t length, unsigned char *data)
 
149
  inline void set_ptr(uint32_t length, uchar *data)
148
150
    {
149
151
      set_ptr_offset(0, length, data);
150
152
    }
151
 
  uint32_t get_key_image(unsigned char *buff,uint32_t length, imagetype type);
152
 
  void set_key_image(const unsigned char *buff,uint32_t length);
 
153
  uint get_key_image(uchar *buff,uint length, imagetype type);
 
154
  void set_key_image(const uchar *buff,uint length);
153
155
  void sql_type(String &str) const;
154
156
  inline bool copy()
155
157
  {
156
 
    unsigned char *tmp;
 
158
    uchar *tmp;
157
159
    get_ptr(&tmp);
158
160
    if (value.copy((char*) tmp, get_length(), charset()))
159
161
    {
160
162
      Field_blob::reset();
161
163
      return 1;
162
164
    }
163
 
    tmp=(unsigned char*) value.ptr();
 
165
    tmp=(uchar*) value.ptr();
164
166
    memcpy(ptr+packlength,&tmp,sizeof(char*));
165
167
    return 0;
166
168
  }
167
 
  virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
168
 
                      uint32_t max_length, bool low_byte_first);
169
 
  unsigned char *pack_key(unsigned char *to, const unsigned char *from,
170
 
                  uint32_t max_length, bool low_byte_first);
171
 
  unsigned char *pack_key_from_key_image(unsigned char* to, const unsigned char *from,
172
 
                                 uint32_t max_length, bool low_byte_first);
173
 
  virtual const unsigned char *unpack(unsigned char *to, const unsigned char *from,
174
 
                              uint32_t param_data, bool low_byte_first);
175
 
  const unsigned char *unpack_key(unsigned char* to, const unsigned char *from,
176
 
                          uint32_t max_length, bool low_byte_first);
177
 
  int pack_cmp(const unsigned char *a, const unsigned char *b, uint32_t key_length,
178
 
               bool insert_or_update);
179
 
  int pack_cmp(const unsigned char *b, uint32_t key_length,bool insert_or_update);
180
 
  uint32_t packed_col_length(const unsigned char *col_ptr, uint32_t length);
181
 
  uint32_t max_packed_col_length(uint32_t max_length);
 
169
  virtual uchar *pack(uchar *to, const uchar *from,
 
170
                      uint max_length, bool low_byte_first);
 
171
  uchar *pack_key(uchar *to, const uchar *from,
 
172
                  uint max_length, bool low_byte_first);
 
173
  uchar *pack_key_from_key_image(uchar* to, const uchar *from,
 
174
                                 uint max_length, bool low_byte_first);
 
175
  virtual const uchar *unpack(uchar *to, const uchar *from,
 
176
                              uint param_data, bool low_byte_first);
 
177
  const uchar *unpack_key(uchar* to, const uchar *from,
 
178
                          uint max_length, bool low_byte_first);
 
179
  int pack_cmp(const uchar *a, const uchar *b, uint key_length,
 
180
               my_bool insert_or_update);
 
181
  int pack_cmp(const uchar *b, uint key_length,my_bool insert_or_update);
 
182
  uint packed_col_length(const uchar *col_ptr, uint length);
 
183
  uint max_packed_col_length(uint max_length);
182
184
  void free() { value.free(); }
183
 
  inline void clear_temporary() { memset(&value, 0, sizeof(value)); }
 
185
  inline void clear_temporary() { memset((uchar*) &value, 0, sizeof(value)); }
184
186
  friend int field_conv(Field *to,Field *from);
185
 
  uint32_t size_of() const { return sizeof(*this); }
 
187
  uint size_of() const { return sizeof(*this); }
186
188
  bool has_charset(void) const
187
189
  { return charset() == &my_charset_bin ? false : true; }
188
190
  uint32_t max_display_length();
189
 
  uint32_t is_equal(Create_field *new_field);
 
191
  uint is_equal(Create_field *new_field);
190
192
  inline bool in_read_set() { return bitmap_is_set(table->read_set, field_index); }
191
193
  inline bool in_write_set() { return bitmap_is_set(table->write_set, field_index); }
192
194
private:
193
 
  int do_save_field_metadata(unsigned char *first_byte);
 
195
  int do_save_field_metadata(uchar *first_byte);
194
196
};
195
197
 
196
198
#endif