51
48
unsigned char null_bit_arg,
52
49
const char *field_name_arg,
51
uint32_t blob_pack_length,
54
52
const CHARSET_INFO * const cs)
55
53
:Field_str(ptr_arg,
56
blob_pack_length_to_max_length(sizeof(uint32_t)),
54
blob_pack_length_to_max_length(blob_pack_length),
59
packlength(blob_pack_length)
63
62
share->blob_fields++;
64
/* TODO: why do not fill table->getShare()->blob_field array here? */
63
/* TODO: why do not fill table->s->blob_field array here? */
67
66
void Field_blob::store_length(unsigned char *i_ptr,
67
uint32_t i_packlength,
69
69
bool low_byte_first)
71
71
#ifndef WORDS_BIGENDIAN
72
72
(void)low_byte_first;
75
#ifdef WORDS_BIGENDIAN
78
int4store(i_ptr,i_number);
74
switch (i_packlength) {
76
i_ptr[0]= (unsigned char) i_number;
79
#ifdef WORDS_BIGENDIAN
82
int2store(i_ptr,(unsigned short) i_number);
86
shortstore(i_ptr,(unsigned short) i_number);
89
int3store(i_ptr,i_number);
92
#ifdef WORDS_BIGENDIAN
95
int4store(i_ptr,i_number);
99
longstore(i_ptr,i_number);
82
longstore(i_ptr,i_number);
86
void Field_blob::store_length(unsigned char *i_ptr, uint32_t i_number)
104
void Field_blob::store_length(unsigned char *i_ptr, uint32_t i_packlength,
88
store_length(i_ptr, i_number, getTable()->getShare()->db_low_byte_first);
107
store_length(i_ptr, i_packlength, i_number, table->s->db_low_byte_first);
92
111
uint32_t Field_blob::get_length(const unsigned char *pos,
112
uint32_t packlength_arg,
93
113
bool low_byte_first)
95
115
#ifndef WORDS_BIGENDIAN
96
116
(void)low_byte_first;
99
#ifdef WORDS_BIGENDIAN
105
return (uint32_t) tmp;
118
switch (packlength_arg) {
120
return (uint32_t) pos[0];
124
#ifdef WORDS_BIGENDIAN
130
return (uint32_t) tmp;
133
return (uint32_t) uint3korr(pos);
137
#ifdef WORDS_BIGENDIAN
143
return (uint32_t) tmp;
146
return 0; // Impossible
109
150
uint32_t Field_blob::get_packed_size(const unsigned char *ptr_arg,
110
151
bool low_byte_first)
112
return sizeof(uint32_t) + get_length(ptr_arg, low_byte_first);
153
return packlength + get_length(ptr_arg, packlength, low_byte_first);
116
157
uint32_t Field_blob::get_length(uint32_t row_offset)
118
return get_length(ptr+row_offset,
119
getTable()->getShare()->db_low_byte_first);
159
return get_length(ptr+row_offset, this->packlength,
160
table->s->db_low_byte_first);
123
164
uint32_t Field_blob::get_length(const unsigned char *ptr_arg)
125
return get_length(ptr_arg, getTable()->getShare()->db_low_byte_first);
166
return get_length(ptr_arg, this->packlength, table->s->db_low_byte_first);
130
171
Put a blob length field into a record buffer.
132
Blob length is always stored in sizeof(uint32_t) (4 bytes)
173
Depending on the maximum length of a blob, its length field is
174
put into 1 to 4 bytes. This is a property of the blob object,
175
described by 'packlength'.
134
177
@param pos Pointer into the record buffer.
135
178
@param length The length value to put.
161
217
if (from == value.ptr())
219
uint32_t dummy_offset;
164
220
if (!String::needs_conversion(length, cs, field_charset, &dummy_offset))
166
222
Field_blob::store_length(length);
167
memmove(ptr+sizeof(uint32_t), &from, sizeof(char*));
223
memmove(ptr+packlength, &from, sizeof(char*));
170
226
if (tmpstr.copy(from, length, cs))
307
363
uint32_t max_length)
309
365
unsigned char *blob1,*blob2;
310
memcpy(&blob1,a_ptr+sizeof(uint32_t),sizeof(char*));
311
memcpy(&blob2,b_ptr+sizeof(uint32_t),sizeof(char*));
366
memcpy(&blob1,a_ptr+packlength,sizeof(char*));
367
memcpy(&blob2,b_ptr+packlength,sizeof(char*));
312
368
uint32_t a_len= get_length(a_ptr), b_len= get_length(b_ptr);
313
369
set_if_smaller(a_len, max_length);
314
370
set_if_smaller(b_len, max_length);
324
380
uint32_t a_length,b_length;
325
memcpy(&a,a_ptr+sizeof(uint32_t),sizeof(char*));
326
memcpy(&b,b_ptr+sizeof(uint32_t),sizeof(char*));
381
memcpy(&a,a_ptr+packlength,sizeof(char*));
382
memcpy(&b,b_ptr+packlength,sizeof(char*));
328
384
a_length= get_length(a_ptr);
406
462
unsigned char *blob1;
407
463
uint32_t blob_length=get_length(ptr);
408
memcpy(&blob1,ptr+sizeof(uint32_t),sizeof(char*));
464
memcpy(&blob1,ptr+packlength,sizeof(char*));
409
465
const CHARSET_INFO * const cs= charset();
410
466
uint32_t local_char_length= max_key_length / cs->mbmaxlen;
411
467
local_char_length= my_charpos(cs, blob1, blob1+blob_length,
445
501
Store length of blob last in blob to shorter blobs before longer blobs
447
length-= sizeof(uint32_t); // size of stored blob length
450
mi_int4store(pos, blob_length);
506
switch (packlength) {
508
*pos= (char) blob_length;
511
mi_int2store(pos, blob_length);
514
mi_int3store(pos, blob_length);
517
mi_int4store(pos, blob_length);
452
memcpy(&blob,ptr+sizeof(uint32_t),sizeof(char*));
521
memcpy(&blob,ptr+packlength,sizeof(char*));
454
523
blob_length=my_strnxfrm(field_charset,
455
524
to, length, blob, blob_length);
482
551
length given is smaller than the actual length of the blob, we
483
552
just store the initial bytes of the blob.
485
store_length(to, min(length, max_length), low_byte_first);
554
store_length(to, packlength, min(length, max_length), low_byte_first);
488
557
Store the actual blob data, which will occupy 'length' bytes.
517
586
const unsigned char *Field_blob::unpack(unsigned char *,
518
587
const unsigned char *from,
520
589
bool low_byte_first)
522
uint32_t const length= get_length(from, low_byte_first);
523
getTable()->setWriteSet(position());
524
store(reinterpret_cast<const char*>(from) + sizeof(uint32_t),
591
uint32_t const master_packlength=
592
param_data > 0 ? param_data & 0xFF : packlength;
593
uint32_t const length= get_length(from, master_packlength, low_byte_first);
594
table->setWriteSet(field_index);
595
store(reinterpret_cast<const char*>(from) + master_packlength,
525
596
length, field_charset);
526
return(from + sizeof(uint32_t) + length);
597
return(from + master_packlength + length);
529
600
/** Create a packed key that will be used for storage from a MySQL row. */