~ubuntu-branches/ubuntu/maverick/mysql-5.1/maverick-proposed

« back to all changes in this revision

Viewing changes to sql/sql_load.cc

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 14:16:05 UTC
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: package-import@ubuntu.com-20120222141605-nxlu9yzc6attylc2
Tags: upstream-5.1.61
ImportĀ upstreamĀ versionĀ 5.1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2006 MySQL AB
 
1
/*
 
2
   Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
2
3
 
3
4
   This program is free software; you can redistribute it and/or modify
4
5
   it under the terms of the GNU General Public License as published by
11
12
 
12
13
   You should have received a copy of the GNU General Public License
13
14
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 
16
*/
15
17
 
16
18
 
17
19
/* Copy data from a textfile to table */
128
130
  bool is_fifo=0;
129
131
#ifndef EMBEDDED_LIBRARY
130
132
  LOAD_FILE_INFO lf_info;
 
133
  THD::killed_state killed_status;
131
134
#endif
132
135
  char *db = table_list->db;                    // This is never null
133
136
  /*
138
141
  char *tdb= thd->db ? thd->db : db;            // Result is never null
139
142
  ulong skip_lines= ex->skip_lines;
140
143
  bool transactional_table;
141
 
  THD::killed_state killed_status= THD::NOT_KILLED;
142
144
  DBUG_ENTER("mysql_load");
143
145
 
 
146
  /*
 
147
    Bug #34283
 
148
    mysqlbinlog leaves tmpfile after termination if binlog contains
 
149
    load data infile, so in mixed mode we go to row-based for
 
150
    avoiding the problem.
 
151
  */
 
152
  thd->set_current_stmt_binlog_row_based_if_mixed();
 
153
 
144
154
#ifdef EMBEDDED_LIBRARY
145
155
  read_file_from_client  = 0; //server is always in the same process 
146
156
#endif
306
316
      (void) fn_format(name, ex->file_name, mysql_real_data_home, "",
307
317
                       MY_RELATIVE_PATH | MY_UNPACK_FILENAME |
308
318
                       MY_RETURN_REAL_PATH);
309
 
#if !defined(__WIN__) && ! defined(__NETWARE__)
310
 
      MY_STAT stat_info;
311
 
      if (!my_stat(name,&stat_info,MYF(MY_WME)))
312
 
        DBUG_RETURN(TRUE);
313
 
 
314
 
      // if we are not in slave thread, the file must be:
315
 
      if (!thd->slave_thread &&
316
 
          !((stat_info.st_mode & S_IROTH) == S_IROTH &&  // readable by others
317
 
            (stat_info.st_mode & S_IFLNK) != S_IFLNK && // and not a symlink
318
 
            ((stat_info.st_mode & S_IFREG) == S_IFREG ||
319
 
             (stat_info.st_mode & S_IFIFO) == S_IFIFO)))
320
 
      {
321
 
        my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), name);
322
 
        DBUG_RETURN(TRUE);
323
 
      }
324
 
      if ((stat_info.st_mode & S_IFIFO) == S_IFIFO)
325
 
        is_fifo = 1;
326
 
#endif
327
 
 
328
 
      if (thd->slave_thread)
329
 
      {
 
319
    }
 
320
 
 
321
    if (thd->slave_thread)
 
322
    {
330
323
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
331
 
        if (strncmp(active_mi->rli.slave_patternload_file, name, 
332
 
            active_mi->rli.slave_patternload_file_size))
333
 
        {
334
 
          /*
335
 
            LOAD DATA INFILE in the slave SQL Thread can only read from 
336
 
            --slave-load-tmpdir". This should never happen. Please, report a bug.
337
 
           */
338
 
 
339
 
          sql_print_error("LOAD DATA INFILE in the slave SQL Thread can only read from --slave-load-tmpdir. " \
340
 
                          "Please, report a bug.");
341
 
          my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--slave-load-tmpdir");
342
 
          DBUG_RETURN(TRUE);
343
 
        }
344
 
#else
 
324
      if (strncmp(active_mi->rli.slave_patternload_file, name, 
 
325
          active_mi->rli.slave_patternload_file_size))
 
326
      {
345
327
        /*
346
 
          This is impossible and should never happen.
 
328
          LOAD DATA INFILE in the slave SQL Thread can only read from 
 
329
          --slave-load-tmpdir". This should never happen. Please, report a bug.
347
330
        */
348
 
        DBUG_ASSERT(FALSE); 
349
 
#endif
350
 
      }
351
 
      else if (!is_secure_file_path(name))
352
 
      {
353
 
        /* Read only allowed from within dir specified by secure_file_priv */
354
 
        my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");
 
331
 
 
332
        sql_print_error("LOAD DATA INFILE in the slave SQL Thread can only read from --slave-load-tmpdir. " \
 
333
                        "Please, report a bug.");
 
334
        my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--slave-load-tmpdir");
355
335
        DBUG_RETURN(TRUE);
356
336
      }
357
 
 
358
 
    }
 
337
#else
 
338
      /*
 
339
        This is impossible and should never happen.
 
340
      */
 
341
      DBUG_ASSERT(FALSE); 
 
342
#endif
 
343
    }
 
344
    else if (!is_secure_file_path(name))
 
345
    {
 
346
      /* Read only allowed from within dir specified by secure_file_priv */
 
347
      my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");
 
348
      DBUG_RETURN(TRUE);
 
349
    }
 
350
 
 
351
#if !defined(__WIN__) && ! defined(__NETWARE__)
 
352
    MY_STAT stat_info;
 
353
    if (!my_stat(name, &stat_info, MYF(MY_WME)))
 
354
      DBUG_RETURN(TRUE);
 
355
 
 
356
    // if we are not in slave thread, the file must be:
 
357
    if (!thd->slave_thread &&
 
358
        !((stat_info.st_mode & S_IROTH) == S_IROTH &&  // readable by others
 
359
          (stat_info.st_mode & S_IFLNK) != S_IFLNK &&  // and not a symlink
 
360
          ((stat_info.st_mode & S_IFREG) == S_IFREG || // and a regular file
 
361
           (stat_info.st_mode & S_IFIFO) == S_IFIFO))) // or FIFO
 
362
    {
 
363
      my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), name);
 
364
      DBUG_RETURN(TRUE);
 
365
    }
 
366
    if ((stat_info.st_mode & S_IFIFO) == S_IFIFO)
 
367
      is_fifo= 1;
 
368
#endif
 
369
 
359
370
    if ((file=my_open(name,O_RDONLY,MYF(MY_WME))) < 0)
360
371
      DBUG_RETURN(TRUE);
361
372
  }
455
466
                    error=1;
456
467
                    thd->killed= THD::KILL_QUERY;
457
468
                  };);
458
 
  killed_status= (error == 0)? THD::NOT_KILLED : thd->killed;
 
469
 
 
470
#ifndef EMBEDDED_LIBRARY
 
471
  killed_status= (error == 0) ? THD::NOT_KILLED : thd->killed;
 
472
#endif
 
473
 
459
474
  /*
460
475
    We must invalidate the table in query cache before binlog writing and
461
476
    ha_autocommit_...
555
570
                                                  transactional_table,
556
571
                                                  errcode);
557
572
      }
 
573
 
 
574
      /*
 
575
        Flushing the IO CACHE while writing the execute load query log event
 
576
        may result in error (for instance, because the max_binlog_size has been 
 
577
        reached, and rotation of the binary log failed).
 
578
      */
 
579
      error= error || mysql_bin_log.get_log_file()->error;
558
580
    }
559
581
    if (error)
560
582
      goto err;
708
730
  List_iterator_fast<Item> it(fields_vars);
709
731
  Item_field *sql_field;
710
732
  TABLE *table= table_list->table;
711
 
  ulonglong id;
712
733
  bool err;
713
734
  DBUG_ENTER("read_fixed_length");
714
735
 
715
 
  id= 0;
716
 
 
717
736
  while (!read_info.read_fixed_length())
718
737
  {
719
738
    if (thd->killed)
839
858
  Item *item;
840
859
  TABLE *table= table_list->table;
841
860
  uint enclosed_length;
842
 
  ulonglong id;
843
861
  bool err;
844
862
  DBUG_ENTER("read_sep_field");
845
863
 
846
864
  enclosed_length=enclosed.length();
847
 
  id= 0;
848
865
 
849
866
  for (;;it.rewind())
850
867
  {
1060
1077
                     String &field_term, String &line_start, String &line_term,
1061
1078
                     String &enclosed_par, int escape, bool get_it_from_net,
1062
1079
                     bool is_fifo)
1063
 
  :file(file_par),escape_char(escape)
 
1080
  :file(file_par), buff_length(tot_length), escape_char(escape),
 
1081
   found_end_of_line(false), eof(false), need_end_io_cache(false),
 
1082
   error(false), line_cuted(false), found_null(false), read_charset(cs)
1064
1083
{
1065
 
  read_charset= cs;
1066
1084
  field_term_ptr=(char*) field_term.ptr();
1067
1085
  field_term_length= field_term.length();
1068
1086
  line_term_ptr=(char*) line_term.ptr();
1089
1107
    (uchar) enclosed_par[0] : INT_MAX;
1090
1108
  field_term_char= field_term_length ? (uchar) field_term_ptr[0] : INT_MAX;
1091
1109
  line_term_char= line_term_length ? (uchar) line_term_ptr[0] : INT_MAX;
1092
 
  error=eof=found_end_of_line=found_null=line_cuted=0;
1093
 
  buff_length=tot_length;
1094
1110
 
1095
1111
 
1096
1112
  /* Set of a stack for unget if long terminators */
1097
 
  uint length=max(field_term_length,line_term_length)+1;
 
1113
  uint length= max(cs->mbmaxlen, max(field_term_length, line_term_length)) + 1;
1098
1114
  set_if_bigger(length,line_start.length());
1099
1115
  stack=stack_pos=(int*) sql_alloc(sizeof(int)*length);
1100
1116
 
1109
1125
                      MYF(MY_WME)))
1110
1126
    {
1111
1127
      my_free((uchar*) buffer,MYF(0)); /* purecov: inspected */
 
1128
      buffer= NULL;
1112
1129
      error=1;
1113
1130
    }
1114
1131
    else
1135
1152
 
1136
1153
READ_INFO::~READ_INFO()
1137
1154
{
1138
 
  if (!error)
1139
 
  {
1140
 
    if (need_end_io_cache)
1141
 
      ::end_io_cache(&cache);
1142
 
    my_free((uchar*) buffer,MYF(0));
1143
 
    error=1;
1144
 
  }
 
1155
  if (need_end_io_cache)
 
1156
    ::end_io_cache(&cache);
 
1157
 
 
1158
  my_free(buffer, MYF(MY_ALLOW_ZERO_PTR));
1145
1159
}
1146
1160
 
1147
1161
 
1208
1222
    while ( to < end_of_buff)
1209
1223
    {
1210
1224
      chr = GET;
1211
 
#ifdef USE_MB
1212
 
      if ((my_mbcharlen(read_charset, chr) > 1) &&
1213
 
          to+my_mbcharlen(read_charset, chr) <= end_of_buff)
1214
 
      {
1215
 
          uchar* p = (uchar*)to;
1216
 
          *to++ = chr;
1217
 
          int ml = my_mbcharlen(read_charset, chr);
1218
 
          int i;
1219
 
          for (i=1; i<ml; i++) {
1220
 
              chr = GET;
1221
 
              if (chr == my_b_EOF)
1222
 
                  goto found_eof;
1223
 
              *to++ = chr;
1224
 
          }
1225
 
          if (my_ismbchar(read_charset,
1226
 
                          (const char *)p,
1227
 
                          (const char *)to))
1228
 
            continue;
1229
 
          for (i=0; i<ml; i++)
1230
 
            PUSH((uchar) *--to);
1231
 
          chr = GET;
1232
 
      }
1233
 
#endif
1234
1225
      if (chr == my_b_EOF)
1235
1226
        goto found_eof;
1236
1227
      if (chr == escape_char)
1314
1305
          return 0;
1315
1306
        }
1316
1307
      }
 
1308
#ifdef USE_MB
 
1309
      if (my_mbcharlen(read_charset, chr) > 1 &&
 
1310
          to + my_mbcharlen(read_charset, chr) <= end_of_buff)
 
1311
      {
 
1312
        uchar* p= (uchar*) to;
 
1313
        int ml, i;
 
1314
        *to++ = chr;
 
1315
 
 
1316
        ml= my_mbcharlen(read_charset, chr);
 
1317
 
 
1318
        for (i= 1; i < ml; i++) 
 
1319
        {
 
1320
          chr= GET;
 
1321
          if (chr == my_b_EOF)
 
1322
          {
 
1323
            /*
 
1324
             Need to back up the bytes already ready from illformed
 
1325
             multi-byte char 
 
1326
            */
 
1327
            to-= i;
 
1328
            goto found_eof;
 
1329
          }
 
1330
          *to++ = chr;
 
1331
        }
 
1332
        if (my_ismbchar(read_charset,
 
1333
                        (const char *)p,
 
1334
                        (const char *)to))
 
1335
          continue;
 
1336
        for (i= 0; i < ml; i++)
 
1337
          PUSH((uchar) *--to);
 
1338
        chr= GET;
 
1339
      }
 
1340
#endif
1317
1341
      *to++ = (uchar) chr;
1318
1342
    }
1319
1343
    /*