~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_string.cc

  • Committer: Brian Aker
  • Date: 2009-05-21 21:59:59 UTC
  • Revision ID: brian@gaz-20090521215959-f49m3tntk8m1aeas
Dead Code

Show diffs side-by-side

added added

removed removed

Lines of Context:
761
761
{
762
762
  uint32_t res;
763
763
 
764
 
  if ((to_cs == &my_charset_bin) ||
765
 
      (from_cs == &my_charset_bin) ||
766
 
      (to_cs == from_cs) ||
767
 
      my_charset_same(from_cs, to_cs))
768
 
  {
769
 
    if (to_length < to_cs->mbminlen || !nchars)
770
 
    {
771
 
      *from_end_pos= from;
772
 
      *cannot_convert_error_pos= NULL;
773
 
      *well_formed_error_pos= NULL;
774
 
      return 0;
775
 
    }
776
 
 
777
 
    if (to_cs == &my_charset_bin)
778
 
    {
779
 
      res= cmin(cmin(nchars, to_length), from_length);
780
 
      memmove(to, from, res);
781
 
      *from_end_pos= from + res;
782
 
      *well_formed_error_pos= NULL;
783
 
      *cannot_convert_error_pos= NULL;
784
 
    }
785
 
    else
786
 
    {
787
 
      int well_formed_error;
788
 
      uint32_t from_offset;
789
 
 
790
 
      if ((from_offset= (from_length % to_cs->mbminlen)) &&
791
 
          (from_cs == &my_charset_bin))
792
 
      {
793
 
        /*
794
 
          Copying from BINARY to UCS2 needs to prepend zeros sometimes:
795
 
          INSERT INTO t1 (ucs2_column) VALUES (0x01);
796
 
          0x01 -> 0x0001
797
 
        */
798
 
        uint32_t pad_length= to_cs->mbminlen - from_offset;
799
 
        memset(to, 0, pad_length);
800
 
        memmove(to + pad_length, from, from_offset);
801
 
        nchars--;
802
 
        from+= from_offset;
803
 
        from_length-= from_offset;
804
 
        to+= to_cs->mbminlen;
805
 
        to_length-= to_cs->mbminlen;
806
 
      }
807
 
 
808
 
      set_if_smaller(from_length, to_length);
809
 
      res= to_cs->cset->well_formed_len(to_cs, from, from + from_length,
810
 
                                        nchars, &well_formed_error);
811
 
      memmove(to, from, res);
812
 
      *from_end_pos= from + res;
813
 
      *well_formed_error_pos= well_formed_error ? from + res : NULL;
814
 
      *cannot_convert_error_pos= NULL;
815
 
      if (from_offset)
816
 
        res+= to_cs->mbminlen;
817
 
    }
 
764
  assert((to_cs == &my_charset_bin) ||
 
765
         (from_cs == &my_charset_bin) ||
 
766
         (to_cs == from_cs) ||
 
767
         my_charset_same(from_cs, to_cs));
 
768
 
 
769
  if (to_length < to_cs->mbminlen || !nchars)
 
770
  {
 
771
    *from_end_pos= from;
 
772
    *cannot_convert_error_pos= NULL;
 
773
    *well_formed_error_pos= NULL;
 
774
    return 0;
 
775
  }
 
776
 
 
777
  if (to_cs == &my_charset_bin)
 
778
  {
 
779
    res= cmin(cmin(nchars, to_length), from_length);
 
780
    memmove(to, from, res);
 
781
    *from_end_pos= from + res;
 
782
    *well_formed_error_pos= NULL;
 
783
    *cannot_convert_error_pos= NULL;
818
784
  }
819
785
  else
820
786
  {
821
 
    int cnvres;
822
 
    my_wc_t wc;
823
 
    my_charset_conv_mb_wc mb_wc= from_cs->cset->mb_wc;
824
 
    my_charset_conv_wc_mb wc_mb= to_cs->cset->wc_mb;
825
 
    const unsigned char *from_end= (const unsigned char*) from + from_length;
826
 
    unsigned char *to_end= (unsigned char*) to + to_length;
827
 
    char *to_start= to;
828
 
    *well_formed_error_pos= NULL;
829
 
    *cannot_convert_error_pos= NULL;
 
787
    int well_formed_error;
 
788
    uint32_t from_offset;
830
789
 
831
 
    for ( ; nchars; nchars--)
 
790
    if ((from_offset= (from_length % to_cs->mbminlen)) &&
 
791
        (from_cs == &my_charset_bin))
832
792
    {
833
 
      const char *from_prev= from;
834
 
      if ((cnvres= (*mb_wc)(from_cs, &wc, (unsigned char*) from, from_end)) > 0)
835
 
        from+= cnvres;
836
 
      else if (cnvres == MY_CS_ILSEQ)
837
 
      {
838
 
        if (!*well_formed_error_pos)
839
 
          *well_formed_error_pos= from;
840
 
        from++;
841
 
        wc= '?';
842
 
      }
843
 
      else if (cnvres > MY_CS_TOOSMALL)
844
 
      {
845
 
        /*
846
 
          A correct multibyte sequence detected
847
 
          But it doesn't have Unicode mapping.
848
 
        */
849
 
        if (!*cannot_convert_error_pos)
850
 
          *cannot_convert_error_pos= from;
851
 
        from+= (-cnvres);
852
 
        wc= '?';
853
 
      }
854
 
      else
855
 
        break;  // Not enough characters
856
 
 
857
 
outp:
858
 
      if ((cnvres= (*wc_mb)(to_cs, wc, (unsigned char*) to, to_end)) > 0)
859
 
        to+= cnvres;
860
 
      else if (cnvres == MY_CS_ILUNI && wc != '?')
861
 
      {
862
 
        if (!*cannot_convert_error_pos)
863
 
          *cannot_convert_error_pos= from_prev;
864
 
        wc= '?';
865
 
        goto outp;
866
 
      }
867
 
      else
868
 
      {
869
 
        from= from_prev;
870
 
        break;
871
 
      }
 
793
      /*
 
794
        Copying from BINARY to UCS2 needs to prepend zeros sometimes:
 
795
        INSERT INTO t1 (ucs2_column) VALUES (0x01);
 
796
        0x01 -> 0x0001
 
797
      */
 
798
      uint32_t pad_length= to_cs->mbminlen - from_offset;
 
799
      memset(to, 0, pad_length);
 
800
      memmove(to + pad_length, from, from_offset);
 
801
      nchars--;
 
802
      from+= from_offset;
 
803
      from_length-= from_offset;
 
804
      to+= to_cs->mbminlen;
 
805
      to_length-= to_cs->mbminlen;
872
806
    }
873
 
    *from_end_pos= from;
874
 
    res= to - to_start;
 
807
 
 
808
    set_if_smaller(from_length, to_length);
 
809
    res= to_cs->cset->well_formed_len(to_cs, from, from + from_length,
 
810
                                      nchars, &well_formed_error);
 
811
    memmove(to, from, res);
 
812
    *from_end_pos= from + res;
 
813
    *well_formed_error_pos= well_formed_error ? from + res : NULL;
 
814
    *cannot_convert_error_pos= NULL;
 
815
    if (from_offset)
 
816
      res+= to_cs->mbminlen;
875
817
  }
876
 
  return (uint32_t) res;
 
818
 
 
819
  return res;
877
820
}
878
821
 
879
822