~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_load.cc

  • Committer: Brian Aker
  • Date: 2010-12-24 21:27:54 UTC
  • mto: (2035.1.1 clean)
  • mto: This revision was merged to the branch mainline in revision 2037.
  • Revision ID: brian@tangent.org-20101224212754-85xvjullymvhibr9
Merge in cast() for BOOLEAN.

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>
20
 
 
 
19
#include "config.h"
21
20
#include <drizzled/sql_load.h>
22
21
#include <drizzled/error.h>
23
22
#include <drizzled/data_home.h>
24
23
#include <drizzled/session.h>
25
24
#include <drizzled/sql_base.h>
26
25
#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>
 
26
#include "drizzled/internal/my_sys.h"
 
27
#include "drizzled/internal/iocache.h"
 
28
#include <drizzled/db.h>
30
29
 
31
30
#include <sys/stat.h>
32
31
#include <fcntl.h>
82
81
 
83
82
  /*
84
83
    Either this method, or we need to make cache public
85
 
    Arg must be set from load() since constructor does not see
 
84
    Arg must be set from mysql_load() since constructor does not see
86
85
    either the table or Session value
87
86
  */
88
87
  void set_io_cache_arg(void* arg) { cache.arg = arg; }
104
103
  Execute LOAD DATA query
105
104
 
106
105
  SYNOPSYS
107
 
    load()
 
106
    mysql_load()
108
107
      session - current thread
109
108
      ex  - file_exchange object representing source cursor and its parsing rules
110
109
      table_list  - list of tables to which we are loading data
120
119
    true - error / false - success
121
120
*/
122
121
 
123
 
int load(Session *session,file_exchange *ex,TableList *table_list,
 
122
int mysql_load(Session *session,file_exchange *ex,TableList *table_list,
124
123
                List<Item> &fields_vars, List<Item> &set_fields,
125
124
                List<Item> &set_values,
126
125
                enum enum_duplicates handle_duplicates, bool ignore)
156
155
  if (session->openTablesLock(table_list))
157
156
    return(true);
158
157
 
159
 
  if (setup_tables_and_check_access(session, &session->getLex()->select_lex.context,
160
 
                                    &session->getLex()->select_lex.top_join_list,
 
158
  if (setup_tables_and_check_access(session, &session->lex->select_lex.context,
 
159
                                    &session->lex->select_lex.top_join_list,
161
160
                                    table_list,
162
 
                                    &session->getLex()->select_lex.leaf_tables, true))
 
161
                                    &session->lex->select_lex.leaf_tables, true))
163
162
     return(-1);
164
163
 
165
164
  /*
225
224
 
226
225
  size_t tot_length=0;
227
226
  bool use_blobs= 0, use_vars= 0;
228
 
  List<Item>::iterator it(fields_vars.begin());
 
227
  List_iterator_fast<Item> it(fields_vars);
229
228
  Item *item;
230
229
 
231
230
  while ((item= it++))
320
319
  info.handle_duplicates=handle_duplicates;
321
320
  info.escape_char=escaped->length() ? (*escaped)[0] : INT_MAX;
322
321
 
323
 
  identifier::Schema identifier(*schema);
 
322
  SchemaIdentifier identifier(*schema);
324
323
  READ_INFO read_info(file, tot_length,
325
324
                      ex->cs ? ex->cs : plugin::StorageEngine::getSchemaCollation(identifier),
326
325
                      *field_term, *ex->line_start, *ex->line_term, *enclosed,
366
365
    table->cursor->ha_start_bulk_insert((ha_rows) 0);
367
366
    table->copy_blobs=1;
368
367
 
369
 
    session->setAbortOnWarning(true);
 
368
    session->abort_on_warning= true;
370
369
 
371
370
    if (!field_term->length() && !enclosed->length())
372
371
      error= read_fixed_length(session, info, table_list, fields_vars,
415
414
              session->transaction.stmt.hasModifiedNonTransData());
416
415
  table->cursor->ha_release_auto_increment();
417
416
  table->auto_increment_field_not_null= false;
418
 
  session->setAbortOnWarning(false);
419
 
 
 
417
  session->abort_on_warning= 0;
420
418
  return(error);
421
419
}
422
420
 
431
429
                  List<Item> &set_values, READ_INFO &read_info,
432
430
                  uint32_t skip_lines, bool ignore_check_option_errors)
433
431
{
434
 
  List<Item>::iterator it(fields_vars.begin());
 
432
  List_iterator_fast<Item> it(fields_vars);
435
433
  Item_field *sql_field;
436
434
  Table *table= table_list->table;
437
435
  uint64_t id;
457
455
      skip_lines--;
458
456
      continue;
459
457
    }
460
 
    it= fields_vars.begin();
 
458
    it.rewind();
461
459
    unsigned char *pos=read_info.row_start;
462
460
#ifdef HAVE_VALGRIND
463
461
    read_info.row_end[0]=0;
487
485
                            ER_WARN_TOO_FEW_RECORDS,
488
486
                            ER(ER_WARN_TOO_FEW_RECORDS), session->row_count);
489
487
 
490
 
        if (not field->maybe_null() and field->is_timestamp())
 
488
        if (!field->maybe_null() && field->type() == DRIZZLE_TYPE_TIMESTAMP)
491
489
            ((field::Epoch::pointer) field)->set_time();
492
490
      }
493
491
      else
552
550
               String &enclosed, uint32_t skip_lines,
553
551
               bool ignore_check_option_errors)
554
552
{
555
 
  List<Item>::iterator it(fields_vars.begin());
 
553
  List_iterator_fast<Item> it(fields_vars);
556
554
  Item *item;
557
555
  Table *table= table_list->table;
558
556
  uint32_t enclosed_length;
562
560
  enclosed_length=enclosed.length();
563
561
  id= 0;
564
562
 
565
 
  for (;;it= fields_vars.begin())
 
563
  for (;;it.rewind())
566
564
  {
567
565
    if (session->getKilled())
568
566
    {
604
602
            return(1);
605
603
          }
606
604
          field->set_null();
607
 
          if (not field->maybe_null())
 
605
          if (!field->maybe_null())
608
606
          {
609
 
            if (field->is_timestamp())
 
607
            if (field->type() == DRIZZLE_TYPE_TIMESTAMP)
610
608
            {
611
609
              ((field::Epoch::pointer) field)->set_time();
612
610
            }
674
672
                     session->row_count);
675
673
            return(1);
676
674
          }
677
 
          if (not field->maybe_null() and field->is_timestamp())
 
675
          if (!field->maybe_null() && field->type() == DRIZZLE_TYPE_TIMESTAMP)
678
676
              ((field::Epoch::pointer) field)->set_time();
679
677
          /*
680
678
            QQ: We probably should not throw warning for each field.