43
43
/****************************************************************************
45
45
** A blob is saved as a length and a pointer. The length is stored in the
46
** packlength slot and may be from 1-4.
46
** packlength slot and is sizeof(uint32_t) (4 bytes)
47
47
****************************************************************************/
49
49
Field_blob::Field_blob(unsigned char *ptr_arg,
51
51
unsigned char null_bit_arg,
52
52
const char *field_name_arg,
54
uint32_t blob_pack_length,
55
54
const CHARSET_INFO * const cs)
56
55
:Field_str(ptr_arg,
57
blob_pack_length_to_max_length(blob_pack_length),
56
blob_pack_length_to_max_length(sizeof(uint32_t)),
62
packlength(blob_pack_length)
65
63
share->blob_fields++;
69
67
void Field_blob::store_length(unsigned char *i_ptr,
70
uint32_t i_packlength,
72
69
bool low_byte_first)
74
71
#ifndef WORDS_BIGENDIAN
75
72
(void)low_byte_first;
77
switch (i_packlength) {
79
i_ptr[0]= (unsigned char) i_number;
82
#ifdef WORDS_BIGENDIAN
85
int2store(i_ptr,(unsigned short) i_number);
89
shortstore(i_ptr,(unsigned short) i_number);
92
int3store(i_ptr,i_number);
95
#ifdef WORDS_BIGENDIAN
98
int4store(i_ptr,i_number);
102
longstore(i_ptr,i_number);
75
#ifdef WORDS_BIGENDIAN
78
int4store(i_ptr,i_number);
82
longstore(i_ptr,i_number);
107
void Field_blob::store_length(unsigned char *i_ptr, uint32_t i_packlength,
86
void Field_blob::store_length(unsigned char *i_ptr, uint32_t i_number)
110
store_length(i_ptr, i_packlength, i_number, getTable()->getShare()->db_low_byte_first);
88
store_length(i_ptr, i_number, getTable()->getShare()->db_low_byte_first);
114
92
uint32_t Field_blob::get_length(const unsigned char *pos,
115
uint32_t packlength_arg,
116
93
bool low_byte_first)
118
95
#ifndef WORDS_BIGENDIAN
119
96
(void)low_byte_first;
121
switch (packlength_arg) {
123
return (uint32_t) pos[0];
127
#ifdef WORDS_BIGENDIAN
133
return (uint32_t) tmp;
136
return (uint32_t) uint3korr(pos);
140
#ifdef WORDS_BIGENDIAN
146
return (uint32_t) tmp;
149
return 0; // Impossible
99
#ifdef WORDS_BIGENDIAN
105
return (uint32_t) tmp;
153
109
uint32_t Field_blob::get_packed_size(const unsigned char *ptr_arg,
154
110
bool low_byte_first)
156
return packlength + get_length(ptr_arg, packlength, low_byte_first);
112
return sizeof(uint32_t) + get_length(ptr_arg, low_byte_first);
160
116
uint32_t Field_blob::get_length(uint32_t row_offset)
162
return get_length(ptr+row_offset, this->packlength,
118
return get_length(ptr+row_offset,
163
119
getTable()->getShare()->db_low_byte_first);
167
123
uint32_t Field_blob::get_length(const unsigned char *ptr_arg)
169
return get_length(ptr_arg, this->packlength, getTable()->getShare()->db_low_byte_first);
125
return get_length(ptr_arg, getTable()->getShare()->db_low_byte_first);
174
130
Put a blob length field into a record buffer.
176
Depending on the maximum length of a blob, its length field is
177
put into 1 to 4 bytes. This is a property of the blob object,
178
described by 'packlength'.
132
Blob length is always stored in sizeof(uint32_t) (4 bytes)
180
134
@param pos Pointer into the record buffer.
181
135
@param length The length value to put.
223
164
if (!String::needs_conversion(length, cs, field_charset, &dummy_offset))
225
166
Field_blob::store_length(length);
226
memmove(ptr+packlength, &from, sizeof(char*));
167
memmove(ptr+sizeof(uint32_t), &from, sizeof(char*));
229
170
if (tmpstr.copy(from, length, cs))
251
192
Field_blob::store_length(copy_length);
252
193
tmp= value.ptr();
253
memmove(ptr+packlength, &tmp, sizeof(char*));
194
memmove(ptr+sizeof(uint32_t), &tmp, sizeof(char*));
255
196
if (check_string_copy_error(this, well_formed_error_pos,
256
197
cannot_convert_error_pos, from + length, cs))
323
264
ASSERT_COLUMN_MARKED_FOR_READ;
325
memcpy(&blob,ptr+packlength,sizeof(char*));
266
memcpy(&blob,ptr+sizeof(uint32_t),sizeof(char*));
327
268
val_ptr->set("",0,charset()); // A bit safer than ->length(0)
366
307
uint32_t max_length)
368
309
unsigned char *blob1,*blob2;
369
memcpy(&blob1,a_ptr+packlength,sizeof(char*));
370
memcpy(&blob2,b_ptr+packlength,sizeof(char*));
310
memcpy(&blob1,a_ptr+sizeof(uint32_t),sizeof(char*));
311
memcpy(&blob2,b_ptr+sizeof(uint32_t),sizeof(char*));
371
312
uint32_t a_len= get_length(a_ptr), b_len= get_length(b_ptr);
372
313
set_if_smaller(a_len, max_length);
373
314
set_if_smaller(b_len, max_length);
383
324
uint32_t a_length,b_length;
384
memcpy(&a,a_ptr+packlength,sizeof(char*));
385
memcpy(&b,b_ptr+packlength,sizeof(char*));
325
memcpy(&a,a_ptr+sizeof(uint32_t),sizeof(char*));
326
memcpy(&b,b_ptr+sizeof(uint32_t),sizeof(char*));
387
328
a_length= get_length(a_ptr);
465
406
unsigned char *blob1;
466
407
uint32_t blob_length=get_length(ptr);
467
memcpy(&blob1,ptr+packlength,sizeof(char*));
408
memcpy(&blob1,ptr+sizeof(uint32_t),sizeof(char*));
468
409
const CHARSET_INFO * const cs= charset();
469
410
uint32_t local_char_length= max_key_length / cs->mbmaxlen;
470
411
local_char_length= my_charpos(cs, blob1, blob1+blob_length,
504
445
Store length of blob last in blob to shorter blobs before longer blobs
447
length-= sizeof(uint32_t); // size of stored blob length
509
switch (packlength) {
511
*pos= (char) blob_length;
514
mi_int2store(pos, blob_length);
517
mi_int3store(pos, blob_length);
520
mi_int4store(pos, blob_length);
450
mi_int4store(pos, blob_length);
524
memcpy(&blob,ptr+packlength,sizeof(char*));
452
memcpy(&blob,ptr+sizeof(uint32_t),sizeof(char*));
526
454
blob_length=my_strnxfrm(field_charset,
527
455
to, length, blob, blob_length);
554
482
length given is smaller than the actual length of the blob, we
555
483
just store the initial bytes of the blob.
557
store_length(to, packlength, min(length, max_length), low_byte_first);
485
store_length(to, min(length, max_length), low_byte_first);
560
488
Store the actual blob data, which will occupy 'length' bytes.
564
492
get_ptr((unsigned char**) &from);
565
memcpy(to+packlength, from,length);
493
memcpy(to+sizeof(uint32_t), from,length);
568
496
ptr= save; // Restore org row pointer
569
return(to+packlength+length);
497
return(to+sizeof(uint32_t)+length);
589
517
const unsigned char *Field_blob::unpack(unsigned char *,
590
518
const unsigned char *from,
592
520
bool low_byte_first)
594
uint32_t const master_packlength=
595
param_data > 0 ? param_data & 0xFF : packlength;
596
uint32_t const length= get_length(from, master_packlength, low_byte_first);
522
uint32_t const length= get_length(from, low_byte_first);
597
523
getTable()->setWriteSet(field_index);
598
store(reinterpret_cast<const char*>(from) + master_packlength,
524
store(reinterpret_cast<const char*>(from) + sizeof(uint32_t),
599
525
length, field_charset);
600
return(from + master_packlength + length);
526
return(from + sizeof(uint32_t) + length);
603
529
/** Create a packed key that will be used for storage from a MySQL row. */
636
562
uint32_t Field_blob::max_display_length()
641
return 255 * field_charset->mbmaxlen;
643
return 65535 * field_charset->mbmaxlen;
645
return 16777215 * field_charset->mbmaxlen;
647
564
return (uint32_t) 4294967295U;
649
assert(0); // we should never go here
654
567
} /* namespace drizzled */