51
51
unsigned char null_bit_arg,
52
52
const char *field_name_arg,
54
uint32_t blob_pack_length,
54
55
const CHARSET_INFO * const cs)
55
56
:Field_str(ptr_arg,
56
blob_pack_length_to_max_length(sizeof(uint32_t)),
57
blob_pack_length_to_max_length(blob_pack_length),
62
packlength(blob_pack_length)
63
65
share->blob_fields++;
67
69
void Field_blob::store_length(unsigned char *i_ptr,
70
uint32_t i_packlength,
69
72
bool low_byte_first)
71
74
#ifndef WORDS_BIGENDIAN
72
75
(void)low_byte_first;
75
#ifdef WORDS_BIGENDIAN
78
int4store(i_ptr,i_number);
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);
82
longstore(i_ptr,i_number);
86
void Field_blob::store_length(unsigned char *i_ptr, uint32_t i_number)
107
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);
110
store_length(i_ptr, i_packlength, i_number, table->getShare()->db_low_byte_first);
92
114
uint32_t Field_blob::get_length(const unsigned char *pos,
93
bool low_byte_first) const
115
uint32_t packlength_arg,
95
118
#ifndef WORDS_BIGENDIAN
96
119
(void)low_byte_first;
99
#ifdef WORDS_BIGENDIAN
105
return (uint32_t) tmp;
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
109
153
uint32_t Field_blob::get_packed_size(const unsigned char *ptr_arg,
110
154
bool low_byte_first)
112
return sizeof(uint32_t) + get_length(ptr_arg, low_byte_first);
116
uint32_t Field_blob::get_length(uint32_t row_offset) const
118
return get_length(ptr+row_offset,
119
getTable()->getShare()->db_low_byte_first);
123
uint32_t Field_blob::get_length(const unsigned char *ptr_arg) const
125
return get_length(ptr_arg, getTable()->getShare()->db_low_byte_first);
156
return packlength + get_length(ptr_arg, packlength, low_byte_first);
160
uint32_t Field_blob::get_length(uint32_t row_offset)
162
return get_length(ptr+row_offset, this->packlength,
163
table->getShare()->db_low_byte_first);
167
uint32_t Field_blob::get_length(const unsigned char *ptr_arg)
169
return get_length(ptr_arg, this->packlength, table->getShare()->db_low_byte_first);
130
174
Put a blob length field into a record buffer.
132
Blob length is always stored in sizeof(uint32_t) (4 bytes)
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'.
134
180
@param pos Pointer into the record buffer.
135
181
@param length The length value to put.
161
220
if (from == value.ptr())
222
uint32_t dummy_offset;
164
223
if (!String::needs_conversion(length, cs, field_charset, &dummy_offset))
166
225
Field_blob::store_length(length);
167
memmove(ptr+sizeof(uint32_t), &from, sizeof(char*));
226
memmove(ptr+packlength, &from, sizeof(char*));
170
229
if (tmpstr.copy(from, length, cs))
192
251
Field_blob::store_length(copy_length);
193
252
tmp= value.ptr();
194
memmove(ptr+sizeof(uint32_t), &tmp, sizeof(char*));
253
memmove(ptr+packlength, &tmp, sizeof(char*));
196
255
if (check_string_copy_error(this, well_formed_error_pos,
197
256
cannot_convert_error_pos, from + length, cs))
245
int64_t Field_blob::val_int(void) const
304
int64_t Field_blob::val_int(void)
250
309
ASSERT_COLUMN_MARKED_FOR_READ;
252
memcpy(&blob,ptr+sizeof(uint32_t),sizeof(char*));
311
memcpy(&blob,ptr+packlength,sizeof(char*));
255
uint32_t length= get_length(ptr);
314
uint32_t length=get_length(ptr);
256
315
return my_strntoll(charset(),blob,length,10,NULL,¬_used);
259
String *Field_blob::val_str(String *, String *val_ptr) const
318
String *Field_blob::val_str(String *,
263
323
ASSERT_COLUMN_MARKED_FOR_READ;
265
memcpy(&blob,ptr+sizeof(uint32_t),sizeof(char*));
325
memcpy(&blob,ptr+packlength,sizeof(char*));
267
327
val_ptr->set("",0,charset()); // A bit safer than ->length(0)
274
type::Decimal *Field_blob::val_decimal(type::Decimal *decimal_value) const
334
my_decimal *Field_blob::val_decimal(my_decimal *decimal_value)
276
336
const char *blob;
279
339
ASSERT_COLUMN_MARKED_FOR_READ;
281
memcpy(&blob, ptr+sizeof(uint32_t), sizeof(const unsigned char*));
341
memcpy(&blob, ptr+packlength, sizeof(const unsigned char*));
289
348
length= get_length(ptr);
292
decimal_value->store(E_DEC_FATAL_ERROR, blob, length, charset());
350
str2my_decimal(E_DEC_FATAL_ERROR, blob, length, charset(),
294
352
return decimal_value;
308
366
uint32_t max_length)
310
368
unsigned char *blob1,*blob2;
311
memcpy(&blob1,a_ptr+sizeof(uint32_t),sizeof(char*));
312
memcpy(&blob2,b_ptr+sizeof(uint32_t),sizeof(char*));
369
memcpy(&blob1,a_ptr+packlength,sizeof(char*));
370
memcpy(&blob2,b_ptr+packlength,sizeof(char*));
313
371
uint32_t a_len= get_length(a_ptr), b_len= get_length(b_ptr);
314
372
set_if_smaller(a_len, max_length);
315
373
set_if_smaller(b_len, max_length);
325
383
uint32_t a_length,b_length;
326
memcpy(&a,a_ptr+sizeof(uint32_t),sizeof(char*));
327
memcpy(&b,b_ptr+sizeof(uint32_t),sizeof(char*));
384
memcpy(&a,a_ptr+packlength,sizeof(char*));
385
memcpy(&b,b_ptr+packlength,sizeof(char*));
329
387
a_length= get_length(a_ptr);
407
465
unsigned char *blob1;
408
466
uint32_t blob_length=get_length(ptr);
409
memcpy(&blob1,ptr+sizeof(uint32_t),sizeof(char*));
467
memcpy(&blob1,ptr+packlength,sizeof(char*));
410
468
const CHARSET_INFO * const cs= charset();
411
469
uint32_t local_char_length= max_key_length / cs->mbmaxlen;
412
470
local_char_length= my_charpos(cs, blob1, blob1+blob_length,
446
504
Store length of blob last in blob to shorter blobs before longer blobs
448
length-= sizeof(uint32_t); // size of stored blob length
451
mi_int4store(pos, 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);
453
memcpy(&blob,ptr+sizeof(uint32_t),sizeof(char*));
524
memcpy(&blob,ptr+packlength,sizeof(char*));
455
526
blob_length=my_strnxfrm(field_charset,
456
527
to, length, blob, blob_length);
483
554
length given is smaller than the actual length of the blob, we
484
555
just store the initial bytes of the blob.
486
store_length(to, min(length, max_length), low_byte_first);
557
store_length(to, packlength, min(length, max_length), low_byte_first);
489
560
Store the actual blob data, which will occupy 'length' bytes.
493
564
get_ptr((unsigned char**) &from);
494
memcpy(to+sizeof(uint32_t), from,length);
565
memcpy(to+packlength, from,length);
497
568
ptr= save; // Restore org row pointer
498
return(to+sizeof(uint32_t)+length);
569
return(to+packlength+length);
518
589
const unsigned char *Field_blob::unpack(unsigned char *,
519
590
const unsigned char *from,
521
592
bool low_byte_first)
523
uint32_t const length= get_length(from, low_byte_first);
524
getTable()->setWriteSet(position());
525
store(reinterpret_cast<const char*>(from) + sizeof(uint32_t),
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);
597
table->setWriteSet(field_index);
598
store(reinterpret_cast<const char*>(from) + master_packlength,
526
599
length, field_charset);
527
return(from + sizeof(uint32_t) + length);
600
return(from + master_packlength + length);
530
603
/** Create a packed key that will be used for storage from a MySQL row. */