~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_load.cc

  • Committer: patrick crews
  • Date: 2011-02-23 17:17:25 UTC
  • mto: (2195.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2196.
  • Revision ID: gleebix@gmail.com-20110223171725-4tgewemxhsw1m7q8
Integrated randgen with dbqp.  We now have mode=randgen and a set of randgen test suites (very basic now).  Output = same as dtr : )  We also have mode=cleanup to kill any servers we have started.  Docs updates too.  Gendata utility allows us to populate test servers 

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
  /*
224
225
 
225
226
  size_t tot_length=0;
226
227
  bool use_blobs= 0, use_vars= 0;
227
 
  List_iterator_fast<Item> it(fields_vars);
 
228
  List<Item>::iterator it(fields_vars.begin());
228
229
  Item *item;
229
230
 
230
231
  while ((item= it++))
319
320
  info.handle_duplicates=handle_duplicates;
320
321
  info.escape_char=escaped->length() ? (*escaped)[0] : INT_MAX;
321
322
 
322
 
  SchemaIdentifier identifier(*schema);
 
323
  identifier::Schema identifier(*schema);
323
324
  READ_INFO read_info(file, tot_length,
324
325
                      ex->cs ? ex->cs : plugin::StorageEngine::getSchemaCollation(identifier),
325
326
                      *field_term, *ex->line_start, *ex->line_term, *enclosed,
365
366
    table->cursor->ha_start_bulk_insert((ha_rows) 0);
366
367
    table->copy_blobs=1;
367
368
 
368
 
    session->abort_on_warning= true;
 
369
    session->setAbortOnWarning(true);
369
370
 
370
371
    if (!field_term->length() && !enclosed->length())
371
372
      error= read_fixed_length(session, info, table_list, fields_vars,
414
415
              session->transaction.stmt.hasModifiedNonTransData());
415
416
  table->cursor->ha_release_auto_increment();
416
417
  table->auto_increment_field_not_null= false;
417
 
  session->abort_on_warning= 0;
 
418
  session->setAbortOnWarning(false);
 
419
 
418
420
  return(error);
419
421
}
420
422
 
429
431
                  List<Item> &set_values, READ_INFO &read_info,
430
432
                  uint32_t skip_lines, bool ignore_check_option_errors)
431
433
{
432
 
  List_iterator_fast<Item> it(fields_vars);
 
434
  List<Item>::iterator it(fields_vars.begin());
433
435
  Item_field *sql_field;
434
436
  Table *table= table_list->table;
435
437
  uint64_t id;
455
457
      skip_lines--;
456
458
      continue;
457
459
    }
458
 
    it.rewind();
 
460
    it= fields_vars.begin();
459
461
    unsigned char *pos=read_info.row_start;
460
462
#ifdef HAVE_VALGRIND
461
463
    read_info.row_end[0]=0;
484
486
        push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
485
487
                            ER_WARN_TOO_FEW_RECORDS,
486
488
                            ER(ER_WARN_TOO_FEW_RECORDS), session->row_count);
487
 
        if (!field->maybe_null() && field->type() == DRIZZLE_TYPE_TIMESTAMP)
488
 
            ((Field_timestamp*) field)->set_time();
 
489
 
 
490
        if (not field->maybe_null() and field->is_timestamp())
 
491
            ((field::Epoch::pointer) field)->set_time();
489
492
      }
490
493
      else
491
494
      {
549
552
               String &enclosed, uint32_t skip_lines,
550
553
               bool ignore_check_option_errors)
551
554
{
552
 
  List_iterator_fast<Item> it(fields_vars);
 
555
  List<Item>::iterator it(fields_vars.begin());
553
556
  Item *item;
554
557
  Table *table= table_list->table;
555
558
  uint32_t enclosed_length;
559
562
  enclosed_length=enclosed.length();
560
563
  id= 0;
561
564
 
562
 
  for (;;it.rewind())
 
565
  for (;;it= fields_vars.begin())
563
566
  {
564
567
    if (session->getKilled())
565
568
    {
601
604
            return(1);
602
605
          }
603
606
          field->set_null();
604
 
          if (!field->maybe_null())
 
607
          if (not field->maybe_null())
605
608
          {
606
 
            if (field->type() == DRIZZLE_TYPE_TIMESTAMP)
607
 
              ((Field_timestamp*) field)->set_time();
 
609
            if (field->is_timestamp())
 
610
            {
 
611
              ((field::Epoch::pointer) field)->set_time();
 
612
            }
608
613
            else if (field != table->next_number_field)
609
 
              field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
610
 
                                 ER_WARN_NULL_TO_NOTNULL, 1);
 
614
            {
 
615
              field->set_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_WARN_NULL_TO_NOTNULL, 1);
 
616
            }
611
617
          }
612
618
        }
613
619
        else if (item->type() == Item::STRING_ITEM)
668
674
                     session->row_count);
669
675
            return(1);
670
676
          }
671
 
          if (!field->maybe_null() && field->type() == DRIZZLE_TYPE_TIMESTAMP)
672
 
              ((Field_timestamp*) field)->set_time();
 
677
          if (not field->maybe_null() and field->is_timestamp())
 
678
              ((field::Epoch::pointer) field)->set_time();
673
679
          /*
674
680
            QQ: We probably should not throw warning for each field.
675
681
            But how about intention to always have the same number