~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/blob.h

  • Committer: Monty Taylor
  • Date: 2010-10-13 17:53:36 UTC
  • mto: This revision was merged to the branch mainline in revision 1845.
  • Revision ID: mordred@inaugust.com-20101013175336-amzhjftgztblvua5
Updated pandora-build files to version 0.161

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 */
36
36
class Field_blob :public Field_str {
37
37
protected:
 
38
  uint32_t packlength;
38
39
  String value;                         // For temporaries
39
40
public:
40
41
 
50
51
             unsigned char null_bit_arg,
51
52
             const char *field_name_arg,
52
53
             TableShare *share,
 
54
             uint32_t blob_pack_length,
53
55
             const CHARSET_INFO * const cs);
54
56
  Field_blob(uint32_t len_arg,
55
57
             bool maybe_null_arg,
60
62
               maybe_null_arg ? (unsigned char *) "": 0,
61
63
               0,
62
64
               field_name_arg,
63
 
               cs)
64
 
  {
65
 
    flags|= BLOB_FLAG;
66
 
  }
67
 
 
 
65
               cs),
 
66
    packlength(4)
 
67
  {
 
68
    flags|= BLOB_FLAG;
 
69
  }
 
70
  Field_blob(uint32_t len_arg,
 
71
             bool maybe_null_arg,
 
72
             const char *field_name_arg,
 
73
             const CHARSET_INFO * const cs,
 
74
             bool set_packlength)
 
75
    :Field_str((unsigned char*) NULL,
 
76
               len_arg,
 
77
               maybe_null_arg ? (unsigned char*) "": 0,
 
78
               0,
 
79
               field_name_arg,
 
80
               cs),
 
81
    packlength(4)
 
82
  {
 
83
    flags|= BLOB_FLAG;
 
84
    if (set_packlength)
 
85
    {
 
86
      uint32_t l_char_length= len_arg/cs->mbmaxlen;
 
87
      packlength= l_char_length <= 255 ? 1 :
 
88
                  l_char_length <= 65535 ? 2 :
 
89
                  l_char_length <= 16777215 ? 3 : 4;
 
90
    }
 
91
  }
 
92
  Field_blob(uint32_t packlength_arg)
 
93
    :Field_str((unsigned char*) 0,
 
94
               0,
 
95
               (unsigned char*) "",
 
96
               0,
 
97
               "temp",
 
98
               system_charset_info),
 
99
    packlength(packlength_arg) 
 
100
  {}
68
101
  enum_field_types type() const { return DRIZZLE_TYPE_BLOB;}
69
102
  enum ha_base_keytype key_type() const
70
103
    { return binary() ? HA_KEYTYPE_VARBINARY2 : HA_KEYTYPE_VARTEXT2; }
98
131
     @returns The length of the raw data itself without the pointer.
99
132
  */
100
133
  uint32_t pack_length_no_ptr() const
101
 
  { return (uint32_t) (sizeof(uint32_t)); }
102
 
 
 
134
  { return (uint32_t) (packlength); }
103
135
  uint32_t sort_length() const;
104
136
  virtual uint32_t max_data_length() const
105
137
  {
106
 
    return (uint32_t) (((uint64_t) 1 << 32) -1);
 
138
    return (uint32_t) (((uint64_t) 1 << (packlength*8)) -1);
107
139
  }
108
 
  int reset(void) { memset(ptr, 0, sizeof(uint32_t)+sizeof(unsigned char*)); return 0; }
 
140
  int reset(void) { memset(ptr, 0, packlength+sizeof(unsigned char*)); return 0; }
109
141
  void reset_fields() { memset(&value, 0, sizeof(value)); }
110
142
#ifndef WORDS_BIGENDIAN
111
143
  static
112
144
#endif
113
 
  void store_length(unsigned char *i_ptr, uint32_t i_number, bool low_byte_first);
114
 
  void store_length(unsigned char *i_ptr, uint32_t i_number);
 
145
  void store_length(unsigned char *i_ptr, uint32_t i_packlength,
 
146
                    uint32_t i_number, bool low_byte_first);
 
147
  void store_length(unsigned char *i_ptr, uint32_t i_packlength,
 
148
                    uint32_t i_number);
115
149
 
116
150
  inline void store_length(uint32_t number)
117
151
  {
118
 
    store_length(ptr, number);
 
152
    store_length(ptr, packlength, number);
119
153
  }
120
154
 
121
155
  /**
129
163
  uint32_t get_packed_size(const unsigned char *ptr_arg, bool low_byte_first);
130
164
 
131
165
  uint32_t get_length(uint32_t row_offset= 0);
132
 
  uint32_t get_length(const unsigned char *ptr, bool low_byte_first);
 
166
  uint32_t get_length(const unsigned char *ptr, uint32_t packlength,
 
167
                      bool low_byte_first);
133
168
  uint32_t get_length(const unsigned char *ptr_arg);
134
169
  void put_length(unsigned char *pos, uint32_t length);
135
170
  inline void get_ptr(unsigned char **str)
136
171
    {
137
 
      memcpy(str,ptr+sizeof(uint32_t),sizeof(unsigned char*));
 
172
      memcpy(str,ptr+packlength,sizeof(unsigned char*));
138
173
    }
139
174
  inline void get_ptr(unsigned char **str, uint32_t row_offset)
140
175
    {
141
 
      memcpy(str,ptr+sizeof(uint32_t)+row_offset,sizeof(char*));
 
176
      memcpy(str,ptr+packlength+row_offset,sizeof(char*));
142
177
    }
143
178
  inline void set_ptr(unsigned char *length, unsigned char *data)
144
179
    {
145
 
      memcpy(ptr,length,sizeof(uint32_t));
146
 
      memcpy(ptr+sizeof(uint32_t),&data,sizeof(char*));
 
180
      memcpy(ptr,length,packlength);
 
181
      memcpy(ptr+packlength,&data,sizeof(char*));
147
182
    }
148
183
  void set_ptr_offset(ptrdiff_t ptr_diff, uint32_t length, unsigned char *data)
149
184
    {
150
185
      unsigned char *ptr_ofs= ADD_TO_PTR(ptr,ptr_diff,unsigned char*);
151
 
      store_length(ptr_ofs, length);
152
 
      memcpy(ptr_ofs+sizeof(uint32_t),&data,sizeof(char*));
 
186
      store_length(ptr_ofs, packlength, length);
 
187
      memcpy(ptr_ofs+packlength,&data,sizeof(char*));
153
188
    }
154
189
  inline void set_ptr(uint32_t length, unsigned char *data)
155
190
    {
169
204
      return 1;
170
205
    }
171
206
    tmp=(unsigned char*) value.ptr();
172
 
    memcpy(ptr+sizeof(uint32_t),&tmp,sizeof(char*));
 
207
    memcpy(ptr+packlength,&tmp,sizeof(char*));
173
208
    return 0;
174
209
  }
175
210
  virtual unsigned char *pack(unsigned char *to, const unsigned char *from,
177
212
  unsigned char *pack_key(unsigned char *to, const unsigned char *from,
178
213
                  uint32_t max_length, bool low_byte_first);
179
214
  virtual const unsigned char *unpack(unsigned char *to, const unsigned char *from,
180
 
                              uint32_t , bool low_byte_first);
 
215
                              uint32_t param_data, bool low_byte_first);
181
216
  void free() { value.free(); }
182
217
  inline void clear_temporary() { memset(&value, 0, sizeof(value)); }
183
218
  friend int field_conv(Field *to,Field *from);