~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_load.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
/* Copy data from a textfile to table */
18
18
 
19
 
#include "config.h"
 
19
#include <config.h>
 
20
 
20
21
#include <drizzled/sql_load.h>
21
22
#include <drizzled/error.h>
22
23
#include <drizzled/data_home.h>
23
24
#include <drizzled/session.h>
24
25
#include <drizzled/sql_base.h>
25
 
#include <drizzled/field/timestamp.h>
26
 
#include "drizzled/internal/my_sys.h"
27
 
#include "drizzled/internal/iocache.h"
28
 
#include <drizzled/db.h>
 
26
#include <drizzled/field/epoch.h>
 
27
#include <drizzled/internal/my_sys.h>
 
28
#include <drizzled/internal/iocache.h>
 
29
#include <drizzled/plugin/storage_engine.h>
29
30
 
30
31
#include <sys/stat.h>
31
32
#include <fcntl.h>
81
82
 
82
83
  /*
83
84
    Either this method, or we need to make cache public
84
 
    Arg must be set from mysql_load() since constructor does not see
 
85
    Arg must be set from load() since constructor does not see
85
86
    either the table or Session value
86
87
  */
87
88
  void set_io_cache_arg(void* arg) { cache.arg = arg; }
103
104
  Execute LOAD DATA query
104
105
 
105
106
  SYNOPSYS
106
 
    mysql_load()
 
107
    load()
107
108
      session - current thread
108
109
      ex  - file_exchange object representing source cursor and its parsing rules
109
110
      table_list  - list of tables to which we are loading data
119
120
    true - error / false - success
120
121
*/
121
122
 
122
 
int mysql_load(Session *session,file_exchange *ex,TableList *table_list,
 
123
int load(Session *session,file_exchange *ex,TableList *table_list,
123
124
                List<Item> &fields_vars, List<Item> &set_fields,
124
125
                List<Item> &set_values,
125
126
                enum enum_duplicates handle_duplicates, bool ignore)
155
156
  if (session->openTablesLock(table_list))
156
157
    return(true);
157
158
 
158
 
  if (setup_tables_and_check_access(session, &session->lex->select_lex.context,
159
 
                                    &session->lex->select_lex.top_join_list,
 
159
  if (setup_tables_and_check_access(session, &session->getLex()->select_lex.context,
 
160
                                    &session->getLex()->select_lex.top_join_list,
160
161
                                    table_list,
161
 
                                    &session->lex->select_lex.leaf_tables, true))
 
162
                                    &session->getLex()->select_lex.leaf_tables, true))
162
163
     return(-1);
163
164
 
164
165
  /*
206
207
    */
207
208
    if (table->timestamp_field)
208
209
    {
209
 
      if (table->isWriteSet(table->timestamp_field->field_index))
 
210
      if (table->isWriteSet(table->timestamp_field->position()))
 
211
      {
210
212
        table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
 
213
      }
211
214
      else
212
215
      {
213
 
        table->setWriteSet(table->timestamp_field->field_index);
 
216
        table->setWriteSet(table->timestamp_field->position());
214
217
      }
215
218
    }
216
219
    /* Fix the expressions in SET clause */
222
225
 
223
226
  size_t tot_length=0;
224
227
  bool use_blobs= 0, use_vars= 0;
225
 
  List_iterator_fast<Item> it(fields_vars);
 
228
  List<Item>::iterator it(fields_vars.begin());
226
229
  Item *item;
227
230
 
228
231
  while ((item= it++))
317
320
  info.handle_duplicates=handle_duplicates;
318
321
  info.escape_char=escaped->length() ? (*escaped)[0] : INT_MAX;
319
322
 
320
 
  SchemaIdentifier identifier(*schema);
 
323
  identifier::Schema identifier(*schema);
321
324
  READ_INFO read_info(file, tot_length,
322
325
                      ex->cs ? ex->cs : plugin::StorageEngine::getSchemaCollation(identifier),
323
326
                      *field_term, *ex->line_start, *ex->line_term, *enclosed,
363
366
    table->cursor->ha_start_bulk_insert((ha_rows) 0);
364
367
    table->copy_blobs=1;
365
368
 
366
 
    session->abort_on_warning= true;
 
369
    session->setAbortOnWarning(true);
367
370
 
368
371
    if (!field_term->length() && !enclosed->length())
369
372
      error= read_fixed_length(session, info, table_list, fields_vars,
412
415
              session->transaction.stmt.hasModifiedNonTransData());
413
416
  table->cursor->ha_release_auto_increment();
414
417
  table->auto_increment_field_not_null= false;
415
 
  session->abort_on_warning= 0;
 
418
  session->setAbortOnWarning(false);
 
419
 
416
420
  return(error);
417
421
}
418
422
 
427
431
                  List<Item> &set_values, READ_INFO &read_info,
428
432
                  uint32_t skip_lines, bool ignore_check_option_errors)
429
433
{
430
 
  List_iterator_fast<Item> it(fields_vars);
 
434
  List<Item>::iterator it(fields_vars.begin());
431
435
  Item_field *sql_field;
432
436
  Table *table= table_list->table;
433
437
  uint64_t id;
453
457
      skip_lines--;
454
458
      continue;
455
459
    }
456
 
    it.rewind();
 
460
    it= fields_vars.begin();
457
461
    unsigned char *pos=read_info.row_start;
458
462
#ifdef HAVE_VALGRIND
459
463
    read_info.row_end[0]=0;
482
486
        push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
483
487
                            ER_WARN_TOO_FEW_RECORDS,
484
488
                            ER(ER_WARN_TOO_FEW_RECORDS), session->row_count);
485
 
        if (!field->maybe_null() && field->type() == DRIZZLE_TYPE_TIMESTAMP)
486
 
            ((Field_timestamp*) field)->set_time();
 
489
 
 
490
        if (not field->maybe_null() and field->is_timestamp())
 
491
            ((field::Epoch::pointer) field)->set_time();
487
492
      }
488
493
      else
489
494
      {
547
552
               String &enclosed, uint32_t skip_lines,
548
553
               bool ignore_check_option_errors)
549
554
{
550
 
  List_iterator_fast<Item> it(fields_vars);
 
555
  List<Item>::iterator it(fields_vars.begin());
551
556
  Item *item;
552
557
  Table *table= table_list->table;
553
558
  uint32_t enclosed_length;
557
562
  enclosed_length=enclosed.length();
558
563
  id= 0;
559
564
 
560
 
  for (;;it.rewind())
 
565
  for (;;it= fields_vars.begin())
561
566
  {
562
567
    if (session->getKilled())
563
568
    {
599
604
            return(1);
600
605
          }
601
606
          field->set_null();
602
 
          if (!field->maybe_null())
 
607
          if (not field->maybe_null())
603
608
          {
604
 
            if (field->type() == DRIZZLE_TYPE_TIMESTAMP)
605
 
              ((Field_timestamp*) field)->set_time();
 
609
            if (field->is_timestamp())
 
610
            {
 
611
              ((field::Epoch::pointer) field)->set_time();
 
612
            }
606
613
            else if (field != table->next_number_field)
607
 
              field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
608
 
                                 ER_WARN_NULL_TO_NOTNULL, 1);
 
614
            {
 
615
              field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_NULL_TO_NOTNULL, 1);
 
616
            }
609
617
          }
610
618
        }
611
619
        else if (item->type() == Item::STRING_ITEM)
666
674
                     session->row_count);
667
675
            return(1);
668
676
          }
669
 
          if (!field->maybe_null() && field->type() == DRIZZLE_TYPE_TIMESTAMP)
670
 
              ((Field_timestamp*) field)->set_time();
 
677
          if (not field->maybe_null() and field->is_timestamp())
 
678
              ((field::Epoch::pointer) field)->set_time();
671
679
          /*
672
680
            QQ: We probably should not throw warning for each field.
673
681
            But how about intention to always have the same number