~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_load.cc

  • Committer: Monty Taylor
  • Date: 2010-10-07 05:19:48 UTC
  • mto: (1821.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 1822.
  • Revision ID: mordred@inaugust.com-20101007051948-woxgvqo7fr47yp22
TurnedĀ onĀ -Werror.

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
  */
76
76
  void end_io_cache()
77
77
  {
78
 
    cache.end_io_cache();
 
78
    internal::end_io_cache(&cache);
79
79
    need_end_io_cache = 0;
80
80
  }
81
81
 
124
124
                List<Item> &set_values,
125
125
                enum enum_duplicates handle_duplicates, bool ignore)
126
126
{
 
127
  char name[FN_REFLEN];
127
128
  int file;
128
129
  Table *table= NULL;
129
130
  int error;
130
131
  String *field_term=ex->field_term,*escaped=ex->escaped;
131
132
  String *enclosed=ex->enclosed;
132
133
  bool is_fifo=0;
133
 
 
134
 
  assert(table_list->getSchemaName()); // This should never be null
135
 
 
 
134
  char *db= table_list->db;                     // This is never null
 
135
  assert(db);
136
136
  /*
137
137
    If path for cursor is not defined, we will use the current database.
138
138
    If this is not set, we will use the directory where the table to be
139
139
    loaded is located
140
140
  */
141
 
  util::string::const_shared_ptr schema(session->schema());
142
 
  const char *tdb= (schema and not schema->empty()) ? schema->c_str() : table_list->getSchemaName(); // Result should never be null
 
141
  const char *tdb= session->db.empty() ? db  : session->db.c_str();             // Result is never null
143
142
  assert(tdb);
144
143
  uint32_t skip_lines= ex->skip_lines;
145
144
  bool transactional_table;
146
 
  Session::killed_state_t killed_status= Session::NOT_KILLED;
 
145
  Session::killed_state killed_status= Session::NOT_KILLED;
147
146
 
148
147
  /* Escape and enclosed character may be a utf8 4-byte character */
149
148
  if (escaped->length() > 4 || enclosed->length() > 4)
171
170
  */
172
171
  if (unique_table(table_list, table_list->next_global))
173
172
  {
174
 
    my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->getTableName());
 
173
    my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->table_name);
175
174
    return(true);
176
175
  }
177
176
 
206
205
    */
207
206
    if (table->timestamp_field)
208
207
    {
209
 
      if (table->isWriteSet(table->timestamp_field->position()))
210
 
      {
 
208
      if (table->isWriteSet(table->timestamp_field->field_index))
211
209
        table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
212
 
      }
213
210
      else
214
211
      {
215
 
        table->setWriteSet(table->timestamp_field->position());
 
212
        table->setWriteSet(table->timestamp_field->field_index);
216
213
      }
217
214
    }
218
215
    /* Fix the expressions in SET clause */
257
254
    return(true);
258
255
  }
259
256
 
260
 
  fs::path to_file(ex->file_name);
261
 
  fs::path target_path(fs::system_complete(getDataHomeCatalog()));
262
 
  if (not to_file.has_root_directory())
263
 
  {
264
 
    int count_elements= 0;
265
 
    for (fs::path::iterator iter= to_file.begin();
266
 
         iter != to_file.end();
267
 
         ++iter, ++count_elements)
268
 
    { }
269
 
 
270
 
    if (count_elements == 1)
271
 
    {
272
 
      target_path /= tdb;
273
 
    }
274
 
    target_path /= to_file;
275
 
  }
276
 
  else
277
 
  {
278
 
    target_path= to_file;
279
 
  }
280
 
 
281
 
  if (not secure_file_priv.string().empty())
282
 
  {
283
 
    if (target_path.file_string().substr(0, secure_file_priv.file_string().size()) != secure_file_priv.file_string())
284
 
    {
285
 
      /* Read only allowed from within dir specified by secure_file_priv */
286
 
      my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");
 
257
  {
 
258
#ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS
 
259
    ex->file_name+=dirname_length(ex->file_name);
 
260
#endif
 
261
    if (!internal::dirname_length(ex->file_name))
 
262
    {
 
263
      strcpy(name, getDataHomeCatalog().c_str());
 
264
      strncat(name, "/", 1);
 
265
      strncat(name, tdb, FN_REFLEN-getDataHomeCatalog().size());
 
266
      (void) internal::fn_format(name, ex->file_name, name, "",
 
267
                       MY_RELATIVE_PATH | MY_UNPACK_FILENAME);
 
268
    }
 
269
    else
 
270
    {
 
271
      (void) internal::fn_format(name, ex->file_name, getDataHomeCatalog().c_str(), "",
 
272
                       MY_RELATIVE_PATH | MY_UNPACK_FILENAME);
 
273
 
 
274
      if (opt_secure_file_priv)
 
275
      {
 
276
        fs::path secure_file_path(fs::system_complete(fs::path(opt_secure_file_priv)));
 
277
        fs::path target_path(fs::system_complete(fs::path(name)));
 
278
        if (target_path.file_string().substr(0, secure_file_path.file_string().size()) != secure_file_path.file_string())
 
279
        {
 
280
          /* Read only allowed from within dir specified by secure_file_priv */
 
281
          my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");
 
282
          return(true);
 
283
        }
 
284
      }
 
285
 
 
286
      struct stat stat_info;
 
287
      if (stat(name,&stat_info))
 
288
      {
 
289
        my_error(ER_FILE_NOT_FOUND, MYF(0), name, errno);
 
290
        return(true);
 
291
      }
 
292
 
 
293
      // if we are not in slave thread, the cursor must be:
 
294
      if (!((stat_info.st_mode & S_IROTH) == S_IROTH &&  // readable by others
 
295
            (stat_info.st_mode & S_IFLNK) != S_IFLNK && // and not a symlink
 
296
            ((stat_info.st_mode & S_IFREG) == S_IFREG ||
 
297
             (stat_info.st_mode & S_IFIFO) == S_IFIFO)))
 
298
      {
 
299
        my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), name);
 
300
        return(true);
 
301
      }
 
302
      if ((stat_info.st_mode & S_IFIFO) == S_IFIFO)
 
303
        is_fifo = 1;
 
304
    }
 
305
    if ((file=internal::my_open(name,O_RDONLY,MYF(MY_WME))) < 0)
 
306
    {
 
307
      my_error(ER_CANT_OPEN_FILE, MYF(0), name, errno);
287
308
      return(true);
288
309
    }
289
310
  }
290
311
 
291
 
  struct stat stat_info;
292
 
  if (stat(target_path.file_string().c_str(), &stat_info))
293
 
  {
294
 
    my_error(ER_FILE_NOT_FOUND, MYF(0), target_path.file_string().c_str(), errno);
295
 
    return(true);
296
 
  }
297
 
 
298
 
  // if we are not in slave thread, the cursor must be:
299
 
  if (!((stat_info.st_mode & S_IROTH) == S_IROTH &&  // readable by others
300
 
        (stat_info.st_mode & S_IFLNK) != S_IFLNK && // and not a symlink
301
 
        ((stat_info.st_mode & S_IFREG) == S_IFREG ||
302
 
         (stat_info.st_mode & S_IFIFO) == S_IFIFO)))
303
 
  {
304
 
    my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), target_path.file_string().c_str());
305
 
    return(true);
306
 
  }
307
 
  if ((stat_info.st_mode & S_IFIFO) == S_IFIFO)
308
 
    is_fifo = 1;
309
 
 
310
 
 
311
 
  if ((file=internal::my_open(target_path.file_string().c_str(), O_RDONLY,MYF(MY_WME))) < 0)
312
 
  {
313
 
    my_error(ER_CANT_OPEN_FILE, MYF(0), target_path.file_string().c_str(), errno);
314
 
    return(true);
315
 
  }
316
312
  CopyInfo info;
317
313
  memset(&info, 0, sizeof(info));
318
314
  info.ignore= ignore;
319
315
  info.handle_duplicates=handle_duplicates;
320
316
  info.escape_char=escaped->length() ? (*escaped)[0] : INT_MAX;
321
317
 
322
 
  SchemaIdentifier identifier(*schema);
 
318
  SchemaIdentifier identifier(session->db);
323
319
  READ_INFO read_info(file, tot_length,
324
320
                      ex->cs ? ex->cs : plugin::StorageEngine::getSchemaCollation(identifier),
325
321
                      *field_term, *ex->line_start, *ex->line_term, *enclosed,
393
389
     simulated killing in the middle of per-row loop
394
390
     must be effective for binlogging
395
391
  */
396
 
  killed_status= (error == 0)? Session::NOT_KILLED : session->getKilled();
 
392
  killed_status= (error == 0)? Session::NOT_KILLED : session->killed;
397
393
  if (error)
398
394
  {
399
395
    error= -1;                          // Error on read
400
396
    goto err;
401
397
  }
402
 
 
403
 
  char msg[FN_REFLEN];
404
 
  snprintf(msg, sizeof(msg), ER(ER_LOAD_INFO), info.records, info.deleted,
 
398
  snprintf(name, sizeof(name), ER(ER_LOAD_INFO), info.records, info.deleted,
405
399
           (info.records - info.copied), session->cuted_fields);
406
400
 
407
401
  if (session->transaction.stmt.hasModifiedNonTransData())
408
402
    session->transaction.all.markModifiedNonTransData();
409
403
 
410
404
  /* ok to client sent only after binlog write and engine commit */
411
 
  session->my_ok(info.copied + info.deleted, 0, 0L, msg);
 
405
  session->my_ok(info.copied + info.deleted, 0, 0L, name);
412
406
err:
413
407
  assert(transactional_table || !(info.copied || info.deleted) ||
414
408
              session->transaction.stmt.hasModifiedNonTransData());
439
433
 
440
434
  while (!read_info.read_fixed_length())
441
435
  {
442
 
    if (session->getKilled())
 
436
    if (session->killed)
443
437
    {
444
438
      session->send_kill_message();
445
439
      return(1);
457
451
    }
458
452
    it.rewind();
459
453
    unsigned char *pos=read_info.row_start;
460
 
#ifdef HAVE_VALGRIND
 
454
#ifdef HAVE_purify
461
455
    read_info.row_end[0]=0;
462
456
#endif
463
457
 
512
506
                          ER(ER_WARN_TOO_MANY_RECORDS), session->row_count);
513
507
    }
514
508
 
515
 
    if (session->getKilled() ||
 
509
    if (session->killed ||
516
510
        fill_record(session, set_fields, set_values,
517
511
                    ignore_check_option_errors))
518
512
      return(1);
561
555
 
562
556
  for (;;it.rewind())
563
557
  {
564
 
    if (session->getKilled())
 
558
    if (session->killed)
565
559
    {
566
560
      session->send_kill_message();
567
561
      return(1);
694
688
      }
695
689
    }
696
690
 
697
 
    if (session->getKilled() ||
 
691
    if (session->killed ||
698
692
        fill_record(session, set_fields, set_values,
699
693
                    ignore_check_option_errors))
700
694
      return(1);
715
709
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
716
710
                          ER_WARN_TOO_MANY_RECORDS, ER(ER_WARN_TOO_MANY_RECORDS),
717
711
                          session->row_count);
718
 
      if (session->getKilled())
 
712
      if (session->killed)
719
713
        return(1);
720
714
    }
721
715
    session->row_count++;
789
783
 
790
784
 
791
785
  /* Set of a stack for unget if long terminators */
792
 
  size_t length= max(field_term_length,line_term_length)+1;
793
 
  set_if_bigger(length, line_start.length());
 
786
  uint32_t length= max(field_term_length,line_term_length)+1;
 
787
  set_if_bigger(length,line_start.length());
794
788
  stack= stack_pos= (int*) memory::sql_alloc(sizeof(int)*length);
795
789
 
796
790
  if (!(buffer=(unsigned char*) calloc(1, buff_length+1)))
798
792
  else
799
793
  {
800
794
    end_of_buff=buffer+buff_length;
801
 
    if (cache.init_io_cache((false) ? -1 : cursor, 0,
802
 
                            (false) ? internal::READ_NET :
803
 
                            (is_fifo ? internal::READ_FIFO : internal::READ_CACHE),0L,1,
804
 
                            MYF(MY_WME)))
 
795
    if (init_io_cache(&cache,(false) ? -1 : cursor, 0,
 
796
                      (false) ? internal::READ_NET :
 
797
                      (is_fifo ? internal::READ_FIFO : internal::READ_CACHE),0L,1,
 
798
                      MYF(MY_WME)))
805
799
    {
806
800
      free((unsigned char*) buffer);
807
801
      error=1;
824
818
  if (!error)
825
819
  {
826
820
    if (need_end_io_cache)
827
 
      cache.end_io_cache();
 
821
      internal::end_io_cache(&cache);
828
822
    free(buffer);
829
823
    error=1;
830
824
  }