40
40
/****************************************************************************
42
42
** A blob is saved as a length and a pointer. The length is stored in the
43
** packlength slot and may be from 1-4.
43
** packlength slot and is sizeof(uint32_t) (4 bytes)
44
44
****************************************************************************/
46
46
Field_blob::Field_blob(unsigned char *ptr_arg,
65
64
void Field_blob::store_length(unsigned char *i_ptr,
66
uint32_t i_packlength,
68
66
bool low_byte_first)
70
68
#ifndef WORDS_BIGENDIAN
71
69
(void)low_byte_first;
73
switch (i_packlength) {
75
i_ptr[0]= (unsigned char) i_number;
78
#ifdef WORDS_BIGENDIAN
81
int2store(i_ptr,(unsigned short) i_number);
85
shortstore(i_ptr,(unsigned short) i_number);
88
int3store(i_ptr,i_number);
91
#ifdef WORDS_BIGENDIAN
94
int4store(i_ptr,i_number);
98
longstore(i_ptr,i_number);
72
#ifdef WORDS_BIGENDIAN
75
int4store(i_ptr,i_number);
79
longstore(i_ptr,i_number);
103
void Field_blob::store_length(unsigned char *i_ptr, uint32_t i_packlength,
83
void Field_blob::store_length(unsigned char *i_ptr, uint32_t i_number)
106
store_length(i_ptr, i_packlength, i_number, table->s->db_low_byte_first);
85
store_length(i_ptr, i_number, table->s->db_low_byte_first);
110
89
uint32_t Field_blob::get_length(const unsigned char *pos,
111
uint32_t packlength_arg,
112
90
bool low_byte_first)
114
92
#ifndef WORDS_BIGENDIAN
115
93
(void)low_byte_first;
117
switch (packlength_arg) {
119
return (uint32_t) pos[0];
123
#ifdef WORDS_BIGENDIAN
129
return (uint32_t) tmp;
132
return (uint32_t) uint3korr(pos);
136
#ifdef WORDS_BIGENDIAN
142
return (uint32_t) tmp;
145
return 0; // Impossible
96
#ifdef WORDS_BIGENDIAN
102
return (uint32_t) tmp;
149
106
uint32_t Field_blob::get_packed_size(const unsigned char *ptr_arg,
150
107
bool low_byte_first)
152
return packlength + get_length(ptr_arg, packlength, low_byte_first);
109
return sizeof(uint32_t) + get_length(ptr_arg, low_byte_first);
156
113
uint32_t Field_blob::get_length(uint32_t row_offset)
158
return get_length(ptr+row_offset, this->packlength,
159
table->s->db_low_byte_first);
115
return get_length(ptr+row_offset, table->s->db_low_byte_first);
163
119
uint32_t Field_blob::get_length(const unsigned char *ptr_arg)
165
return get_length(ptr_arg, this->packlength, table->s->db_low_byte_first);
121
return get_length(ptr_arg, table->s->db_low_byte_first);
170
126
Put a blob length field into a record buffer.
172
Depending on the maximum length of a blob, its length field is
173
put into 1 to 4 bytes. This is a property of the blob object,
174
described by 'packlength'.
128
Blob length is always stored in sizeof(uint32_t) (4 bytes)
176
130
@param pos Pointer into the record buffer.
177
131
@param length The length value to put.
219
160
if (!String::needs_conversion(length, cs, field_charset, &dummy_offset))
221
162
Field_blob::store_length(length);
222
memmove(ptr+packlength, &from, sizeof(char*));
163
memmove(ptr+sizeof(uint32_t), &from, sizeof(char*));
225
166
if (tmpstr.copy(from, length, cs))
247
188
Field_blob::store_length(copy_length);
248
189
tmp= value.ptr();
249
memmove(ptr+packlength, &tmp, sizeof(char*));
190
memmove(ptr+sizeof(uint32_t), &tmp, sizeof(char*));
251
192
if (check_string_copy_error(this, well_formed_error_pos,
252
193
cannot_convert_error_pos, from + length, cs))
319
260
ASSERT_COLUMN_MARKED_FOR_READ;
321
memcpy(&blob,ptr+packlength,sizeof(char*));
262
memcpy(&blob,ptr+sizeof(uint32_t),sizeof(char*));
323
264
val_ptr->set("",0,charset()); // A bit safer than ->length(0)
362
303
uint32_t max_length)
364
305
unsigned char *blob1,*blob2;
365
memcpy(&blob1,a_ptr+packlength,sizeof(char*));
366
memcpy(&blob2,b_ptr+packlength,sizeof(char*));
306
memcpy(&blob1,a_ptr+sizeof(uint32_t),sizeof(char*));
307
memcpy(&blob2,b_ptr+sizeof(uint32_t),sizeof(char*));
367
308
uint32_t a_len= get_length(a_ptr), b_len= get_length(b_ptr);
368
309
set_if_smaller(a_len, max_length);
369
310
set_if_smaller(b_len, max_length);
379
320
uint32_t a_length,b_length;
380
memcpy(&a,a_ptr+packlength,sizeof(char*));
381
memcpy(&b,b_ptr+packlength,sizeof(char*));
321
memcpy(&a,a_ptr+sizeof(uint32_t),sizeof(char*));
322
memcpy(&b,b_ptr+sizeof(uint32_t),sizeof(char*));
383
324
a_length= get_length(a_ptr);
461
402
unsigned char *blob1;
462
403
uint32_t blob_length=get_length(ptr);
463
memcpy(&blob1,ptr+packlength,sizeof(char*));
404
memcpy(&blob1,ptr+sizeof(uint32_t),sizeof(char*));
464
405
const CHARSET_INFO * const cs= charset();
465
406
uint32_t local_char_length= max_key_length / cs->mbmaxlen;
466
407
local_char_length= my_charpos(cs, blob1, blob1+blob_length,
500
441
Store length of blob last in blob to shorter blobs before longer blobs
443
length-= sizeof(uint32_t); // size of stored blob length
505
switch (packlength) {
507
*pos= (char) blob_length;
510
mi_int2store(pos, blob_length);
513
mi_int3store(pos, blob_length);
516
mi_int4store(pos, blob_length);
446
mi_int4store(pos, blob_length);
520
memcpy(&blob,ptr+packlength,sizeof(char*));
448
memcpy(&blob,ptr+sizeof(uint32_t),sizeof(char*));
522
450
blob_length=my_strnxfrm(field_charset,
523
451
to, length, blob, blob_length);
550
478
length given is smaller than the actual length of the blob, we
551
479
just store the initial bytes of the blob.
553
store_length(to, packlength, min(length, max_length), low_byte_first);
481
store_length(to, min(length, max_length), low_byte_first);
556
484
Store the actual blob data, which will occupy 'length' bytes.
560
488
get_ptr((unsigned char**) &from);
561
memcpy(to+packlength, from,length);
489
memcpy(to+sizeof(uint32_t), from,length);
564
492
ptr= save; // Restore org row pointer
565
return(to+packlength+length);
493
return(to+sizeof(uint32_t)+length);
585
513
const unsigned char *Field_blob::unpack(unsigned char *,
586
514
const unsigned char *from,
588
516
bool low_byte_first)
590
uint32_t const master_packlength=
591
param_data > 0 ? param_data & 0xFF : packlength;
592
uint32_t const length= get_length(from, master_packlength, low_byte_first);
518
uint32_t const length= get_length(from, low_byte_first);
593
519
table->setWriteSet(field_index);
594
store(reinterpret_cast<const char*>(from) + master_packlength,
520
store(reinterpret_cast<const char*>(from) + sizeof(uint32_t),
595
521
length, field_charset);
596
return(from + master_packlength + length);
522
return(from + sizeof(uint32_t) + length);
599
525
/** Create a packed key that will be used for storage from a MySQL row. */