~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/blob.cc

  • Committer: Brian Aker
  • Date: 2009-07-16 22:37:01 UTC
  • mto: This revision was merged to the branch mainline in revision 1100.
  • Revision ID: brian@gaz-20090716223701-vbbbo8dmgd2ljqqo
Refactor TableShare has to be behind class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
 
22
 
#include "config.h"
 
22
#include <drizzled/server_includes.h>
23
23
#include <drizzled/field/blob.h>
24
24
#include <drizzled/table.h>
25
25
#include <drizzled/session.h>
26
 
#include "plugin/myisam/myisam.h"
27
26
 
28
27
#include <string>
29
28
#include <algorithm>
30
29
 
31
30
using namespace std;
32
31
 
33
 
namespace drizzled
34
 
{
35
 
 
36
32
static uint32_t blob_pack_length_to_max_length(uint32_t arg)
37
33
{
38
34
  return max(UINT32_MAX,
46
42
** packlength slot and may be from 1-4.
47
43
****************************************************************************/
48
44
 
49
 
Field_blob::Field_blob(unsigned char *ptr_arg,
50
 
                       unsigned char *null_ptr_arg,
51
 
                       unsigned char null_bit_arg,
52
 
                                   const char *field_name_arg,
53
 
                       TableShare *share,
54
 
                       uint32_t blob_pack_length,
55
 
                       const CHARSET_INFO * const cs)
56
 
  :Field_str(ptr_arg,
57
 
             blob_pack_length_to_max_length(blob_pack_length),
58
 
             null_ptr_arg,
59
 
             null_bit_arg,
60
 
             field_name_arg,
61
 
             cs),
 
45
Field_blob::Field_blob(unsigned char *ptr_arg, unsigned char *null_ptr_arg, unsigned char null_bit_arg,
 
46
                       enum utype unireg_check_arg, const char *field_name_arg,
 
47
                       TableShare *share, uint32_t blob_pack_length,
 
48
                       const CHARSET_INFO * const cs)
 
49
  :Field_str(ptr_arg, blob_pack_length_to_max_length(blob_pack_length),
 
50
                 null_ptr_arg, null_bit_arg, unireg_check_arg, field_name_arg,
 
51
                 cs),
62
52
   packlength(blob_pack_length)
63
53
{
64
54
  flags|= BLOB_FLAG;
66
56
  /* TODO: why do not fill table->s->blob_field array here? */
67
57
}
68
58
 
 
59
 
69
60
void Field_blob::store_length(unsigned char *i_ptr,
70
61
                              uint32_t i_packlength,
71
62
                              uint32_t i_number,
235
226
  if (value.alloc(new_length))
236
227
    goto oom_error;
237
228
 
 
229
 
 
230
  if (f_is_hex_escape(flags))
 
231
  {
 
232
    copy_length= my_copy_with_hex_escaping(field_charset,
 
233
                                           (char*) value.ptr(), new_length,
 
234
                                            from, length);
 
235
    Field_blob::store_length(copy_length);
 
236
    tmp= value.ptr();
 
237
    memmove(ptr + packlength, &tmp, sizeof(char*));
 
238
    return 0;
 
239
  }
238
240
  /*
239
241
    "length" is OK as "nchars" argument to well_formed_copy_nchars as this
240
242
    is never used to limit the length of the data. The cut of long data
414
416
  if ((uint32_t) length > blob_length)
415
417
  {
416
418
    /*
417
 
      Must clear this as we do a memcmp in optimizer/range.cc to detect
 
419
      Must clear this as we do a memcmp in opt_range.cc to detect
418
420
      identical keys
419
421
    */
420
422
    memset(buff+HA_KEY_BLOB_LENGTH+blob_length, 0, (length-blob_length));
445
447
  if (length > blob_length)
446
448
  {
447
449
    /*
448
 
      Must clear this as we do a memcmp in optimizer/range.cc to detect
 
450
      Must clear this as we do a memcmp in opt_range.cc to detect
449
451
      identical keys
450
452
    */
451
453
 
481
483
                         b+HA_KEY_BLOB_LENGTH, uint2korr(b));
482
484
}
483
485
 
 
486
/**
 
487
   Save the field metadata for blob fields.
 
488
 
 
489
   Saves the pack length in the first byte of the field metadata array
 
490
   at index of *metadata_ptr.
 
491
 
 
492
   @param   metadata_ptr   First byte of field metadata
 
493
 
 
494
   @returns number of bytes written to metadata_ptr
 
495
*/
 
496
int Field_blob::do_save_field_metadata(unsigned char *metadata_ptr)
 
497
{
 
498
  *metadata_ptr= pack_length_no_ptr();
 
499
  return 1;
 
500
}
 
501
 
484
502
uint32_t Field_blob::sort_length() const
485
503
{
486
504
  return (uint32_t) (current_session->variables.max_sort_length +
587
605
   @return  New pointer into memory based on from + length of the data
588
606
*/
589
607
const unsigned char *Field_blob::unpack(unsigned char *,
590
 
                                        const unsigned char *from,
591
 
                                        uint32_t param_data,
592
 
                                        bool low_byte_first)
 
608
                                const unsigned char *from,
 
609
                                uint32_t param_data,
 
610
                                bool low_byte_first)
593
611
{
594
612
  uint32_t const master_packlength=
595
613
    param_data > 0 ? param_data & 0xFF : packlength;
626
644
}
627
645
 
628
646
 
 
647
uint32_t Field_blob::is_equal(CreateField *new_field_ptr)
 
648
{
 
649
  if (compare_str_field_flags(new_field_ptr, flags))
 
650
    return 0;
 
651
  Field_blob *blob_field_ptr= static_cast<Field_blob *>(new_field_ptr->field);
 
652
 
 
653
  return (new_field_ptr->sql_type == DRIZZLE_TYPE_BLOB
 
654
          && new_field_ptr->charset == field_charset
 
655
          && blob_field_ptr->max_data_length() == max_data_length());
 
656
}
 
657
 
 
658
 
629
659
/**
630
660
  maximum possible display length for blob.
631
661
 
650
680
    return 0;
651
681
  }
652
682
}
653
 
 
654
 
} /* namespace drizzled */