102
String *Item_func_md5::val_str(String *str)
105
String * sptr= args[0]->val_str(str);
106
str->set_charset(&my_charset_bin);
113
my_MD5Init (&context);
114
my_MD5Update (&context,(uchar *) sptr->ptr(), sptr->length());
115
my_MD5Final (digest, &context);
116
if (str->alloc(32)) // Ensure that memory is free
121
sprintf((char *) str->ptr(),
122
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
123
digest[0], digest[1], digest[2], digest[3],
124
digest[4], digest[5], digest[6], digest[7],
125
digest[8], digest[9], digest[10], digest[11],
126
digest[12], digest[13], digest[14], digest[15]);
127
str->length((uint) 32);
135
void Item_func_md5::fix_length_and_dec()
139
The MD5() function treats its parameter as being a case sensitive. Thus
140
we set binary collation on it so different instances of MD5() will be
143
args[0]->collation.set(
144
get_charset_by_csname(args[0]->collation.collation->csname,
145
MY_CS_BINSORT,MYF(0)), DERIVATION_COERCIBLE);
149
99
Concatenate args with the following premises:
150
100
If only one arg (which is ok), return value of arg;
223
173
now work in place in tmp_value to set it to res | res2
225
175
/* Chop the last characters in tmp_value that isn't in res2 */
226
tmp_value.length((uint32) (res2->ptr() - tmp_value.ptr()) +
176
tmp_value.length((uint32_t) (res2->ptr() - tmp_value.ptr()) +
228
178
/* Place res2 at start of tmp_value, remove chars before res2 */
229
if (tmp_value.replace(0,(uint32) (res2->ptr() - tmp_value.ptr()),
179
if (tmp_value.replace(0,(uint32_t) (res2->ptr() - tmp_value.ptr()),
392
342
now work in place in tmp_value to set it to res | sep_str | res2
394
344
/* Chop the last characters in tmp_value that isn't in res2 */
395
tmp_value.length((uint32) (res2->ptr() - tmp_value.ptr()) +
345
tmp_value.length((uint32_t) (res2->ptr() - tmp_value.ptr()) +
397
347
/* Place res2 at start of tmp_value, remove chars before res2 */
398
if (tmp_value.replace(0,(uint32) (res2->ptr() - tmp_value.ptr()),
348
if (tmp_value.replace(0,(uint32_t) (res2->ptr() - tmp_value.ptr()),
400
350
tmp_value.replace(res->length(),0, *sep_str))
695
645
/* start and length are now sufficiently valid to pass to charpos function */
696
646
start= res->charpos((int) start);
697
length= res->charpos((int) length, (uint32) start);
647
length= res->charpos((int) length, (uint32_t) start);
699
649
/* Re-testing with corrected params */
700
650
if (start > res->length())
714
664
res=copy_if_not_alloced(str,res,res->length());
715
res->replace((uint32) start,(uint32) length,*res2);
665
res->replace((uint32_t) start,(uint32_t) length,*res2);
903
853
if ((start < 0) || ((uint) start + 1 > res->length()))
904
854
return &my_empty_string;
906
length= res->charpos((int) length, (uint32) start);
856
length= res->charpos((int) length, (uint32_t) start);
907
857
tmp_length= res->length() - start;
908
858
length= min(length, tmp_length);
910
860
if (!start && (int64_t) res->length() == length)
912
tmp_value.set(*res, (uint32) start, (uint32) length);
862
tmp_value.set(*res, (uint32_t) start, (uint32_t) length);
913
863
return &tmp_value;
921
871
collation.set(args[0]->collation);
922
872
if (args[1]->const_item())
924
int32 start= (int32) args[1]->val_int();
874
int32_t start= (int32_t) args[1]->val_int();
926
876
max_length= ((uint)(-start) > max_length) ? 0 : (uint)(-start);
953
903
assert(fixed == 1);
954
904
String *res= args[0]->val_str(str);
955
905
String *delimiter= args[1]->val_str(&tmp_value);
956
int32 count= (int32) args[2]->val_int();
906
int32_t count= (int32_t) args[2]->val_int();
959
909
if (args[0]->null_value || args[1]->null_value || args[2]->null_value)
976
926
const char *end= strend-delimiter_length+1;
977
927
const char *search= delimiter->ptr();
978
928
const char *search_end= search+delimiter_length;
979
int32 n=0,c=count,pass;
929
int32_t n=0,c=count,pass;
981
931
for (pass=(count>0);pass<2;++pass)
983
933
while (ptr < end)
1817
1767
str->set_charset(collation.collation);
1818
1768
for (uint i=0 ; i < arg_count ; i++)
1820
int32 num=(int32) args[i]->val_int();
1770
int32_t num=(int32_t) args[i]->val_int();
1821
1771
if (!args[i]->null_value)
1823
1773
char char_num= (char) num;
1982
1932
String *Item_func_rpad::val_str(String *str)
1984
1934
assert(fixed == 1);
1985
uint32 res_byte_length,res_char_length,pad_char_length,pad_byte_length;
1935
uint32_t res_byte_length,res_char_length,pad_char_length,pad_byte_length;
1987
1937
const char *ptr_pad;
1988
1938
/* must be int64_t to avoid truncation */
2025
1975
ptr_pad=rpad->ptr();
2026
1976
pad_byte_length= rpad->length();
2027
1977
count-= res_char_length;
2028
for ( ; (uint32) count > pad_char_length; count-= pad_char_length)
1978
for ( ; (uint32_t) count > pad_char_length; count-= pad_char_length)
2030
1980
memcpy(to,ptr_pad,pad_byte_length);
2031
1981
to+= pad_byte_length;
2085
2035
String *Item_func_lpad::val_str(String *str)
2087
2037
assert(fixed == 1);
2088
uint32 res_char_length,pad_char_length;
2038
uint32_t res_char_length,pad_char_length;
2089
2039
/* must be int64_t to avoid truncation */
2090
2040
int64_t count= args[1]->val_int();
2091
2041
int64_t byte_count;
2174
2124
from_base, &endptr, &err);
2176
2126
ptr= int64_t2str(dec, ans, to_base);
2177
if (str->copy(ans, (uint32) (ptr-ans), default_charset()))
2127
if (str->copy(ans, (uint32_t) (ptr-ans), default_charset()))
2178
2128
return &my_empty_string;
2378
2328
if ((null_value= args[0]->null_value))
2380
2330
ptr= int64_t2str(dec,ans,16);
2381
if (str->copy(ans,(uint32) (ptr-ans),default_charset()))
2331
if (str->copy(ans,(uint32_t) (ptr-ans),default_charset()))
2382
2332
return &my_empty_string; // End of memory
2704
2652
return uint4korr(res->ptr()) & 0x3FFFFFFF;
2707
int64_t Item_func_crc32::val_int()
2710
String *res=args[0]->val_str(&value);
2714
return 0; /* purecov: inspected */
2717
return (int64_t) crc32(0L, (uchar*)res->ptr(), res->length());
2720
2655
#ifdef HAVE_COMPRESS
2721
2656
#include "zlib.h"
2749
2684
new_size= res->length() + res->length() / 5 + 12;
2751
2686
// Check new_size overflow: new_size <= res->length()
2752
if (((uint32) (new_size+5) <= res->length()) ||
2753
buffer.realloc((uint32) new_size + 4 + 1))
2687
if (((uint32_t) (new_size+5) <= res->length()) ||
2688
buffer.realloc((uint32_t) new_size + 4 + 1))
2817
2752
current_thd->variables.max_allowed_packet);
2820
if (buffer.realloc((uint32)new_size))
2755
if (buffer.realloc((uint32_t)new_size))
2823
2758
if ((err= uncompress((Byte*)buffer.ptr(), &new_size,
2824
2759
((const Bytef*)res->ptr())+4,res->length())) == Z_OK)
2826
buffer.length((uint32) new_size);
2761
buffer.length((uint32_t) new_size);
2827
2762
return &buffer;
2872
2807
static void set_clock_seq_str()
2874
uint16 clock_seq= ((uint)(my_rnd(&uuid_rand)*16383)) | UUID_VARIANT;
2809
uint16_t clock_seq= ((uint)(my_rnd(&uuid_rand)*16383)) | UUID_VARIANT;
2875
2810
tohex(clock_seq_and_node_str+1, clock_seq, 4);
2935
2870
pthread_mutex_unlock(&LOCK_uuid_generator);
2937
uint32 time_low= (uint32) (tv & 0xFFFFFFFF);
2938
uint16 time_mid= (uint16) ((tv >> 32) & 0xFFFF);
2939
uint16 time_hi_and_version= (uint16) ((tv >> 48) | UUID_VERSION);
2872
uint32_t time_low= (uint32_t) (tv & 0xFFFFFFFF);
2873
uint16_t time_mid= (uint16_t) ((tv >> 32) & 0xFFFF);
2874
uint16_t time_hi_and_version= (uint16_t) ((tv >> 48) | UUID_VERSION);
2941
2876
str->realloc(UUID_LENGTH+1);
2942
2877
str->length(UUID_LENGTH);