~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/blob.cc

Giant merge.

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 "drizzle/server/field/blob.h"
 
25
#include <drizzled/field/blob.h>
26
26
 
27
27
#define BLOB_PACK_LENGTH_TO_MAX_LENGH(arg) \
28
28
((ulong) ((1LL << min(arg, 4) * 8) - 1LL))
51
51
void Field_blob::store_length(uchar *i_ptr,
52
52
                              uint i_packlength,
53
53
                              uint32_t i_number,
54
 
                              bool low_byte_first __attribute__((__unused__)))
 
54
                              bool low_byte_first __attribute__((unused)))
55
55
{
56
56
  switch (i_packlength) {
57
57
  case 1:
85
85
 
86
86
uint32_t Field_blob::get_length(const uchar *pos,
87
87
                              uint packlength_arg,
88
 
                              bool low_byte_first __attribute__((__unused__)))
 
88
                              bool low_byte_first __attribute__((unused)))
89
89
{
90
90
  switch (packlength_arg) {
91
91
  case 1:
160
160
 
161
161
  if (!length)
162
162
  {
163
 
    bzero(ptr,Field_blob::pack_length());
 
163
    memset(ptr, 0, Field_blob::pack_length());
164
164
    return 0;
165
165
  }
166
166
 
170
170
    if (!String::needs_conversion(length, cs, field_charset, &dummy_offset))
171
171
    {
172
172
      Field_blob::store_length(length);
173
 
      bmove(ptr+packlength,(char*) &from,sizeof(char*));
 
173
      memcpy(ptr+packlength, (char*) &from, sizeof(char*));
174
174
      return 0;
175
175
    }
176
176
    if (tmpstr.copy(from, length, cs))
190
190
                                            from, length);
191
191
    Field_blob::store_length(copy_length);
192
192
    tmp= value.ptr();
193
 
    bmove(ptr + packlength, (uchar*) &tmp, sizeof(char*));
 
193
    memcpy(ptr + packlength, (uchar*) &tmp, sizeof(char*));
194
194
    return 0;
195
195
  }
196
196
  /*
208
208
 
209
209
  Field_blob::store_length(copy_length);
210
210
  tmp= value.ptr();
211
 
  bmove(ptr+packlength,(uchar*) &tmp,sizeof(char*));
 
211
  memcpy(ptr+packlength, (uchar*) &tmp, sizeof(char*));
212
212
 
213
213
  if (check_string_copy_error(this, well_formed_error_pos,
214
214
                              cannot_convert_error_pos, from + length, cs))
218
218
 
219
219
oom_error:
220
220
  /* Fatal OOM error */
221
 
  bzero(ptr,Field_blob::pack_length());
 
221
  memset(ptr, 0, Field_blob::pack_length());
222
222
  return -1; 
223
223
}
224
224
 
246
246
  uint32_t length;
247
247
  CHARSET_INFO *cs;
248
248
 
249
 
  memcpy_fixed(&blob,ptr+packlength,sizeof(char*));
 
249
  memcpy(&blob,ptr+packlength,sizeof(char*));
250
250
  if (!blob)
251
251
    return 0.0;
252
252
  length= get_length(ptr);
259
259
{
260
260
  int not_used;
261
261
  char *blob;
262
 
  memcpy_fixed(&blob,ptr+packlength,sizeof(char*));
 
262
  memcpy(&blob,ptr+packlength,sizeof(char*));
263
263
  if (!blob)
264
264
    return 0;
265
265
  uint32_t length=get_length(ptr);
270
270
                            String *val_ptr)
271
271
{
272
272
  char *blob;
273
 
  memcpy_fixed(&blob,ptr+packlength,sizeof(char*));
 
273
  memcpy(&blob,ptr+packlength,sizeof(char*));
274
274
  if (!blob)
275
275
    val_ptr->set("",0,charset());       // A bit safer than ->length(0)
276
276
  else
283
283
{
284
284
  const char *blob;
285
285
  size_t length;
286
 
  memcpy_fixed(&blob, ptr+packlength, sizeof(const uchar*));
 
286
  memcpy(&blob, ptr+packlength, sizeof(const uchar*));
287
287
  if (!blob)
288
288
  {
289
289
    blob= "";
311
311
                        uint max_length)
312
312
{
313
313
  uchar *blob1,*blob2;
314
 
  memcpy_fixed(&blob1,a_ptr+packlength,sizeof(char*));
315
 
  memcpy_fixed(&blob2,b_ptr+packlength,sizeof(char*));
 
314
  memcpy(&blob1,a_ptr+packlength,sizeof(char*));
 
315
  memcpy(&blob2,b_ptr+packlength,sizeof(char*));
316
316
  uint a_len= get_length(a_ptr), b_len= get_length(b_ptr);
317
317
  set_if_smaller(a_len, max_length);
318
318
  set_if_smaller(b_len, max_length);
326
326
  char *a,*b;
327
327
  uint diff;
328
328
  uint32_t a_length,b_length;
329
 
  memcpy_fixed(&a,a_ptr+packlength,sizeof(char*));
330
 
  memcpy_fixed(&b,b_ptr+packlength,sizeof(char*));
 
329
  memcpy(&a,a_ptr+packlength,sizeof(char*));
 
330
  memcpy(&b,b_ptr+packlength,sizeof(char*));
331
331
  a_length=get_length(a_ptr);
332
332
  if (a_length > max_length)
333
333
    a_length=max_length;
343
343
 
344
344
uint Field_blob::get_key_image(uchar *buff,
345
345
                               uint length,
346
 
                               imagetype type_arg __attribute__((__unused__)))
 
346
                               imagetype type_arg __attribute__((unused)))
347
347
{
348
348
  uint32_t blob_length= get_length(ptr);
349
349
  uchar *blob;
360
360
      Must clear this as we do a memcmp in opt_range.cc to detect
361
361
      identical keys
362
362
    */
363
 
    bzero(buff+HA_KEY_BLOB_LENGTH+blob_length, (length-blob_length));
 
363
    memset(buff+HA_KEY_BLOB_LENGTH+blob_length, 0, (length-blob_length));
364
364
    length=(uint) blob_length;
365
365
  }
366
366
  int2store(buff,length);
381
381
{
382
382
  uchar *blob1;
383
383
  uint blob_length=get_length(ptr);
384
 
  memcpy_fixed(&blob1,ptr+packlength,sizeof(char*));
 
384
  memcpy(&blob1,ptr+packlength,sizeof(char*));
385
385
  CHARSET_INFO *cs= charset();
386
386
  uint local_char_length= max_key_length / cs->mbmaxlen;
387
387
  local_char_length= my_charpos(cs, blob1, blob1+blob_length,
429
429
  uint blob_length=get_length();
430
430
 
431
431
  if (!blob_length)
432
 
    bzero(to,length);
 
432
    memset(to, 0, length);
433
433
  else
434
434
  {
435
435
    if (field_charset == &my_charset_bin)
457
457
        break;
458
458
      }
459
459
    }
460
 
    memcpy_fixed(&blob,ptr+packlength,sizeof(char*));
 
460
    memcpy(&blob,ptr+packlength,sizeof(char*));
461
461
    
462
462
    blob_length=my_strnxfrm(field_charset,
463
463
                            to, length, blob, blob_length);
468
468
 
469
469
void Field_blob::sql_type(String &res) const
470
470
{
471
 
  const char *str;
472
 
  uint length;
473
 
  switch (packlength) {
474
 
  default: str="tiny"; length=4; break;
475
 
  case 2:  str="";     length=0; break;
476
 
  case 3:  str="medium"; length= 6; break;
477
 
  case 4:  str="long";  length=4; break;
478
 
  }
479
 
  res.set_ascii(str,length);
480
471
  if (charset() == &my_charset_bin)
481
 
    res.append(STRING_WITH_LEN("blob"));
 
472
    res.set_ascii(STRING_WITH_LEN("blob"));
482
473
  else
483
 
  {
484
 
    res.append(STRING_WITH_LEN("text"));
485
 
  }
 
474
    res.set_ascii(STRING_WITH_LEN("text"));
486
475
}
487
476
 
488
477
uchar *Field_blob::pack(uchar *to, const uchar *from,
529
518
 
530
519
   @return  New pointer into memory based on from + length of the data
531
520
*/
532
 
const uchar *Field_blob::unpack(uchar *to __attribute__((__unused__)),
 
521
const uchar *Field_blob::unpack(uchar *to __attribute__((unused)),
533
522
                                const uchar *from,
534
523
                                uint param_data,
535
524
                                bool low_byte_first)
571
560
{
572
561
  uchar *a;
573
562
  uint a_length, b_length;
574
 
  memcpy_fixed(&a,ptr+packlength,sizeof(char*));
 
563
  memcpy(&a,ptr+packlength,sizeof(char*));
575
564
  if (!a)
576
565
    return key_length_arg > 0 ? -1 : 0;
577
566
 
649
638
 
650
639
  /* put the address of the blob buffer or NULL */
651
640
  if (length)
652
 
    memcpy_fixed(to + packlength, &from, sizeof(from));
 
641
    memcpy(to + packlength, &from, sizeof(from));
653
642
  else
654
 
    bzero(to + packlength, sizeof(from));
 
643
    memset(to + packlength, 0, sizeof(from));
655
644
 
656
645
  /* point to first byte of next field in 'from' */
657
646
  return from + length;