@ -605,27 +605,15 @@ null:
void Item_func_concat : : fix_length_and_dec ( )
{
ulonglong max_result _length= 0 ;
ulonglong char _length= 0 ;
if ( agg_arg_charsets_for_string_result ( collation , args , arg_count ) )
return ;
for ( uint i = 0 ; i < arg_count ; i + + )
{
if ( args [ i ] - > collation . collation - > mbmaxlen ! = collation . collation - > mbmaxlen )
max_result_length + = ( args [ i ] - > max_length /
args [ i ] - > collation . collation - > mbmaxlen ) *
collation . collation - > mbmaxlen ;
else
max_result_length + = args [ i ] - > max_length ;
}
char_length + = args [ i ] - > max_char_length ( ) ;
if ( max_result_length > = MAX_BLOB_WIDTH )
{
max_result_length = MAX_BLOB_WIDTH ;
maybe_null = 1 ;
}
max_length = ( ulong ) max_result_length ;
fix_char_length_ulonglong ( char_length ) ;
}
/**
@ -962,7 +950,7 @@ null:
void Item_func_concat_ws : : fix_length_and_dec ( )
{
ulonglong max_result _length;
ulonglong char _length;
if ( agg_arg_charsets_for_string_result ( collation , args , arg_count ) )
return ;
@ -972,16 +960,11 @@ void Item_func_concat_ws::fix_length_and_dec()
it is done on parser level in sql_yacc . yy
so , ( arg_count - 2 ) is safe here .
*/
max_result _length= ( ulonglong ) args [ 0 ] - > max_length * ( arg_count - 2 ) ;
char _length= ( ulonglong ) args [ 0 ] - > max_char_ length ( ) * ( arg_count - 2 ) ;
for ( uint i = 1 ; i < arg_count ; i + + )
max_result _length+ = args [ i ] - > max_length ;
char _length+ = args [ i ] - > max_char_ length ( ) ;
if ( max_result_length > = MAX_BLOB_WIDTH )
{
max_result_length = MAX_BLOB_WIDTH ;
maybe_null = 1 ;
}
max_length = ( ulong ) max_result_length ;
fix_char_length_ulonglong ( char_length ) ;
}
@ -1036,6 +1019,7 @@ String *Item_func_reverse::val_str(String *str)
void Item_func_reverse : : fix_length_and_dec ( )
{
agg_arg_charsets_for_string_result ( collation , args , 1 ) ;
DBUG_ASSERT ( collation . collation ! = NULL ) ;
fix_char_length ( args [ 0 ] - > max_char_length ( ) ) ;
}
@ -1165,22 +1149,17 @@ null:
void Item_func_replace : : fix_length_and_dec ( )
{
ulonglong max_result_length = args [ 0 ] - > max_length ;
int diff = ( int ) ( args [ 2 ] - > max_length - args [ 1 ] - > max_length ) ;
if ( diff > 0 & & args [ 1 ] - > max_length )
ulonglong char_length = ( ulonglong ) args [ 0 ] - > max_char_ length ( ) ;
int diff = ( int ) ( args [ 2 ] - > max_char_ length ( ) - args [ 1 ] - > max_char_ length ( ) ) ;
if ( diff > 0 & & args [ 1 ] - > max_char_ length ( ) )
{ // Calculate of maxreplaces
ulonglong max_substrs = max_result_length / args [ 1 ] - > max_length ;
max_result_length + = max_substrs * ( uint ) diff ;
}
if ( max_result_length > = MAX_BLOB_WIDTH )
{
max_result_length = MAX_BLOB_WIDTH ;
maybe_null = 1 ;
ulonglong max_substrs = char_length / args [ 1 ] - > max_char_length ( ) ;
char_length + = max_substrs * ( uint ) diff ;
}
max_length = ( ulong ) max_result_length ;
if ( agg_arg_charsets_for_comparison ( collation , args , 3 ) )
return ;
fix_char_length_ulonglong ( char_length ) ;
}
@ -1235,19 +1214,14 @@ null:
void Item_func_insert : : fix_length_and_dec ( )
{
ulonglong max_result _length;
ulonglong char _length;
// Handle character set for args[0] and args[3].
if ( agg_arg_charsets_for_string_result ( collation , args , 2 , 3 ) )
return ;
max_result_length = ( ( ulonglong ) args [ 0 ] - > max_length +
( ulonglong ) args [ 3 ] - > max_length ) ;
if ( max_result_length > = MAX_BLOB_WIDTH )
{
max_result_length = MAX_BLOB_WIDTH ;
maybe_null = 1 ;
}
max_length = ( ulong ) max_result_length ;
char_length = ( ( ulonglong ) args [ 0 ] - > max_char_length ( ) +
( ulonglong ) args [ 3 ] - > max_char_length ( ) ) ;
fix_char_length_ulonglong ( char_length ) ;
}
@ -1287,17 +1261,19 @@ String *Item_str_conv::val_str(String *str)
void Item_func_lcase : : fix_length_and_dec ( )
{
agg_arg_charsets_for_string_result ( collation , args , 1 ) ;
DBUG_ASSERT ( collation . collation ! = NULL ) ;
multiply = collation . collation - > casedn_multiply ;
converter = collation . collation - > cset - > casedn ;
max_length = args [ 0 ] - > max_length * multiply ;
fix_char_length_ulonglong ( ( ulonglong ) args [ 0 ] - > max_char_ length ( ) * multiply ) ;
}
void Item_func_ucase : : fix_length_and_dec ( )
{
agg_arg_charsets_for_string_result ( collation , args , 1 ) ;
DBUG_ASSERT ( collation . collation ! = NULL ) ;
multiply = collation . collation - > caseup_multiply ;
converter = collation . collation - > cset - > caseup ;
max_length = args [ 0 ] - > max_length * multiply ;
fix_char_length_ulonglong ( ( ulonglong ) args [ 0 ] - > max_char_ length ( ) * multiply ) ;
}
@ -1328,21 +1304,23 @@ String *Item_func_left::val_str(String *str)
void Item_str_func : : left_right_max_length ( )
{
max_length = args [ 0 ] - > max_length ;
uint32 char_length = args [ 0 ] - > max_char_ length ( ) ;
if ( args [ 1 ] - > const_item ( ) )
{
int length = ( int ) args [ 1 ] - > val_int ( ) * collation . collation - > mbmaxlen ;
int length = ( int ) args [ 1 ] - > val_int ( ) ;
if ( length < = 0 )
max _length= 0 ;
char _length= 0 ;
else
set_if_smaller ( max_length , ( uint ) length ) ;
set_if_smaller ( char_length , ( uint ) length ) ;
}
fix_char_length ( char_length ) ;
}
void Item_func_left : : fix_length_and_dec ( )
{
agg_arg_charsets_for_string_result ( collation , args , 1 ) ;
DBUG_ASSERT ( collation . collation ! = NULL ) ;
left_right_max_length ( ) ;
}
@ -1376,6 +1354,7 @@ String *Item_func_right::val_str(String *str)
void Item_func_right : : fix_length_and_dec ( )
{
agg_arg_charsets_for_string_result ( collation , args , 1 ) ;
DBUG_ASSERT ( collation . collation ! = NULL ) ;
left_right_max_length ( ) ;
}
@ -1432,6 +1411,7 @@ void Item_func_substr::fix_length_and_dec()
max_length = args [ 0 ] - > max_length ;
agg_arg_charsets_for_string_result ( collation , args , 1 ) ;
DBUG_ASSERT ( collation . collation ! = NULL ) ;
if ( args [ 1 ] - > const_item ( ) )
{
int32 start = ( int32 ) args [ 1 ] - > val_int ( ) ;
@ -1454,10 +1434,9 @@ void Item_func_substr::fix_length_and_dec()
void Item_func_substr_index : : fix_length_and_dec ( )
{
max_length = args [ 0 ] - > max_length ;
if ( agg_arg_charsets_for_comparison ( collation , args , 2 ) )
return ;
fix_char_length ( args [ 0 ] - > max_char_length ( ) ) ;
}
@ -1783,10 +1762,10 @@ String *Item_func_trim::val_str(String *str)
void Item_func_trim : : fix_length_and_dec ( )
{
max_length = args [ 0 ] - > max_length ;
if ( arg_count = = 1 )
{
agg_arg_charsets_for_string_result ( collation , args , 1 ) ;
DBUG_ASSERT ( collation . collation ! = NULL ) ;
remove . set_charset ( collation . collation ) ;
remove . set_ascii ( " " , 1 ) ;
}
@ -1797,6 +1776,7 @@ void Item_func_trim::fix_length_and_dec()
if ( agg_arg_charsets_for_comparison ( collation , & args [ 1 ] , 2 , - 1 ) )
return ;
}
fix_char_length ( args [ 0 ] - > max_char_length ( ) ) ;
}
void Item_func_trim : : print ( String * str , enum_query_type query_type )
@ -2072,9 +2052,11 @@ bool Item_func_current_user::fix_fields(THD *thd, Item **ref)
void Item_func_soundex : : fix_length_and_dec ( )
{
uint32 char_length = args [ 0 ] - > max_char_length ( ) ;
agg_arg_charsets_for_string_result ( collation , args , 1 ) ;
max_length = args [ 0 ] - > max_length ;
set_if_bigger ( max_length , 4 * collation . collation - > mbminlen ) ;
DBUG_ASSERT ( collation . collation ! = NULL ) ;
set_if_bigger ( char_length , 4 ) ;
fix_char_length ( char_length ) ;
tmp_value . set_charset ( collation . collation ) ;
}
@ -2251,11 +2233,10 @@ MY_LOCALE *Item_func_format::get_locale(Item *item)
void Item_func_format : : fix_length_and_dec ( )
{
uint char_length = args [ 0 ] - > max_length / args [ 0 ] - > collation . collation - > mbmaxlen ;
uint max_sep_count = char_length / 3 + ( decimals ? 1 : 0 ) + /*sign*/ 1 ;
uint32 char_length = args [ 0 ] - > max_char_length ( ) ;
uint32 max_sep_count = ( char_length / 3 ) + ( decimals ? 1 : 0 ) + /*sign*/ 1 ;
collation . set ( default_charset ( ) ) ;
max_length = ( char_length + max_sep_count + decimals ) *
collation . collation - > mbmaxlen ;
fix_char_length ( char_length + max_sep_count + decimals ) ;
if ( arg_count = = 3 )
locale = args [ 2 ] - > basic_const_item ( ) ? get_locale ( args [ 2 ] ) : NULL ;
else
@ -2375,7 +2356,7 @@ void Item_func_format::print(String *str, enum_query_type query_type)
void Item_func_elt : : fix_length_and_dec ( )
{
max_length = 0 ;
uint32 char_length = 0 ;
decimals = 0 ;
if ( agg_arg_charsets_for_string_result ( collation , args + 1 , arg_count - 1 ) )
@ -2383,9 +2364,10 @@ void Item_func_elt::fix_length_and_dec()
for ( uint i = 1 ; i < arg_count ; i + + )
{
set_if_bigger ( max_length , args [ i ] - > max_length ) ;
set_if_bigger ( char_length , args [ i ] - > max_char_ length ( ) ) ;
set_if_bigger ( decimals , args [ i ] - > decimals ) ;
}
fix_char_length ( char_length ) ;
maybe_null = 1 ; // NULL if wrong first arg
}
@ -2443,14 +2425,14 @@ void Item_func_make_set::split_sum_func(THD *thd, Item **ref_pointer_array,
void Item_func_make_set : : fix_length_and_dec ( )
{
max_length = arg_count - 1 ;
uint32 char_length = arg_count - 1 ; /* Separators */
if ( agg_arg_charsets_for_string_result ( collation , args , arg_count ) )
return ;
for ( uint i = 0 ; i < arg_count ; i + + )
max _length+ = args [ i ] - > max_length ;
char _length+ = args [ i ] - > max_char_ length ( ) ;
fix_char_length ( char_length ) ;
used_tables_cache | = item - > used_tables ( ) ;
not_null_tables_cache & = item - > not_null_tables ( ) ;
const_item_cache & = item - > const_item ( ) ;
@ -2616,6 +2598,7 @@ inline String* alloc_buffer(String *res,String *str,String *tmp_value,
void Item_func_repeat : : fix_length_and_dec ( )
{
agg_arg_charsets_for_string_result ( collation , args , 1 ) ;
DBUG_ASSERT ( collation . collation ! = NULL ) ;
if ( args [ 1 ] - > const_item ( ) )
{
/* must be longlong to avoid truncation */
@ -2626,13 +2609,8 @@ void Item_func_repeat::fix_length_and_dec()
if ( count > INT_MAX32 )
count = INT_MAX32 ;
ulonglong max_result_length = ( ulonglong ) args [ 0 ] - > max_length * count ;
if ( max_result_length > = MAX_BLOB_WIDTH )
{
max_result_length = MAX_BLOB_WIDTH ;
maybe_null = 1 ;
}
max_length = ( ulong ) max_result_length ;
ulonglong char_length = ( ulonglong ) args [ 0 ] - > max_char_length ( ) * count ;
fix_char_length_ulonglong ( char_length ) ;
}
else
{
@ -2703,26 +2681,13 @@ void Item_func_rpad::fix_length_and_dec()
return ;
if ( args [ 1 ] - > const_item ( ) )
{
ulonglong length = 0 ;
if ( collation . collation - > mbmaxlen > 0 )
{
ulonglong temp = ( ulonglong ) args [ 1 ] - > val_int ( ) ;
/* Assumes that the maximum length of a String is < INT_MAX32. */
/* Set here so that rest of code sees out-of-bound value as such. */
if ( temp > INT_MAX32 )
temp = INT_MAX32 ;
length = temp * collation . collation - > mbmaxlen ;
}
if ( length > = MAX_BLOB_WIDTH )
{
length = MAX_BLOB_WIDTH ;
maybe_null = 1 ;
}
max_length = ( ulong ) length ;
ulonglong char_length = ( ulonglong ) args [ 1 ] - > val_int ( ) ;
DBUG_ASSERT ( collation . collation - > mbmaxlen > 0 ) ;
/* Assumes that the maximum length of a String is < INT_MAX32. */
/* Set here so that rest of code sees out-of-bound value as such. */
if ( char_length > INT_MAX32 )
char_length = INT_MAX32 ;
fix_char_length_ulonglong ( char_length ) ;
}
else
{
@ -2806,26 +2771,13 @@ void Item_func_lpad::fix_length_and_dec()
if ( args [ 1 ] - > const_item ( ) )
{
ulonglong length = 0 ;
if ( collation . collation - > mbmaxlen > 0 )
{
ulonglong temp = ( ulonglong ) args [ 1 ] - > val_int ( ) ;
/* Assumes that the maximum length of a String is < INT_MAX32. */
/* Set here so that rest of code sees out-of-bound value as such. */
if ( temp > INT_MAX32 )
temp = INT_MAX32 ;
length = temp * collation . collation - > mbmaxlen ;
}
if ( length > = MAX_BLOB_WIDTH )
{
length = MAX_BLOB_WIDTH ;
maybe_null = 1 ;
}
max_length = ( ulong ) length ;
ulonglong char_length = ( ulonglong ) args [ 1 ] - > val_int ( ) ;
DBUG_ASSERT ( collation . collation - > mbmaxlen > 0 ) ;
/* Assumes that the maximum length of a String is < INT_MAX32. */
/* Set here so that rest of code sees out-of-bound value as such. */
if ( char_length > INT_MAX32 )
char_length = INT_MAX32 ;
fix_char_length_ulonglong ( char_length ) ;
}
else
{
@ -3309,8 +3261,8 @@ String* Item_func_export_set::val_str(String* str)
void Item_func_export_set : : fix_length_and_dec ( )
{
uint length = max ( args [ 1 ] - > max_length , args [ 2 ] - > max_length ) ;
uint sep_length = ( arg_count > 3 ? args [ 3 ] - > max_length : 1 ) ;
uint32 length = max ( args [ 1 ] - > max_char_ length ( ) , args [ 2 ] - > max_char_ length ( ) ) ;
uint32 sep_length = ( arg_count > 3 ? args [ 3 ] - > max_char _length ( ) : 1 ) ;
if ( agg_arg_charsets_for_string_result ( collation ,
args + 1 , min ( 4 , arg_count ) - 1 ) )