@@ -40,19 +40,16 @@ extern void sql_element_free(void *ptr);
4040bool String::real_alloc (uint32 arg_length)
4141{
4242 arg_length=ALIGN_SIZE (arg_length+1 );
43+ str_length=0 ;
4344 if (Alloced_length < arg_length)
4445 {
4546 free ();
4647 if (!(Ptr=(char *) my_malloc (arg_length,MYF (MY_WME))))
47- {
48- str_length=0 ;
4948 return TRUE ;
50- }
5149 Alloced_length=arg_length;
5250 alloced=1 ;
5351 }
5452 Ptr[0 ]=0 ;
55- str_length=0 ;
5653 return FALSE ;
5754}
5855
@@ -94,36 +91,40 @@ bool String::realloc(uint32 alloc_length)
9491 return FALSE ;
9592}
9693
97- bool String::set (longlong num)
94+ bool String::set (longlong num, CHARSET_INFO *cs )
9895{
9996 if (alloc (21 ))
10097 return TRUE ;
10198 str_length=(uint32) (longlong10_to_str (num,Ptr,-10 )-Ptr);
99+ str_charset=cs;
102100 return FALSE ;
103101}
104102
105- bool String::set (ulonglong num)
103+ bool String::set (ulonglong num, CHARSET_INFO *cs )
106104{
107105 if (alloc (21 ))
108106 return TRUE ;
109107 str_length=(uint32) (longlong10_to_str (num,Ptr,10 )-Ptr);
108+ str_charset=cs;
110109 return FALSE ;
111110}
112111
113- bool String::set (double num,uint decimals)
112+ bool String::set (double num,uint decimals, CHARSET_INFO *cs )
114113{
115114 char buff[331 ];
115+
116+ str_charset=cs;
116117 if (decimals >= NOT_FIXED_DEC)
117118 {
118119 sprintf (buff," %.14g" ,num); // Enough for a DATETIME
119- return copy (buff, (uint32) strlen (buff));
120+ return copy (buff, (uint32) strlen (buff), my_charset_latin1 );
120121 }
121122#ifdef HAVE_FCONVERT
122123 int decpt,sign;
123124 char *pos,*to;
124125
125126 VOID (fconvert (num,(int ) decimals,&decpt,&sign,buff+1 ));
126- if (!isdigit ( buff[1 ]))
127+ if (!my_isdigit (system_charset_info, buff[1 ]))
127128 { // Nan or Inf
128129 pos=buff+1 ;
129130 if (sign)
@@ -181,7 +182,7 @@ bool String::set(double num,uint decimals)
181182#else
182183 sprintf (buff," %.*f" ,(int ) decimals,num);
183184#endif
184- return copy (buff,(uint32) strlen (buff));
185+ return copy (buff,(uint32) strlen (buff), my_charset_latin1 );
185186#endif
186187}
187188
@@ -203,16 +204,18 @@ bool String::copy(const String &str)
203204 str_length=str.str_length ;
204205 bmove (Ptr,str.Ptr ,str_length); // May be overlapping
205206 Ptr[str_length]=0 ;
207+ str_charset=str.str_charset ;
206208 return FALSE ;
207209}
208210
209- bool String::copy (const char *str,uint32 arg_length)
211+ bool String::copy (const char *str,uint32 arg_length, CHARSET_INFO *cs )
210212{
211213 if (alloc (arg_length))
212214 return TRUE ;
213215 if ((str_length=arg_length))
214216 memcpy (Ptr,str,arg_length);
215217 Ptr[arg_length]=0 ;
218+ str_charset=cs;
216219 return FALSE ;
217220}
218221
@@ -489,7 +492,7 @@ void String::qs_append(double d)
489492void String::qs_append (double *d)
490493{
491494 double ld;
492- float8get (ld, d);
495+ float8get (ld, ( char *) d);
493496 qs_append (ld);
494497}
495498
@@ -523,12 +526,23 @@ int sortcmp(const String *x,const String *y)
523526#endif /* USE_STRCOLL */
524527 x_len-=len; // For easy end space test
525528 y_len-=len;
526- while (len-- )
529+ if (x-> str_charset -> sort_order )
527530 {
528- if (x->str_charset ->sort_order [(uchar) *s++] !=
531+ while (len--)
532+ {
533+ if (x->str_charset ->sort_order [(uchar) *s++] !=
529534 x->str_charset ->sort_order [(uchar) *t++])
530- return ((int ) x->str_charset ->sort_order [(uchar) s[-1 ]] -
531- (int ) x->str_charset ->sort_order [(uchar) t[-1 ]]);
535+ return ((int ) x->str_charset ->sort_order [(uchar) s[-1 ]] -
536+ (int ) x->str_charset ->sort_order [(uchar) t[-1 ]]);
537+ }
538+ }
539+ else
540+ {
541+ while (len--)
542+ {
543+ if (*s++ != *t++)
544+ return ((int ) s[-1 ] - (int ) t[-1 ]);
545+ }
532546 }
533547#ifndef CMP_ENDSPACE
534548 /* Don't compare end space in strings */
@@ -586,6 +600,7 @@ String *copy_if_not_alloced(String *to,String *from,uint32 from_length)
586600 return from; // Actually an error
587601 if ((to->str_length =min (from->str_length ,from_length)))
588602 memcpy (to->Ptr ,from->Ptr ,to->str_length );
603+ to->str_charset =from->str_charset ;
589604 return to;
590605}
591606
@@ -658,7 +673,7 @@ int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *str_end,
658673 { // Found wild_many
659674 wildstr++;
660675 /* Remove any '%' and '_' from the wild search string */
661- for ( ; wildstr != wildend ; wildstr++)
676+ for (; wildstr != wildend ; wildstr++)
662677 {
663678 if (*wildstr == wild_many)
664679 continue ;
@@ -787,7 +802,7 @@ int wild_compare(const char *str,const char *str_end,
787802 { // Found wild_many
788803 wildstr++;
789804 /* Remove any '%' and '_' from the wild search string */
790- for ( ; wildstr != wildend ; wildstr++)
805+ for (; wildstr != wildend ; wildstr++)
791806 {
792807 if (*wildstr == wild_many)
793808 continue ;
0 commit comments