diff options
Diffstat (limited to 'sql/field.cc')
-rw-r--r-- | sql/field.cc | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/sql/field.cc b/sql/field.cc index 0225e24b195..e8718c9e407 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -6403,6 +6403,15 @@ uint Field_string::max_packed_col_length(uint max_length) return (max_length > 255 ? 2 : 1)+max_length; } +uint Field_string::get_key_image(char *buff, uint length, imagetype type_arg) +{ + uint bytes = my_charpos(field_charset, ptr, ptr + field_length, + length / field_charset->mbmaxlen); + memcpy(buff, ptr, bytes); + if (bytes < length) + bzero(buff + bytes, length - bytes); + return bytes; +} Field *Field_string::new_field(MEM_ROOT *root, struct st_table *new_table, bool keep_type) @@ -6861,9 +6870,7 @@ uint Field_varstring::max_packed_col_length(uint max_length) return (max_length > 255 ? 2 : 1)+max_length; } - -void Field_varstring::get_key_image(char *buff, uint length, - imagetype type_arg) +uint Field_varstring::get_key_image(char *buff, uint length, imagetype type) { uint f_length= length_bytes == 1 ? (uint) (uchar) *ptr : uint2korr(ptr); uint local_char_length= length / field_charset->mbmaxlen; @@ -6882,6 +6889,7 @@ void Field_varstring::get_key_image(char *buff, uint length, */ bzero(buff+HA_KEY_BLOB_LENGTH+f_length, (length-f_length)); } + return HA_KEY_BLOB_LENGTH+f_length; } @@ -7286,7 +7294,7 @@ int Field_blob::cmp_binary(const char *a_ptr, const char *b_ptr, /* The following is used only when comparing a key */ -void Field_blob::get_key_image(char *buff, uint length, imagetype type_arg) +uint Field_blob::get_key_image(char *buff,uint length, imagetype type_arg) { uint32 blob_length= get_length(ptr); char *blob; @@ -7298,16 +7306,17 @@ void Field_blob::get_key_image(char *buff, uint length, imagetype type_arg) MBR mbr; Geometry_buffer buffer; Geometry *gobj; + const uint image_length= SIZEOF_STORED_DOUBLE*4; if (blob_length < SRID_SIZE) { - bzero(buff, SIZEOF_STORED_DOUBLE*4); - return; + bzero(buff, image_length); + return image_length; } get_ptr(&blob); gobj= Geometry::construct(&buffer, blob, blob_length); if (!gobj || gobj->get_mbr(&mbr, &dummy)) - bzero(buff, SIZEOF_STORED_DOUBLE*4); + bzero(buff, image_length); else { float8store(buff, mbr.xmin); @@ -7315,7 +7324,7 @@ void Field_blob::get_key_image(char *buff, uint length, imagetype type_arg) float8store(buff+16, mbr.ymin); float8store(buff+24, mbr.ymax); } - return; + return image_length; } #endif /*HAVE_SPATIAL*/ @@ -7336,6 +7345,7 @@ void Field_blob::get_key_image(char *buff, uint length, imagetype type_arg) } int2store(buff,length); memcpy(buff+HA_KEY_BLOB_LENGTH, blob, length); + return HA_KEY_BLOB_LENGTH+length; } @@ -7633,7 +7643,7 @@ uint Field_blob::is_equal(create_field *new_field) #ifdef HAVE_SPATIAL -void Field_geom::get_key_image(char *buff, uint length, imagetype type_arg) +uint Field_geom::get_key_image(char *buff, uint length, imagetype type) { char *blob; const char *dummy; @@ -7641,16 +7651,17 @@ void Field_geom::get_key_image(char *buff, uint length, imagetype type_arg) ulong blob_length= get_length(ptr); Geometry_buffer buffer; Geometry *gobj; + const uint image_length= SIZEOF_STORED_DOUBLE*4; if (blob_length < SRID_SIZE) { - bzero(buff, SIZEOF_STORED_DOUBLE*4); - return; + bzero(buff, image_length); + return image_length; } get_ptr(&blob); gobj= Geometry::construct(&buffer, blob, blob_length); if (!gobj || gobj->get_mbr(&mbr, &dummy)) - bzero(buff, SIZEOF_STORED_DOUBLE*4); + bzero(buff, image_length); else { float8store(buff, mbr.xmin); @@ -7658,6 +7669,7 @@ void Field_geom::get_key_image(char *buff, uint length, imagetype type_arg) float8store(buff + 16, mbr.ymin); float8store(buff + 24, mbr.ymax); } + return image_length; } @@ -8441,7 +8453,7 @@ int Field_bit::cmp_offset(uint row_offset) } -void Field_bit::get_key_image(char *buff, uint length, imagetype type_arg) +uint Field_bit::get_key_image(char *buff, uint length, imagetype type_arg) { if (bit_len) { @@ -8449,7 +8461,9 @@ void Field_bit::get_key_image(char *buff, uint length, imagetype type_arg) *buff++= bits; length--; } - memcpy(buff, ptr, min(length, bytes_in_rec)); + uint data_length = min(length, bytes_in_rec); + memcpy(buff, ptr, data_length); + return data_length + 1; } |