@@ -173,89 +173,11 @@ void Item_bool_func2::fix_length_and_dec()
173
173
if (!args[0 ] || !args[1 ])
174
174
return ;
175
175
176
- /*
177
- We allow to apply automatic character set conversion in some cases.
178
- The conditions when conversion is possible are:
179
- - arguments A and B have different charsets
180
- - A wins according to coercibility rules
181
- (i.e. a column is stronger than a string constant,
182
- an explicit COLLATE clause is stronger than a column)
183
- - character set of A is either superset for character set of B,
184
- or B is a string constant which can be converted into the
185
- character set of A without data loss.
186
-
187
- If all of the above is true, then it's possible to convert
188
- B into the character set of A, and then compare according
189
- to the collation of A.
190
- */
191
-
192
- uint32 dummy_offset;
193
176
DTCollation coll;
194
-
195
177
if (args[0 ]->result_type () == STRING_RESULT &&
196
178
args[1 ]->result_type () == STRING_RESULT &&
197
- String::needs_conversion (0 , args[0 ]->collation .collation ,
198
- args[1 ]->collation .collation ,
199
- &dummy_offset) &&
200
- !coll.set (args[0 ]->collation , args[1 ]->collation ,
201
- MY_COLL_ALLOW_SUPERSET_CONV |
202
- MY_COLL_ALLOW_COERCIBLE_CONV))
203
- {
204
- Item* conv= 0 ;
205
- Item_arena *arena= thd->current_arena , backup;
206
- uint strong= coll.strong ;
207
- uint weak= strong ? 0 : 1 ;
208
- /*
209
- In case we're in statement prepare, create conversion item
210
- in its memory: it will be reused on each execute.
211
- */
212
- if (arena->is_stmt_prepare ())
213
- thd->set_n_backup_item_arena (arena, &backup);
214
- if (args[weak]->type () == STRING_ITEM)
215
- {
216
- uint conv_errors;
217
- String tmp, cstr, *ostr= args[weak]->val_str (&tmp);
218
- cstr.copy (ostr->ptr (), ostr->length (), ostr->charset (),
219
- args[strong]->collation .collation , &conv_errors);
220
- if (conv_errors)
221
- {
222
- /*
223
- We could not convert a string into the character set
224
- of the stronger side of the operation without data loss.
225
- It can happen if we tried to combine a column with a string
226
- constant, and the column charset does not cover all the
227
- characters from the string. Operation cannot be done
228
- correctly. Return an error.
229
- */
230
- my_coll_agg_error (args[0 ]->collation , args[1 ]->collation ,
231
- func_name ());
232
- return ;
233
- }
234
- conv= new Item_string (cstr.ptr (),cstr.length (),cstr.charset (),
235
- args[weak]->collation .derivation );
236
- ((Item_string*)conv)->str_value .copy ();
237
- }
238
- else
239
- {
240
- if (!(coll.collation ->state & MY_CS_UNICODE))
241
- {
242
- /*
243
- Don't allow automatic conversion to non-Unicode charsets,
244
- as it potentially loses data.
245
- */
246
- my_coll_agg_error (args[0 ]->collation , args[1 ]->collation ,
247
- func_name ());
248
- return ;
249
- }
250
- conv= new Item_func_conv_charset (args[weak],
251
- args[strong]->collation .collation );
252
- conv->collation .set (args[weak]->collation .derivation );
253
- conv->fix_fields (thd, 0 , &conv);
254
- }
255
- if (arena->is_stmt_prepare ())
256
- thd->restore_backup_item_arena (arena, &backup);
257
- args[weak]= conv ? conv : args[weak];
258
- }
179
+ agg_arg_charsets (coll, args, 2 , MY_COLL_CMP_CONV))
180
+ return ;
259
181
260
182
// Make a special case of compare with fields to get nicer DATE comparisons
261
183
@@ -871,7 +793,7 @@ void Item_func_between::fix_length_and_dec()
871
793
return ;
872
794
agg_cmp_type (&cmp_type, args, 3 );
873
795
if (cmp_type == STRING_RESULT &&
874
- agg_arg_collations_for_comparison (cmp_collation, args, 3 ))
796
+ agg_arg_charsets (cmp_collation, args, 3 , MY_COLL_CMP_CONV ))
875
797
return ;
876
798
877
799
/*
@@ -987,7 +909,7 @@ Item_func_ifnull::fix_length_and_dec()
987
909
decimals=max (args[0 ]->decimals ,args[1 ]->decimals );
988
910
agg_result_type (&cached_result_type, args, 2 );
989
911
if (cached_result_type == STRING_RESULT)
990
- agg_arg_collations (collation, args, arg_count);
912
+ agg_arg_charsets (collation, args, arg_count, MY_COLL_CMP_CONV );
991
913
else if (cached_result_type != REAL_RESULT)
992
914
decimals= 0 ;
993
915
@@ -1083,7 +1005,7 @@ Item_func_if::fix_length_and_dec()
1083
1005
agg_result_type (&cached_result_type, args+1 , 2 );
1084
1006
if (cached_result_type == STRING_RESULT)
1085
1007
{
1086
- if (agg_arg_collations (collation, args+1 , 2 ))
1008
+ if (agg_arg_charsets (collation, args+1 , 2 , MY_COLL_ALLOW_CONV ))
1087
1009
return ;
1088
1010
}
1089
1011
else
@@ -1354,7 +1276,7 @@ void Item_func_case::fix_length_and_dec()
1354
1276
1355
1277
agg_result_type (&cached_result_type, agg, nagg);
1356
1278
if ((cached_result_type == STRING_RESULT) &&
1357
- agg_arg_collations (collation, agg, nagg))
1279
+ agg_arg_charsets (collation, agg, nagg, MY_COLL_ALLOW_CONV ))
1358
1280
return ;
1359
1281
1360
1282
@@ -1370,7 +1292,7 @@ void Item_func_case::fix_length_and_dec()
1370
1292
nagg++;
1371
1293
agg_cmp_type (&cmp_type, agg, nagg);
1372
1294
if ((cmp_type == STRING_RESULT) &&
1373
- agg_arg_collations_for_comparison (cmp_collation, agg, nagg))
1295
+ agg_arg_charsets (cmp_collation, agg, nagg, MY_COLL_CMP_CONV ))
1374
1296
return ;
1375
1297
}
1376
1298
@@ -1477,7 +1399,7 @@ void Item_func_coalesce::fix_length_and_dec()
1477
1399
set_if_bigger (decimals,args[i]->decimals );
1478
1400
}
1479
1401
if (cached_result_type == STRING_RESULT)
1480
- agg_arg_collations (collation, args, arg_count);
1402
+ agg_arg_charsets (collation, args, arg_count, MY_COLL_ALLOW_CONV );
1481
1403
else if (cached_result_type != REAL_RESULT)
1482
1404
decimals= 0 ;
1483
1405
}
@@ -2423,7 +2345,7 @@ Item_func_regex::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
2423
2345
max_length= 1 ;
2424
2346
decimals= 0 ;
2425
2347
2426
- if (agg_arg_collations (cmp_collation, args, 2 ))
2348
+ if (agg_arg_charsets (cmp_collation, args, 2 , MY_COLL_CMP_CONV ))
2427
2349
return 1 ;
2428
2350
2429
2351
used_tables_cache=args[0 ]->used_tables () | args[1 ]->used_tables ();
0 commit comments