~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/blob.cc

  • Committer: Stewart Smith
  • Date: 2008-09-15 07:13:59 UTC
  • mfrom: (383.1.21 drizzle)
  • mto: This revision was merged to the branch mainline in revision 408.
  • Revision ID: stewart@flamingspork.com-20080915071359-f8bznznyaiqrtqxa
merged

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#pragma implementation                          // gcc: Class implementation
23
23
#endif
24
24
 
 
25
#include <drizzled/server_includes.h>
25
26
#include <drizzled/field/blob.h>
26
27
 
27
 
#define BLOB_PACK_LENGTH_TO_MAX_LENGH(arg) \
28
 
((ulong) ((1LL << min(arg, 4) * 8) - 1LL))
 
28
uint32_t
 
29
blob_pack_length_to_max_length(uint arg)
 
30
{
 
31
  return (1LL << min(arg, 4U) * 8) - 1LL;
 
32
}
 
33
 
29
34
 
30
35
/****************************************************************************
31
36
** blob type
36
41
Field_blob::Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
37
42
                       enum utype unireg_check_arg, const char *field_name_arg,
38
43
                       TABLE_SHARE *share, uint blob_pack_length,
39
 
                       CHARSET_INFO *cs)
40
 
  :Field_longstr(ptr_arg, BLOB_PACK_LENGTH_TO_MAX_LENGH(blob_pack_length),
 
44
                       const CHARSET_INFO * const cs)
 
45
  :Field_longstr(ptr_arg, blob_pack_length_to_max_length(blob_pack_length),
41
46
                 null_ptr_arg, null_bit_arg, unireg_check_arg, field_name_arg,
42
47
                 cs),
43
48
   packlength(blob_pack_length)
149
154
}
150
155
 
151
156
 
152
 
int Field_blob::store(const char *from,uint length,CHARSET_INFO *cs)
 
157
int Field_blob::store(const char *from,uint length, const CHARSET_INFO * const cs)
153
158
{
154
159
  uint copy_length, new_length;
155
160
  const char *well_formed_error_pos;
170
175
    if (!String::needs_conversion(length, cs, field_charset, &dummy_offset))
171
176
    {
172
177
      Field_blob::store_length(length);
173
 
      memcpy(ptr+packlength, (char*) &from, sizeof(char*));
 
178
      memcpy(ptr+packlength, &from, sizeof(char*));
174
179
      return 0;
175
180
    }
176
181
    if (tmpstr.copy(from, length, cs))
190
195
                                            from, length);
191
196
    Field_blob::store_length(copy_length);
192
197
    tmp= value.ptr();
193
 
    memcpy(ptr + packlength, (uchar*) &tmp, sizeof(char*));
 
198
    memcpy(ptr + packlength, &tmp, sizeof(char*));
194
199
    return 0;
195
200
  }
196
201
  /*
208
213
 
209
214
  Field_blob::store_length(copy_length);
210
215
  tmp= value.ptr();
211
 
  memcpy(ptr+packlength, (uchar*) &tmp, sizeof(char*));
 
216
  memcpy(ptr+packlength, &tmp, sizeof(char*));
212
217
 
213
218
  if (check_string_copy_error(this, well_formed_error_pos,
214
219
                              cannot_convert_error_pos, from + length, cs))
225
230
 
226
231
int Field_blob::store(double nr)
227
232
{
228
 
  CHARSET_INFO *cs=charset();
 
233
  const CHARSET_INFO * const cs=charset();
229
234
  value.set_real(nr, NOT_FIXED_DEC, cs);
230
235
  return Field_blob::store(value.ptr(),(uint) value.length(), cs);
231
236
}
233
238
 
234
239
int Field_blob::store(int64_t nr, bool unsigned_val)
235
240
{
236
 
  CHARSET_INFO *cs=charset();
 
241
  const CHARSET_INFO * const cs=charset();
237
242
  value.set_int(nr, unsigned_val, cs);
238
243
  return Field_blob::store(value.ptr(), (uint) value.length(), cs);
239
244
}
244
249
  int not_used;
245
250
  char *end_not_used, *blob;
246
251
  uint32_t length;
247
 
  CHARSET_INFO *cs;
 
252
  const CHARSET_INFO *cs;
248
253
 
249
254
  memcpy(&blob,ptr+packlength,sizeof(char*));
250
255
  if (!blob)
382
387
  uchar *blob1;
383
388
  uint blob_length=get_length(ptr);
384
389
  memcpy(&blob1,ptr+packlength,sizeof(char*));
385
 
  CHARSET_INFO *cs= charset();
 
390
  const CHARSET_INFO * const cs= charset();
386
391
  uint local_char_length= max_key_length / cs->mbmaxlen;
387
392
  local_char_length= my_charpos(cs, blob1, blob1+blob_length,
388
393
                                local_char_length);
535
540
/* Keys for blobs are like keys on varchars */
536
541
 
537
542
int Field_blob::pack_cmp(const uchar *a, const uchar *b, uint key_length_arg,
538
 
                         my_bool insert_or_update)
 
543
                         bool insert_or_update)
539
544
{
540
545
  uint a_length, b_length;
541
546
  if (key_length_arg > 255)
556
561
 
557
562
 
558
563
int Field_blob::pack_cmp(const uchar *b, uint key_length_arg,
559
 
                         my_bool insert_or_update)
 
564
                         bool insert_or_update)
560
565
{
561
566
  uchar *a;
562
567
  uint a_length, b_length;