@@ -3412,6 +3412,32 @@ bool Item_param::set_longdata(const char *str, ulong length)
3412
3412
}
3413
3413
3414
3414
3415
+ void Item_param::CONVERSION_INFO::set (THD *thd, CHARSET_INFO *fromcs)
3416
+ {
3417
+ CHARSET_INFO *tocs= thd->variables .collation_connection ;
3418
+
3419
+ character_set_of_placeholder= fromcs;
3420
+ character_set_client= thd->variables .character_set_client ;
3421
+ /*
3422
+ Setup source and destination character sets so that they
3423
+ are different only if conversion is necessary: this will
3424
+ make later checks easier.
3425
+ */
3426
+ uint32 dummy_offset;
3427
+ final_character_set_of_str_value=
3428
+ String::needs_conversion (0 , fromcs, tocs, &dummy_offset) ?
3429
+ tocs : fromcs;
3430
+ }
3431
+
3432
+
3433
+ bool Item_param::CONVERSION_INFO::convert (THD *thd, String *str)
3434
+ {
3435
+ return thd->convert_string (str,
3436
+ character_set_of_placeholder,
3437
+ final_character_set_of_str_value);
3438
+ }
3439
+
3440
+
3415
3441
/* *
3416
3442
Set parameter value from user variable value.
3417
3443
@@ -3451,20 +3477,7 @@ bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry)
3451
3477
break ;
3452
3478
case STRING_RESULT:
3453
3479
{
3454
- CHARSET_INFO *fromcs= entry->charset ();
3455
- CHARSET_INFO *tocs= thd->variables .collation_connection ;
3456
- uint32 dummy_offset;
3457
-
3458
- value.cs_info .character_set_of_placeholder = fromcs;
3459
- value.cs_info .character_set_client = thd->variables .character_set_client ;
3460
- /*
3461
- Setup source and destination character sets so that they
3462
- are different only if conversion is necessary: this will
3463
- make later checks easier.
3464
- */
3465
- value.cs_info .final_character_set_of_str_value =
3466
- String::needs_conversion (0 , fromcs, tocs, &dummy_offset) ?
3467
- tocs : fromcs;
3480
+ value.cs_info .set (thd, entry->charset ());
3468
3481
/*
3469
3482
Exact value of max_length is not known unless data is converted to
3470
3483
charset of connection, so we have to set it later.
@@ -3775,21 +3788,7 @@ bool Item_param::convert_str_value(THD *thd)
3775
3788
bool rc= FALSE ;
3776
3789
if (state == STRING_VALUE || state == LONG_DATA_VALUE)
3777
3790
{
3778
- /*
3779
- Check is so simple because all charsets were set up properly
3780
- in setup_one_conversion_function, where typecode of
3781
- placeholder was also taken into account: the variables are different
3782
- here only if conversion is really necessary.
3783
- */
3784
- if (value.cs_info .final_character_set_of_str_value !=
3785
- value.cs_info .character_set_of_placeholder )
3786
- {
3787
- rc= thd->convert_string (&str_value,
3788
- value.cs_info .character_set_of_placeholder ,
3789
- value.cs_info .final_character_set_of_str_value );
3790
- }
3791
- else
3792
- str_value.set_charset (value.cs_info .final_character_set_of_str_value );
3791
+ rc= value.cs_info .convert_if_needed (thd, &str_value);
3793
3792
/* Here str_value is guaranteed to be in final_character_set_of_str_value */
3794
3793
3795
3794
/*
0 commit comments