~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_load.cc

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
/* Copy data from a textfile to table */
18
18
 
19
19
#include <drizzled/server_includes.h>
20
 
#include <drizzled/sql_load.h>
21
 
#include <drizzled/error.h>
22
 
#include <drizzled/data_home.h>
23
 
#include <drizzled/session.h>
24
 
#include <drizzled/sql_base.h>
25
 
#include <drizzled/field/timestamp.h>
 
20
#include "sql_repl.h"
 
21
#include <drizzled/drizzled_error_messages.h>
 
22
 
26
23
 
27
24
class READ_INFO {
28
25
  File  file;
69
66
  /*
70
67
    Either this method, or we need to make cache public
71
68
    Arg must be set from mysql_load() since constructor does not see
72
 
    either the table or Session value
 
69
    either the table or THD value
73
70
  */
74
71
  void set_io_cache_arg(void* arg) { cache.arg = arg; }
75
72
};
76
73
 
77
 
static int read_fixed_length(Session *session, COPY_INFO &info, TableList *table_list,
 
74
static int read_fixed_length(THD *thd, COPY_INFO &info, TableList *table_list,
78
75
                             List<Item> &fields_vars, List<Item> &set_fields,
79
76
                             List<Item> &set_values, READ_INFO &read_info,
80
77
                             uint32_t skip_lines,
81
78
                             bool ignore_check_option_errors);
82
 
static int read_sep_field(Session *session, COPY_INFO &info, TableList *table_list,
 
79
static int read_sep_field(THD *thd, COPY_INFO &info, TableList *table_list,
83
80
                          List<Item> &fields_vars, List<Item> &set_fields,
84
81
                          List<Item> &set_values, READ_INFO &read_info,
85
82
                          String &enclosed, uint32_t skip_lines,
86
83
                          bool ignore_check_option_errors);
87
84
 
 
85
static bool write_execute_load_query_log_event(THD *thd,
 
86
                                               bool duplicates, bool ignore,
 
87
                                               bool transactional_table,
 
88
                                               THD::killed_state killed_status);
88
89
 
89
90
/*
90
91
  Execute LOAD DATA query
91
92
 
92
93
  SYNOPSYS
93
94
    mysql_load()
94
 
      session - current thread
95
 
      ex  - file_exchange object representing source file and its parsing rules
 
95
      thd - current thread
 
96
      ex  - sql_exchange object representing source file and its parsing rules
96
97
      table_list  - list of tables to which we are loading data
97
98
      fields_vars - list of fields and variables to which we read
98
99
                    data from file
107
108
    true - error / false - success
108
109
*/
109
110
 
110
 
int mysql_load(Session *session,file_exchange *ex,TableList *table_list,
 
111
int mysql_load(THD *thd,sql_exchange *ex,TableList *table_list,
111
112
                List<Item> &fields_vars, List<Item> &set_fields,
112
113
                List<Item> &set_values,
113
114
                enum enum_duplicates handle_duplicates, bool ignore,
120
121
  String *field_term=ex->field_term,*escaped=ex->escaped;
121
122
  String *enclosed=ex->enclosed;
122
123
  bool is_fifo=0;
123
 
  char *db= table_list->db;                     // This is never null
124
 
  assert(db);
 
124
  LOAD_FILE_INFO lf_info;
 
125
  char *db = table_list->db;                    // This is never null
125
126
  /*
126
127
    If path for file is not defined, we will use the current database.
127
128
    If this is not set, we will use the directory where the table to be
128
129
    loaded is located
129
130
  */
130
 
  char *tdb= session->db ? session->db : db;            // Result is never null
131
 
  assert(tdb);
 
131
  char *tdb= thd->db ? thd->db : db;            // Result is never null
132
132
  uint32_t skip_lines= ex->skip_lines;
133
133
  bool transactional_table;
134
 
  Session::killed_state killed_status= Session::NOT_KILLED;
 
134
  THD::killed_state killed_status= THD::NOT_KILLED;
135
135
 
136
 
  /* Escape and enclosed character may be a utf8 4-byte character */
137
 
  if (escaped->length() > 4 || enclosed->length() > 4)
 
136
  if (escaped->length() > 1 || enclosed->length() > 1)
138
137
  {
139
 
    my_error(ER_WRONG_FIELD_TERMINATORS,MYF(0),enclosed->c_ptr(), enclosed->length());
 
138
    my_message(ER_WRONG_FIELD_TERMINATORS,ER(ER_WRONG_FIELD_TERMINATORS),
 
139
               MYF(0));
140
140
    return(true);
141
141
  }
142
 
  if (open_and_lock_tables(session, table_list))
 
142
  if (open_and_lock_tables(thd, table_list))
143
143
    return(true);
144
 
  if (setup_tables_and_check_access(session, &session->lex->select_lex.context,
145
 
                                    &session->lex->select_lex.top_join_list,
 
144
  if (setup_tables_and_check_access(thd, &thd->lex->select_lex.context,
 
145
                                    &thd->lex->select_lex.top_join_list,
146
146
                                    table_list,
147
 
                                    &session->lex->select_lex.leaf_tables, true))
 
147
                                    &thd->lex->select_lex.leaf_tables, true))
148
148
     return(-1);
149
149
 
150
150
  /*
155
155
    table is marked to be 'used for insert' in which case we should never
156
156
    mark this table as 'const table' (ie, one that has only one row).
157
157
  */
158
 
  if (unique_table(session, table_list, table_list->next_global, 0))
 
158
  if (unique_table(thd, table_list, table_list->next_global, 0))
159
159
  {
160
160
    my_error(ER_UPDATE_TABLE_USED, MYF(0), table_list->table_name);
161
161
    return(true);
175
175
      Let us also prepare SET clause, altough it is probably empty
176
176
      in this case.
177
177
    */
178
 
    if (setup_fields(session, 0, set_fields, MARK_COLUMNS_WRITE, 0, 0) ||
179
 
        setup_fields(session, 0, set_values, MARK_COLUMNS_READ, 0, 0))
 
178
    if (setup_fields(thd, 0, set_fields, MARK_COLUMNS_WRITE, 0, 0) ||
 
179
        setup_fields(thd, 0, set_values, MARK_COLUMNS_READ, 0, 0))
180
180
      return(true);
181
181
  }
182
182
  else
183
183
  {                                             // Part field list
184
184
    /* TODO: use this conds for 'WITH CHECK OPTIONS' */
185
 
    if (setup_fields(session, 0, fields_vars, MARK_COLUMNS_WRITE, 0, 0) ||
186
 
        setup_fields(session, 0, set_fields, MARK_COLUMNS_WRITE, 0, 0) ||
187
 
        check_that_all_fields_are_given_values(session, table, table_list))
 
185
    if (setup_fields(thd, 0, fields_vars, MARK_COLUMNS_WRITE, 0, 0) ||
 
186
        setup_fields(thd, 0, set_fields, MARK_COLUMNS_WRITE, 0, 0) ||
 
187
        check_that_all_fields_are_given_values(thd, table, table_list))
188
188
      return(true);
189
189
    /*
190
190
      Check whenever TIMESTAMP field with auto-set feature specified
202
202
      }
203
203
    }
204
204
    /* Fix the expressions in SET clause */
205
 
    if (setup_fields(session, 0, set_values, MARK_COLUMNS_READ, 0, 0))
 
205
    if (setup_fields(thd, 0, set_values, MARK_COLUMNS_READ, 0, 0))
206
206
      return(true);
207
207
  }
208
208
 
249
249
 
250
250
  if (read_file_from_client)
251
251
  {
252
 
    assert(0);
 
252
    (void)net_request_file(&thd->net,ex->file_name);
253
253
    file = -1;
254
254
  }
255
255
  else
259
259
#endif
260
260
    if (!dirname_length(ex->file_name))
261
261
    {
262
 
      strcpy(name, drizzle_real_data_home);
263
 
      strncat(name, tdb, FN_REFLEN-strlen(drizzle_real_data_home)-1);
 
262
      strxnmov(name, FN_REFLEN-1, mysql_real_data_home, tdb, NULL);
264
263
      (void) fn_format(name, ex->file_name, name, "",
265
264
                       MY_RELATIVE_PATH | MY_UNPACK_FILENAME);
266
265
    }
267
266
    else
268
267
    {
269
 
      (void) fn_format(name, ex->file_name, drizzle_real_data_home, "",
 
268
      (void) fn_format(name, ex->file_name, mysql_real_data_home, "",
270
269
                       MY_RELATIVE_PATH | MY_UNPACK_FILENAME);
271
270
 
272
271
      if (opt_secure_file_priv &&
279
278
 
280
279
      struct stat stat_info;
281
280
      if (stat(name,&stat_info))
282
 
      {
283
 
        my_error(ER_FILE_NOT_FOUND, MYF(0), name, errno);
284
281
        return(true);
285
 
      }
286
282
 
287
283
      // if we are not in slave thread, the file must be:
288
 
      if (!((stat_info.st_mode & S_IROTH) == S_IROTH &&  // readable by others
289
 
            (stat_info.st_mode & S_IFLNK) != S_IFLNK && // and not a symlink
290
 
            ((stat_info.st_mode & S_IFREG) == S_IFREG ||
291
 
             (stat_info.st_mode & S_IFIFO) == S_IFIFO)))
 
284
      if (!thd->slave_thread &&
 
285
          !((stat_info.st_mode & S_IROTH) == S_IROTH &&  // readable by others
 
286
            (stat_info.st_mode & S_IFLNK) != S_IFLNK && // and not a symlink
 
287
            ((stat_info.st_mode & S_IFREG) == S_IFREG ||
 
288
             (stat_info.st_mode & S_IFIFO) == S_IFIFO)))
292
289
      {
293
290
        my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), name);
294
291
        return(true);
297
294
        is_fifo = 1;
298
295
    }
299
296
    if ((file=my_open(name,O_RDONLY,MYF(MY_WME))) < 0)
300
 
    {
301
 
      my_error(ER_CANT_OPEN_FILE, MYF(0), my_errno);
302
297
      return(true);
303
 
    }
304
298
  }
305
299
 
306
300
  COPY_INFO info;
310
304
  info.escape_char=escaped->length() ? (*escaped)[0] : INT_MAX;
311
305
 
312
306
  READ_INFO read_info(file,tot_length,
313
 
                      ex->cs ? ex->cs : session->variables.collation_database,
 
307
                      ex->cs ? ex->cs : thd->variables.collation_database,
314
308
                      *field_term,*ex->line_start, *ex->line_term, *enclosed,
315
309
                      info.escape_char, read_file_from_client, is_fifo);
316
310
  if (read_info.error)
320
314
    return(true);                               // Can't allocate buffers
321
315
  }
322
316
 
323
 
  /*
324
 
   * Per the SQL standard, inserting NULL into a NOT NULL
325
 
   * field requires an error to be thrown.
326
 
   *
327
 
   * @NOTE
328
 
   *
329
 
   * NULL check and handling occurs in field_conv.cc
330
 
   */
331
 
  session->count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
332
 
  session->cuted_fields=0L;
 
317
  if (mysql_bin_log.is_open())
 
318
  {
 
319
    lf_info.thd = thd;
 
320
    lf_info.wrote_create_file = 0;
 
321
    lf_info.last_pos_in_file = HA_POS_ERROR;
 
322
    lf_info.log_delayed= transactional_table;
 
323
    read_info.set_io_cache_arg((void*) &lf_info);
 
324
  }
 
325
 
 
326
  thd->count_cuted_fields= CHECK_FIELD_WARN;            /* calc cuted fields */
 
327
  thd->cuted_fields=0L;
333
328
  /* Skip lines if there is a line terminator */
334
329
  if (ex->line_term->length())
335
330
  {
354
349
    table->file->ha_start_bulk_insert((ha_rows) 0);
355
350
    table->copy_blobs=1;
356
351
 
357
 
    session->abort_on_warning= true;
 
352
    thd->abort_on_warning= true;
358
353
 
359
354
    if (!field_term->length() && !enclosed->length())
360
 
      error= read_fixed_length(session, info, table_list, fields_vars,
 
355
      error= read_fixed_length(thd, info, table_list, fields_vars,
361
356
                               set_fields, set_values, read_info,
362
357
                               skip_lines, ignore);
363
358
    else
364
 
      error= read_sep_field(session, info, table_list, fields_vars,
 
359
      error= read_sep_field(thd, info, table_list, fields_vars,
365
360
                            set_fields, set_values, read_info,
366
361
                            *enclosed, skip_lines, ignore);
367
362
    if (table->file->ha_end_bulk_insert() && !error)
377
372
    my_close(file,MYF(0));
378
373
  free_blobs(table);                            /* if pack_blob was used */
379
374
  table->copy_blobs=0;
380
 
  session->count_cuted_fields= CHECK_FIELD_IGNORE;
381
 
  /*
 
375
  thd->count_cuted_fields= CHECK_FIELD_IGNORE;
 
376
  /* 
382
377
     simulated killing in the middle of per-row loop
383
378
     must be effective for binlogging
384
379
  */
385
 
  killed_status= (error == 0)? Session::NOT_KILLED : session->killed;
 
380
  killed_status= (error == 0)? THD::NOT_KILLED : thd->killed;
386
381
  if (error)
387
382
  {
388
383
    if (read_file_from_client)
389
384
      while (!read_info.next_line())
390
385
        ;
391
386
 
 
387
    if (mysql_bin_log.is_open())
 
388
    {
 
389
      {
 
390
        /*
 
391
          Make sure last block (the one which caused the error) gets
 
392
          logged.  This is needed because otherwise after write of (to
 
393
          the binlog, not to read_info (which is a cache))
 
394
          Delete_file_log_event the bad block will remain in read_info
 
395
          (because pre_read is not called at the end of the last
 
396
          block; remember pre_read is called whenever a new block is
 
397
          read from disk).  At the end of mysql_load(), the destructor
 
398
          of read_info will call end_io_cache() which will flush
 
399
          read_info, so we will finally have this in the binlog:
 
400
 
 
401
          Append_block # The last successfull block
 
402
          Delete_file
 
403
          Append_block # The failing block
 
404
          which is nonsense.
 
405
          Or could also be (for a small file)
 
406
          Create_file  # The failing block
 
407
          which is nonsense (Delete_file is not written in this case, because:
 
408
          Create_file has not been written, so Delete_file is not written, then
 
409
          when read_info is destroyed end_io_cache() is called which writes
 
410
          Create_file.
 
411
        */
 
412
        read_info.end_io_cache();
 
413
        /* If the file was not empty, wrote_create_file is true */
 
414
        if (lf_info.wrote_create_file)
 
415
        {
 
416
          if (thd->transaction.stmt.modified_non_trans_table)
 
417
            write_execute_load_query_log_event(thd, handle_duplicates,
 
418
                                               ignore, transactional_table,
 
419
                                               killed_status);
 
420
          else
 
421
          {
 
422
            Delete_file_log_event d(thd, db, transactional_table);
 
423
            d.flags|= LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F;
 
424
            mysql_bin_log.write(&d);
 
425
          }
 
426
        }
 
427
      }
 
428
    }
392
429
    error= -1;                          // Error on read
393
430
    goto err;
394
431
  }
395
432
  sprintf(name, ER(ER_LOAD_INFO), (uint32_t) info.records, (uint32_t) info.deleted,
396
 
          (uint32_t) (info.records - info.copied), (uint32_t) session->cuted_fields);
397
 
 
398
 
  if (session->transaction.stmt.modified_non_trans_table)
399
 
    session->transaction.all.modified_non_trans_table= true;
 
433
          (uint32_t) (info.records - info.copied), (uint32_t) thd->cuted_fields);
 
434
 
 
435
  if (thd->transaction.stmt.modified_non_trans_table)
 
436
    thd->transaction.all.modified_non_trans_table= true;
 
437
 
 
438
  if (mysql_bin_log.is_open())
 
439
  {
 
440
    /*
 
441
      We need to do the job that is normally done inside
 
442
      binlog_query() here, which is to ensure that the pending event
 
443
      is written before tables are unlocked and before any other
 
444
      events are written.  We also need to update the table map
 
445
      version for the binary log to mark that table maps are invalid
 
446
      after this point.
 
447
     */
 
448
    if (thd->current_stmt_binlog_row_based)
 
449
      thd->binlog_flush_pending_rows_event(true);
 
450
    else
 
451
    {
 
452
      /*
 
453
        As already explained above, we need to call end_io_cache() or the last
 
454
        block will be logged only after Execute_load_query_log_event (which is
 
455
        wrong), when read_info is destroyed.
 
456
      */
 
457
      read_info.end_io_cache();
 
458
      if (lf_info.wrote_create_file)
 
459
      {
 
460
        write_execute_load_query_log_event(thd, handle_duplicates, ignore,
 
461
                                           transactional_table,killed_status);
 
462
      }
 
463
    }
 
464
  }
400
465
 
401
466
  /* ok to client sent only after binlog write and engine commit */
402
 
  session->my_ok(info.copied + info.deleted, 0L, name);
 
467
  my_ok(thd, info.copied + info.deleted, 0L, name);
403
468
err:
404
469
  assert(transactional_table || !(info.copied || info.deleted) ||
405
 
              session->transaction.stmt.modified_non_trans_table);
 
470
              thd->transaction.stmt.modified_non_trans_table);
406
471
  table->file->ha_release_auto_increment();
407
472
  table->auto_increment_field_not_null= false;
408
 
  session->abort_on_warning= 0;
 
473
  thd->abort_on_warning= 0;
409
474
  return(error);
410
475
}
411
476
 
412
477
 
 
478
/* Not a very useful function; just to avoid duplication of code */
 
479
static bool write_execute_load_query_log_event(THD *thd,
 
480
                                               bool duplicates, bool ignore,
 
481
                                               bool transactional_table,
 
482
                                               THD::killed_state killed_err_arg)
 
483
{
 
484
  Execute_load_query_log_event
 
485
    e(thd, thd->query, thd->query_length,
 
486
      (char*)thd->lex->fname_start - (char*)thd->query,
 
487
      (char*)thd->lex->fname_end - (char*)thd->query,
 
488
      (duplicates == DUP_REPLACE) ? LOAD_DUP_REPLACE :
 
489
      (ignore ? LOAD_DUP_IGNORE : LOAD_DUP_ERROR),
 
490
      transactional_table, false, killed_err_arg);
 
491
  e.flags|= LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F;
 
492
  return mysql_bin_log.write(&e);
 
493
}
 
494
 
 
495
 
413
496
/****************************************************************************
414
497
** Read of rows of fixed size + optional garage + optonal newline
415
498
****************************************************************************/
416
499
 
417
500
static int
418
 
read_fixed_length(Session *session, COPY_INFO &info, TableList *table_list,
 
501
read_fixed_length(THD *thd, COPY_INFO &info, TableList *table_list,
419
502
                  List<Item> &fields_vars, List<Item> &set_fields,
420
503
                  List<Item> &set_values, READ_INFO &read_info,
421
504
                  uint32_t skip_lines, bool ignore_check_option_errors)
427
510
  bool err;
428
511
 
429
512
  id= 0;
430
 
 
 
513
 
431
514
  while (!read_info.read_fixed_length())
432
515
  {
433
 
    if (session->killed)
 
516
    if (thd->killed)
434
517
    {
435
 
      session->send_kill_message();
 
518
      thd->send_kill_message();
436
519
      return(1);
437
520
    }
438
521
    if (skip_lines)
459
542
    */
460
543
    while ((sql_field= (Item_field*) it++))
461
544
    {
462
 
      Field *field= sql_field->field;
 
545
      Field *field= sql_field->field;                  
463
546
      if (field == table->next_number_field)
464
547
        table->auto_increment_field_not_null= true;
465
548
      /*
471
554
 
472
555
      if (pos == read_info.row_end)
473
556
      {
474
 
        session->cuted_fields++;                        /* Not enough fields */
475
 
        push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
476
 
                            ER_WARN_TOO_FEW_RECORDS,
477
 
                            ER(ER_WARN_TOO_FEW_RECORDS), session->row_count);
 
557
        thd->cuted_fields++;                    /* Not enough fields */
 
558
        push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 
 
559
                            ER_WARN_TOO_FEW_RECORDS, 
 
560
                            ER(ER_WARN_TOO_FEW_RECORDS), thd->row_count);
478
561
        if (!field->maybe_null() && field->type() == DRIZZLE_TYPE_TIMESTAMP)
479
562
            ((Field_timestamp*) field)->set_time();
480
563
      }
494
577
    }
495
578
    if (pos != read_info.row_end)
496
579
    {
497
 
      session->cuted_fields++;                  /* To long row */
498
 
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
499
 
                          ER_WARN_TOO_MANY_RECORDS,
500
 
                          ER(ER_WARN_TOO_MANY_RECORDS), session->row_count);
 
580
      thd->cuted_fields++;                      /* To long row */
 
581
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 
 
582
                          ER_WARN_TOO_MANY_RECORDS, 
 
583
                          ER(ER_WARN_TOO_MANY_RECORDS), thd->row_count); 
501
584
    }
502
585
 
503
 
    if (session->killed ||
504
 
        fill_record(session, set_fields, set_values,
 
586
    if (thd->killed ||
 
587
        fill_record(thd, set_fields, set_values,
505
588
                    ignore_check_option_errors))
506
589
      return(1);
507
590
 
508
 
    err= write_record(session, table, &info);
 
591
    err= write_record(thd, table, &info);
509
592
    table->auto_increment_field_not_null= false;
510
593
    if (err)
511
594
      return(1);
512
 
 
 
595
   
513
596
    /*
514
597
      We don't need to reset auto-increment field since we are restoring
515
598
      its default value at the beginning of each loop iteration.
518
601
      break;
519
602
    if (read_info.line_cuted)
520
603
    {
521
 
      session->cuted_fields++;                  /* To long row */
522
 
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
523
 
                          ER_WARN_TOO_MANY_RECORDS,
524
 
                          ER(ER_WARN_TOO_MANY_RECORDS), session->row_count);
 
604
      thd->cuted_fields++;                      /* To long row */
 
605
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 
 
606
                          ER_WARN_TOO_MANY_RECORDS, 
 
607
                          ER(ER_WARN_TOO_MANY_RECORDS), thd->row_count); 
525
608
    }
526
 
    session->row_count++;
 
609
    thd->row_count++;
527
610
  }
528
611
  return(test(read_info.error));
529
612
}
531
614
 
532
615
 
533
616
static int
534
 
read_sep_field(Session *session, COPY_INFO &info, TableList *table_list,
 
617
read_sep_field(THD *thd, COPY_INFO &info, TableList *table_list,
535
618
               List<Item> &fields_vars, List<Item> &set_fields,
536
619
               List<Item> &set_values, READ_INFO &read_info,
537
620
               String &enclosed, uint32_t skip_lines,
549
632
 
550
633
  for (;;it.rewind())
551
634
  {
552
 
    if (session->killed)
 
635
    if (thd->killed)
553
636
    {
554
 
      session->send_kill_message();
 
637
      thd->send_kill_message();
555
638
      return(1);
556
639
    }
557
640
 
585
668
          if (field->reset())
586
669
          {
587
670
            my_error(ER_WARN_NULL_TO_NOTNULL, MYF(0), field->field_name,
588
 
                     session->row_count);
 
671
                     thd->row_count);
589
672
            return(1);
590
673
          }
591
674
          field->set_null();
653
736
          if (field->reset())
654
737
          {
655
738
            my_error(ER_WARN_NULL_TO_NOTNULL, MYF(0),field->field_name,
656
 
                     session->row_count);
 
739
                     thd->row_count);
657
740
            return(1);
658
741
          }
659
742
          if (!field->maybe_null() && field->type() == DRIZZLE_TYPE_TIMESTAMP)
661
744
          /*
662
745
            QQ: We probably should not throw warning for each field.
663
746
            But how about intention to always have the same number
664
 
            of warnings in Session::cuted_fields (and get rid of cuted_fields
 
747
            of warnings in THD::cuted_fields (and get rid of cuted_fields
665
748
            in the end ?)
666
749
          */
667
 
          session->cuted_fields++;
668
 
          push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
750
          thd->cuted_fields++;
 
751
          push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
669
752
                              ER_WARN_TOO_FEW_RECORDS,
670
 
                              ER(ER_WARN_TOO_FEW_RECORDS), session->row_count);
 
753
                              ER(ER_WARN_TOO_FEW_RECORDS), thd->row_count);
671
754
        }
672
755
        else if (item->type() == Item::STRING_ITEM)
673
756
        {
682
765
      }
683
766
    }
684
767
 
685
 
    if (session->killed ||
686
 
        fill_record(session, set_fields, set_values,
 
768
    if (thd->killed ||
 
769
        fill_record(thd, set_fields, set_values,
687
770
                    ignore_check_option_errors))
688
771
      return(1);
689
772
 
690
 
    err= write_record(session, table, &info);
 
773
    err= write_record(thd, table, &info);
691
774
    table->auto_increment_field_not_null= false;
692
775
    if (err)
693
776
      return(1);
699
782
      break;
700
783
    if (read_info.line_cuted)
701
784
    {
702
 
      session->cuted_fields++;                  /* To long row */
703
 
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
704
 
                          ER_WARN_TOO_MANY_RECORDS, ER(ER_WARN_TOO_MANY_RECORDS),
705
 
                          session->row_count);
706
 
      if (session->killed)
 
785
      thd->cuted_fields++;                      /* To long row */
 
786
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, 
 
787
                          ER_WARN_TOO_MANY_RECORDS, ER(ER_WARN_TOO_MANY_RECORDS), 
 
788
                          thd->row_count);   
 
789
      if (thd->killed)
707
790
        return(1);
708
791
    }
709
 
    session->row_count++;
 
792
    thd->row_count++;
710
793
  }
711
794
  return(test(read_info.error));
712
795
}
781
864
  set_if_bigger(length,line_start.length());
782
865
  stack=stack_pos=(int*) sql_alloc(sizeof(int)*length);
783
866
 
784
 
  if (!(buffer=(unsigned char*) malloc(buff_length+1)))
 
867
  if (!(buffer=(unsigned char*) my_malloc(buff_length+1,MYF(0))))
785
868
    error=1; /* purecov: inspected */
786
869
  else
787
870
  {
805
888
 
806
889
      if (get_it_from_net)
807
890
        cache.read_function = _my_b_net_read;
 
891
 
 
892
      if (mysql_bin_log.is_open())
 
893
        cache.pre_read = cache.pre_close =
 
894
          (IO_CACHE_CALLBACK) log_loaded_block;
808
895
    }
809
896
  }
810
897
}
995
1082
    /*
996
1083
    ** We come here if buffer is too small. Enlarge it and continue
997
1084
    */
998
 
    if (!(new_buffer=(unsigned char*) realloc(buffer, buff_length+1+IO_SIZE)))
 
1085
    if (!(new_buffer=(unsigned char*) my_realloc((char*) buffer,buff_length+1+IO_SIZE,
 
1086
                                        MYF(MY_WME))))
999
1087
      return (error=1);
1000
1088
    to=new_buffer + (to-buffer);
1001
1089
    buffer=new_buffer;