611
611
return(from + master_packlength + length);
614
/* Keys for blobs are like keys on varchars */
616
int Field_blob::pack_cmp(const unsigned char *a, const unsigned char *b, uint32_t key_length_arg,
617
bool insert_or_update)
619
uint32_t a_length, b_length;
620
if (key_length_arg > 255)
622
a_length=uint2korr(a); a+=2;
623
b_length=uint2korr(b); b+=2;
627
a_length= (uint32_t) *a++;
628
b_length= (uint32_t) *b++;
630
return field_charset->coll->strnncollsp(field_charset,
637
int Field_blob::pack_cmp(const unsigned char *b, uint32_t key_length_arg,
638
bool insert_or_update)
641
uint32_t a_length, b_length;
642
memcpy(&a,ptr+packlength,sizeof(char*));
644
return key_length_arg > 0 ? -1 : 0;
646
a_length= get_length(ptr);
647
if (key_length_arg > 255)
649
b_length= uint2korr(b); b+=2;
652
b_length= (uint32_t) *b++;
653
return field_charset->coll->strnncollsp(field_charset,
659
614
/** Create a packed key that will be used for storage from a MySQL row. */
686
Unpack a blob key into a record buffer.
688
A blob key has a maximum size of 64K-1.
689
In its packed form, the length field is one or two bytes long,
690
depending on 'max_length'.
691
Depending on the maximum length of a blob, its length field is
692
put into 1 to 4 bytes. This is a property of the blob object,
693
described by 'packlength'.
694
Blobs are internally stored apart from the record buffer, which
695
contains a pointer to the blob buffer.
698
@param to Pointer into the record buffer.
699
@param from Pointer to the packed key.
700
@param max_length Key length limit from key description.
703
Pointer into 'from' past the last byte copied from packed key.
706
const unsigned char *
707
Field_blob::unpack_key(unsigned char *to, const unsigned char *from, uint32_t max_length,
710
/* get length of the blob key */
711
uint32_t length= *from++;
712
if (max_length > 255)
713
length+= *from++ << 8;
715
/* put the length into the record buffer */
716
put_length(to, length);
718
/* put the address of the blob buffer or NULL */
720
memcpy(to + packlength, &from, sizeof(from));
722
memset(to + packlength, 0, sizeof(from));
724
/* point to first byte of next field in 'from' */
725
return from + length;
729
/** Create a packed key that will be used for storage from a MySQL key. */
732
Field_blob::pack_key_from_key_image(unsigned char *to, const unsigned char *from, uint32_t max_length,
735
uint32_t length=uint2korr(from);
736
if (length > max_length)
738
*to++= (char) (length & 255);
739
if (max_length > 255)
740
*to++= (char) (length >> 8);
742
memcpy(to, from+HA_KEY_BLOB_LENGTH, length);
747
uint32_t Field_blob::packed_col_length(const unsigned char *data_ptr, uint32_t length)
750
return uint2korr(data_ptr)+2;
751
return (uint32_t) *data_ptr + 1;
755
uint32_t Field_blob::max_packed_col_length(uint32_t max_length)
757
return (max_length > 255 ? 2 : 1)+max_length;
761
640
uint32_t Field_blob::is_equal(Create_field *new_field_ptr)
763
642
if (compare_str_field_flags(new_field_ptr, flags))