~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_load.cc

Much closer toward UTF8 being around all the time...

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
class READ_INFO {
25
25
  File  file;
26
 
  unsigned char *buffer,                        /* Buffer for read text */
 
26
  uchar *buffer,                        /* Buffer for read text */
27
27
        *end_of_buff;                   /* Data in bufferts ends here */
28
28
  uint  buff_length,                    /* Length of buffert */
29
29
        max_length;                     /* Max length of row */
38
38
 
39
39
public:
40
40
  bool error,line_cuted,found_null,enclosed;
41
 
  unsigned char *row_start,                     /* Found row starts here */
 
41
  uchar *row_start,                     /* Found row starts here */
42
42
        *row_end;                       /* Found row ends here */
43
43
  const CHARSET_INFO *read_charset;
44
44
 
45
 
  READ_INFO(File file,uint32_t tot_length, const CHARSET_INFO * const cs,
 
45
  READ_INFO(File file,uint tot_length, const CHARSET_INFO * const cs,
46
46
            String &field_term,String &line_start,String &line_term,
47
47
            String &enclosed,int escape,bool get_it_from_net, bool is_fifo);
48
48
  ~READ_INFO();
50
50
  int read_fixed_length(void);
51
51
  int next_line(void);
52
52
  char unescape(char chr);
53
 
  int terminator(char *ptr,uint32_t length);
 
53
  int terminator(char *ptr,uint length);
54
54
  bool find_start_of_fields();
55
55
 
56
56
  /*
208
208
 
209
209
  table->mark_columns_needed_for_insert();
210
210
 
211
 
  uint32_t tot_length=0;
 
211
  uint tot_length=0;
212
212
  bool use_blobs= 0, use_vars= 0;
213
213
  List_iterator_fast<Item> it(fields_vars);
214
214
  Item *item;
259
259
#endif
260
260
    if (!dirname_length(ex->file_name))
261
261
    {
262
 
      strxnmov(name, FN_REFLEN-1, mysql_real_data_home, tdb, NULL);
 
262
      strxnmov(name, FN_REFLEN-1, mysql_real_data_home, tdb, NullS);
263
263
      (void) fn_format(name, ex->file_name, name, "",
264
264
                       MY_RELATIVE_PATH | MY_UNPACK_FILENAME);
265
265
    }
530
530
      continue;
531
531
    }
532
532
    it.rewind();
533
 
    unsigned char *pos=read_info.row_start;
 
533
    uchar *pos=read_info.row_start;
534
534
#ifdef HAVE_purify
535
535
    read_info.row_end[0]=0;
536
536
#endif
563
563
      }
564
564
      else
565
565
      {
566
 
        uint32_t length;
567
 
        unsigned char save_chr;
 
566
        uint length;
 
567
        uchar save_chr;
568
568
        if ((length=(uint) (read_info.row_end-pos)) >
569
569
            field->field_length)
570
570
          length=field->field_length;
623
623
  List_iterator_fast<Item> it(fields_vars);
624
624
  Item *item;
625
625
  Table *table= table_list->table;
626
 
  uint32_t enclosed_length;
 
626
  uint enclosed_length;
627
627
  uint64_t id;
628
628
  bool err;
629
629
 
642
642
 
643
643
    while ((item= it++))
644
644
    {
645
 
      uint32_t length;
646
 
      unsigned char *pos;
 
645
      uint length;
 
646
      uchar *pos;
647
647
      Item *real_item;
648
648
 
649
649
      if (read_info.read_field())
822
822
*/
823
823
 
824
824
 
825
 
READ_INFO::READ_INFO(File file_par, uint32_t tot_length, const CHARSET_INFO * const cs,
 
825
READ_INFO::READ_INFO(File file_par, uint tot_length, const CHARSET_INFO * const cs,
826
826
                     String &field_term, String &line_start, String &line_term,
827
827
                     String &enclosed_par, int escape, bool get_it_from_net,
828
828
                     bool is_fifo)
852
852
    line_term_ptr=(char*) "";
853
853
  }
854
854
  enclosed_char= (enclosed_length=enclosed_par.length()) ?
855
 
    (unsigned char) enclosed_par[0] : INT_MAX;
856
 
  field_term_char= field_term_length ? (unsigned char) field_term_ptr[0] : INT_MAX;
857
 
  line_term_char= line_term_length ? (unsigned char) line_term_ptr[0] : INT_MAX;
 
855
    (uchar) enclosed_par[0] : INT_MAX;
 
856
  field_term_char= field_term_length ? (uchar) field_term_ptr[0] : INT_MAX;
 
857
  line_term_char= line_term_length ? (uchar) line_term_ptr[0] : INT_MAX;
858
858
  error=eof=found_end_of_line=found_null=line_cuted=0;
859
859
  buff_length=tot_length;
860
860
 
861
861
 
862
862
  /* Set of a stack for unget if long terminators */
863
 
  uint32_t length=cmax(field_term_length,line_term_length)+1;
 
863
  uint length=max(field_term_length,line_term_length)+1;
864
864
  set_if_bigger(length,line_start.length());
865
865
  stack=stack_pos=(int*) sql_alloc(sizeof(int)*length);
866
866
 
867
 
  if (!(buffer=(unsigned char*) my_malloc(buff_length+1,MYF(0))))
 
867
  if (!(buffer=(uchar*) my_malloc(buff_length+1,MYF(0))))
868
868
    error=1; /* purecov: inspected */
869
869
  else
870
870
  {
874
874
                      (is_fifo ? READ_FIFO : READ_CACHE),0L,1,
875
875
                      MYF(MY_WME)))
876
876
    {
877
 
      free((unsigned char*) buffer); /* purecov: inspected */
 
877
      my_free((uchar*) buffer,MYF(0)); /* purecov: inspected */
878
878
      error=1;
879
879
    }
880
880
    else
903
903
  {
904
904
    if (need_end_io_cache)
905
905
      ::end_io_cache(&cache);
906
 
    free((unsigned char*) buffer);
 
906
    my_free((uchar*) buffer,MYF(0));
907
907
    error=1;
908
908
  }
909
909
}
913
913
#define PUSH(A) *(stack_pos++)=(A)
914
914
 
915
915
 
916
 
inline int READ_INFO::terminator(char *ptr,uint32_t length)
 
916
inline int READ_INFO::terminator(char *ptr,uint length)
917
917
{
918
918
  int chr=0;                                    // Keep gcc happy
919
 
  uint32_t i;
 
919
  uint i;
920
920
  for (i=1 ; i < length ; i++)
921
921
  {
922
922
    if ((chr=GET) != *++ptr)
928
928
    return 1;
929
929
  PUSH(chr);
930
930
  while (i-- > 1)
931
 
    PUSH((unsigned char) *--ptr);
 
931
    PUSH((uchar) *--ptr);
932
932
  return 0;
933
933
}
934
934
 
936
936
int READ_INFO::read_field()
937
937
{
938
938
  int chr,found_enclosed_char;
939
 
  unsigned char *to,*new_buffer;
 
939
  uchar *to,*new_buffer;
940
940
 
941
941
  found_null=0;
942
942
  if (found_end_of_line)
959
959
  if (chr == enclosed_char)
960
960
  {
961
961
    found_enclosed_char=enclosed_char;
962
 
    *to++=(unsigned char) chr;                          // If error
 
962
    *to++=(uchar) chr;                          // If error
963
963
  }
964
964
  else
965
965
  {
976
976
      if ((my_mbcharlen(read_charset, chr) > 1) &&
977
977
          to+my_mbcharlen(read_charset, chr) <= end_of_buff)
978
978
      {
979
 
          unsigned char* p = (unsigned char*)to;
 
979
          uchar* p = (uchar*)to;
980
980
          *to++ = chr;
981
981
          int ml = my_mbcharlen(read_charset, chr);
982
982
          int i;
991
991
                          (const char *)to))
992
992
            continue;
993
993
          for (i=0; i<ml; i++)
994
 
            PUSH((unsigned char) *--to);
 
994
            PUSH((uchar) *--to);
995
995
          chr = GET;
996
996
      }
997
997
#endif
1001
1001
      {
1002
1002
        if ((chr=GET) == my_b_EOF)
1003
1003
        {
1004
 
          *to++= (unsigned char) escape_char;
 
1004
          *to++= (uchar) escape_char;
1005
1005
          goto found_eof;
1006
1006
        }
1007
1007
        /*
1013
1013
         */
1014
1014
        if (escape_char != enclosed_char || chr == escape_char)
1015
1015
        {
1016
 
          *to++ = (unsigned char) unescape((char) chr);
 
1016
          *to++ = (uchar) unescape((char) chr);
1017
1017
          continue;
1018
1018
        }
1019
1019
        PUSH(chr);
1038
1038
      {
1039
1039
        if ((chr=GET) == found_enclosed_char)
1040
1040
        {                                       // Remove dupplicated
1041
 
          *to++ = (unsigned char) chr;
 
1041
          *to++ = (uchar) chr;
1042
1042
          continue;
1043
1043
        }
1044
1044
        // End of enclosed field if followed by field_term or line_term
1077
1077
          return 0;
1078
1078
        }
1079
1079
      }
1080
 
      *to++ = (unsigned char) chr;
 
1080
      *to++ = (uchar) chr;
1081
1081
    }
1082
1082
    /*
1083
1083
    ** We come here if buffer is too small. Enlarge it and continue
1084
1084
    */
1085
 
    if (!(new_buffer=(unsigned char*) my_realloc((char*) buffer,buff_length+1+IO_SIZE,
 
1085
    if (!(new_buffer=(uchar*) my_realloc((char*) buffer,buff_length+1+IO_SIZE,
1086
1086
                                        MYF(MY_WME))))
1087
1087
      return (error=1);
1088
1088
    to=new_buffer + (to-buffer);
1117
1117
int READ_INFO::read_fixed_length()
1118
1118
{
1119
1119
  int chr;
1120
 
  unsigned char *to;
 
1120
  uchar *to;
1121
1121
  if (found_end_of_line)
1122
1122
    return 1;                                   // One have to call next_line
1123
1123
 
1137
1137
    {
1138
1138
      if ((chr=GET) == my_b_EOF)
1139
1139
      {
1140
 
        *to++= (unsigned char) escape_char;
 
1140
        *to++= (uchar) escape_char;
1141
1141
        goto found_eof;
1142
1142
      }
1143
 
      *to++ =(unsigned char) unescape((char) chr);
 
1143
      *to++ =(uchar) unescape((char) chr);
1144
1144
      continue;
1145
1145
    }
1146
1146
    if (chr == line_term_char)
1152
1152
        return 0;
1153
1153
      }
1154
1154
    }
1155
 
    *to++ = (unsigned char) chr;
 
1155
    *to++ = (uchar) chr;
1156
1156
  }
1157
1157
  row_end=to;                                   // Found full line
1158
1158
  return 0;
1183
1183
#ifdef USE_MB
1184
1184
   if (my_mbcharlen(read_charset, chr) > 1)
1185
1185
   {
1186
 
       for (uint32_t i=1;
 
1186
       for (uint i=1;
1187
1187
            chr != my_b_EOF && i<my_mbcharlen(read_charset, chr);
1188
1188
            i++)
1189
1189
           chr = GET;
1230
1230
      PUSH(chr);
1231
1231
      while (--ptr != line_start_ptr)
1232
1232
      {                                         // Restart with next char
1233
 
        PUSH((unsigned char) *ptr);
 
1233
        PUSH((uchar) *ptr);
1234
1234
      }
1235
1235
      goto try_again;
1236
1236
    }