~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/blob.h

  • Committer: Monty Taylor
  • Date: 2008-11-16 23:47:43 UTC
  • mto: (584.1.10 devel)
  • mto: This revision was merged to the branch mainline in revision 589.
  • Revision ID: monty@inaugust.com-20081116234743-c38gmv0pa2kdefaj
BrokeĀ outĀ cached_item.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 MySQL
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 */
 
20
 
 
21
#ifndef DRIZZLE_SERVER_FIELD_BLOB
 
22
#define DRIZZLE_SERVER_FIELD_BLOB
 
23
 
 
24
class Field_blob :public Field_longstr {
 
25
protected:
 
26
  uint32_t packlength;
 
27
  String value;                         // For temporaries
 
28
public:
 
29
  Field_blob(unsigned char *ptr_arg, unsigned char *null_ptr_arg, unsigned char null_bit_arg,
 
30
             enum utype unireg_check_arg, const char *field_name_arg,
 
31
             TABLE_SHARE *share, uint32_t blob_pack_length, const CHARSET_INFO * const cs);
 
32
  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
                   NONE, field_name_arg, cs),
 
36
    packlength(4)
 
37
  {
 
38
    flags|= BLOB_FLAG;
 
39
  }
 
40
  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
                   NONE, field_name_arg, cs)
 
44
  {
 
45
    flags|= BLOB_FLAG;
 
46
    packlength= 4;
 
47
    if (set_packlength)
 
48
    {
 
49
      uint32_t l_char_length= len_arg/cs->mbmaxlen;
 
50
      packlength= l_char_length <= 255 ? 1 :
 
51
                  l_char_length <= 65535 ? 2 :
 
52
                  l_char_length <= 16777215 ? 3 : 4;
 
53
    }
 
54
  }
 
55
  Field_blob(uint32_t packlength_arg)
 
56
    :Field_longstr((unsigned char*) 0, 0, (unsigned char*) "", 0, NONE, "temp", system_charset_info),
 
57
    packlength(packlength_arg) {}
 
58
  enum_field_types type() const { return DRIZZLE_TYPE_BLOB;}
 
59
  enum ha_base_keytype key_type() const
 
60
    { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
 
61
  int  store(const char *to,uint32_t length, const CHARSET_INFO * const charset);
 
62
  int  store(double nr);
 
63
  int  store(int64_t nr, bool unsigned_val);
 
64
  double val_real(void);
 
65
  int64_t val_int(void);
 
66
  String *val_str(String*,String *);
 
67
  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);
 
75
  uint32_t key_length() const { return 0; }
 
76
  void sort_string(unsigned char *buff,uint32_t length);
 
77
  uint32_t pack_length() const
 
78
  { return (uint32_t) (packlength+table->s->blob_ptr_size); }
 
79
 
 
80
  /**
 
81
     Return the packed length without the pointer size added. 
 
82
 
 
83
     This is used to determine the size of the actual data in the row
 
84
     buffer.
 
85
 
 
86
     @returns The length of the raw data itself without the pointer.
 
87
  */
 
88
  uint32_t pack_length_no_ptr() const
 
89
  { return (uint32_t) (packlength); }
 
90
  uint32_t row_pack_length() { return pack_length_no_ptr(); }
 
91
  uint32_t sort_length() const;
 
92
  virtual uint32_t max_data_length() const
 
93
  {
 
94
    return (uint32_t) (((uint64_t) 1 << (packlength*8)) -1);
 
95
  }
 
96
  int reset(void) { memset(ptr, 0, packlength+sizeof(unsigned char*)); return 0; }
 
97
  void reset_fields() { memset(&value, 0, sizeof(value)); }
 
98
#ifndef WORDS_BIGENDIAN
 
99
  static
 
100
#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
  {
 
104
    store_length(i_ptr, i_packlength, i_number, table->s->db_low_byte_first);
 
105
  }
 
106
  inline void store_length(uint32_t number)
 
107
  {
 
108
    store_length(ptr, packlength, number);
 
109
  }
 
110
 
 
111
  /**
 
112
     Return the packed length plus the length of the data. 
 
113
 
 
114
     This is used to determine the size of the data plus the 
 
115
     packed length portion in the row data.
 
116
 
 
117
     @returns The length in the row plus the size of the data.
 
118
  */
 
119
  uint32_t get_packed_size(const unsigned char *ptr_arg, bool low_byte_first)
 
120
    {return packlength + get_length(ptr_arg, packlength, low_byte_first);}
 
121
 
 
122
  inline uint32_t get_length(uint32_t row_offset= 0)
 
123
  { 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
  { 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)
 
137
    {
 
138
      memcpy(ptr,length,packlength);
 
139
      memcpy(ptr+packlength,&data,sizeof(char*));
 
140
    }
 
141
  void set_ptr_offset(my_ptrdiff_t ptr_diff, uint32_t length, unsigned char *data)
 
142
    {
 
143
      unsigned char *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,unsigned char*);
 
144
      store_length(ptr_ofs, packlength, length);
 
145
      memcpy(ptr_ofs+packlength,&data,sizeof(char*));
 
146
    }
 
147
  inline void set_ptr(uint32_t length, unsigned char *data)
 
148
    {
 
149
      set_ptr_offset(0, length, data);
 
150
    }
 
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
  void sql_type(String &str) const;
 
154
  inline bool copy()
 
155
  {
 
156
    unsigned char *tmp;
 
157
    get_ptr(&tmp);
 
158
    if (value.copy((char*) tmp, get_length(), charset()))
 
159
    {
 
160
      Field_blob::reset();
 
161
      return 1;
 
162
    }
 
163
    tmp=(unsigned char*) value.ptr();
 
164
    memcpy(ptr+packlength,&tmp,sizeof(char*));
 
165
    return 0;
 
166
  }
 
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);
 
182
  void free() { value.free(); }
 
183
  inline void clear_temporary() { memset(&value, 0, sizeof(value)); }
 
184
  friend int field_conv(Field *to,Field *from);
 
185
  uint32_t size_of() const { return sizeof(*this); }
 
186
  bool has_charset(void) const
 
187
  { return charset() == &my_charset_bin ? false : true; }
 
188
  uint32_t max_display_length();
 
189
  uint32_t is_equal(Create_field *new_field);
 
190
  inline bool in_read_set() { return bitmap_is_set(table->read_set, field_index); }
 
191
  inline bool in_write_set() { return bitmap_is_set(table->write_set, field_index); }
 
192
private:
 
193
  int do_save_field_metadata(unsigned char *first_byte);
 
194
};
 
195
 
 
196
#endif
 
197