~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/blob.cc

  • Committer: jay
  • Date: 2008-12-23 00:18:10 UTC
  • Revision ID: jay@piggy.tangent.org-20081223001810-026ibij22q2842k1
Had a --regex-replace by accident. Should have been --replace_column call.  Only showed up in make test, not running single test, because InnoDB key numbers were different with multiple test running.

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
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#ifdef USE_PRAGMA_IMPLEMENTATION
22
 
#pragma implementation                          // gcc: Class implementation
23
 
#endif
24
21
 
25
22
#include <drizzled/server_includes.h>
26
23
#include <drizzled/field/blob.h>
 
24
#include <drizzled/table.h>
 
25
#include <drizzled/session.h>
 
26
 
 
27
#include <string>
 
28
 
 
29
using namespace std;
27
30
 
28
31
uint32_t
29
32
blob_pack_length_to_max_length(uint32_t arg)
88
91
}
89
92
 
90
93
 
 
94
void Field_blob::store_length(unsigned char *i_ptr, uint32_t i_packlength,
 
95
                  uint32_t i_number)
 
96
{
 
97
  store_length(i_ptr, i_packlength, i_number, table->s->db_low_byte_first);
 
98
}
 
99
 
 
100
 
91
101
uint32_t Field_blob::get_length(const unsigned char *pos,
92
102
                              uint32_t packlength_arg,
93
103
                              bool low_byte_first __attribute__((unused)))
124
134
}
125
135
 
126
136
 
 
137
uint32_t Field_blob::get_packed_size(const unsigned char *ptr_arg,
 
138
                                bool low_byte_first)
 
139
{
 
140
  return packlength + get_length(ptr_arg, packlength, low_byte_first);
 
141
}
 
142
 
 
143
 
 
144
uint32_t Field_blob::get_length(uint32_t row_offset)
 
145
{
 
146
  return get_length(ptr+row_offset, this->packlength,
 
147
                    table->s->db_low_byte_first);
 
148
}
 
149
 
 
150
 
 
151
uint32_t Field_blob::get_length(const unsigned char *ptr_arg)
 
152
{
 
153
  return get_length(ptr_arg, this->packlength, table->s->db_low_byte_first);
 
154
}
 
155
 
 
156
 
127
157
/**
128
158
  Put a blob length field into a record buffer.
129
159
 
175
205
    if (!String::needs_conversion(length, cs, field_charset, &dummy_offset))
176
206
    {
177
207
      Field_blob::store_length(length);
178
 
      memcpy(ptr+packlength, &from, sizeof(char*));
 
208
      memmove(ptr+packlength, &from, sizeof(char*));
179
209
      return 0;
180
210
    }
181
211
    if (tmpstr.copy(from, length, cs))
195
225
                                            from, length);
196
226
    Field_blob::store_length(copy_length);
197
227
    tmp= value.ptr();
198
 
    memcpy(ptr + packlength, &tmp, sizeof(char*));
 
228
    memmove(ptr + packlength, &tmp, sizeof(char*));
199
229
    return 0;
200
230
  }
201
231
  /*
213
243
 
214
244
  Field_blob::store_length(copy_length);
215
245
  tmp= value.ptr();
216
 
  memcpy(ptr+packlength, &tmp, sizeof(char*));
 
246
  memmove(ptr+packlength, &tmp, sizeof(char*));
217
247
 
218
248
  if (check_string_copy_error(this, well_formed_error_pos,
219
249
                              cannot_convert_error_pos, from + length, cs))
224
254
oom_error:
225
255
  /* Fatal OOM error */
226
256
  memset(ptr, 0, Field_blob::pack_length());
227
 
  return -1; 
 
257
  return -1;
228
258
}
229
259
 
230
260
 
306
336
int Field_blob::cmp(const unsigned char *a,uint32_t a_length, const unsigned char *b,
307
337
                    uint32_t b_length)
308
338
{
309
 
  return field_charset->coll->strnncollsp(field_charset, 
 
339
  return field_charset->coll->strnncollsp(field_charset,
310
340
                                          a, a_length, b, b_length,
311
341
                                          0);
312
342
}
347
377
/* The following is used only when comparing a key */
348
378
 
349
379
uint32_t Field_blob::get_key_image(unsigned char *buff,
350
 
                               uint32_t length,
351
 
                               imagetype type_arg __attribute__((unused)))
 
380
                                   uint32_t length,
 
381
                                   imagetype)
352
382
{
353
383
  uint32_t blob_length= get_length(ptr);
354
384
  unsigned char *blob;
374
404
}
375
405
 
376
406
 
 
407
uint32_t Field_blob::get_key_image(basic_string<unsigned char> &buff,
 
408
                                   uint32_t length,
 
409
                                   imagetype)
 
410
{
 
411
  uint32_t blob_length= get_length(ptr);
 
412
  unsigned char *blob;
 
413
 
 
414
  get_ptr(&blob);
 
415
  uint32_t local_char_length= length / field_charset->mbmaxlen;
 
416
  local_char_length= my_charpos(field_charset, blob, blob + blob_length,
 
417
                                local_char_length);
 
418
  set_if_smaller(blob_length, local_char_length);
 
419
 
 
420
  unsigned char len_buff[HA_KEY_BLOB_LENGTH];
 
421
  int2store(len_buff,length);
 
422
  buff.append(len_buff);
 
423
  buff.append(blob, blob_length);
 
424
 
 
425
  if (length > blob_length)
 
426
  {
 
427
    /*
 
428
      Must clear this as we do a memcmp in opt_range.cc to detect
 
429
      identical keys
 
430
    */
 
431
 
 
432
    buff.append(length-blob_length, '0');
 
433
  }
 
434
  return HA_KEY_BLOB_LENGTH+length;
 
435
}
 
436
 
 
437
 
377
438
void Field_blob::set_key_image(const unsigned char *buff,uint32_t length)
378
439
{
379
440
  length= uint2korr(buff);
423
484
 
424
485
uint32_t Field_blob::sort_length() const
425
486
{
426
 
  return (uint32_t) (current_thd->variables.max_sort_length + 
 
487
  return (uint32_t) (current_session->variables.max_sort_length +
427
488
                   (field_charset == &my_charset_bin ? 0 : packlength));
428
489
}
429
490
 
463
524
      }
464
525
    }
465
526
    memcpy(&blob,ptr+packlength,sizeof(char*));
466
 
    
 
527
 
467
528
    blob_length=my_strnxfrm(field_charset,
468
529
                            to, length, blob, blob_length);
469
530
    assert(blob_length == length);
471
532
}
472
533
 
473
534
 
 
535
uint32_t Field_blob::pack_length() const
 
536
{
 
537
  return (uint32_t) (packlength+table->s->blob_ptr_size);
 
538
}
 
539
 
 
540
 
474
541
void Field_blob::sql_type(String &res) const
475
542
{
476
543
  if (charset() == &my_charset_bin)
509
576
/**
510
577
   Unpack a blob field from row data.
511
578
 
512
 
   This method is used to unpack a blob field from a master whose size of 
 
579
   This method is used to unpack a blob field from a master whose size of
513
580
   the field is less than that of the slave. Note: This method is included
514
581
   to satisfy inheritance rules, but is not needed for blob fields. It
515
582
   simply is used as a pass-through to the original unpack() method for
721
788
  }
722
789
}
723
790
 
 
791
bool Field_blob::in_read_set()
 
792
{
 
793
  return bitmap_is_set(table->read_set, field_index);
 
794
}
 
795
 
 
796
 
 
797
bool Field_blob::in_write_set()
 
798
{
 
799
  return bitmap_is_set(table->write_set, field_index);
 
800
}