~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_load.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

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
21
#include <drizzled/sql_load.h>
22
22
#include <drizzled/error.h>
24
24
#include <drizzled/session.h>
25
25
#include <drizzled/sql_base.h>
26
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>
30
 
#include <drizzled/sql_lex.h>
31
 
#include <drizzled/copy_info.h>
32
 
#include <drizzled/file_exchange.h>
33
 
#include <drizzled/util/test.h>
34
 
#include <drizzled/session/transactions.h>
 
27
#include "drizzled/internal/my_sys.h"
 
28
#include "drizzled/internal/iocache.h"
 
29
#include <drizzled/db.h>
 
30
#include "drizzled/plugin/storage_engine.h"
35
31
 
36
32
#include <sys/stat.h>
37
33
#include <fcntl.h>
56
52
  int   *stack,*stack_pos;
57
53
  bool  found_end_of_line,start_of_line,eof;
58
54
  bool  need_end_io_cache;
59
 
  internal::io_cache_st cache;
 
55
  internal::IO_CACHE cache;
60
56
 
61
57
public:
62
58
  bool error,line_cuted,found_null,enclosed;
63
59
  unsigned char *row_start,                     /* Found row starts here */
64
60
        *row_end;                       /* Found row ends here */
65
 
  const charset_info_st *read_charset;
 
61
  const CHARSET_INFO *read_charset;
66
62
 
67
 
  READ_INFO(int cursor, size_t tot_length, const charset_info_st * const cs,
 
63
  READ_INFO(int cursor, size_t tot_length, const CHARSET_INFO * const cs,
68
64
            String &field_term,String &line_start,String &line_term,
69
65
            String &enclosed,int escape, bool is_fifo);
70
66
  ~READ_INFO();
144
140
    If this is not set, we will use the directory where the table to be
145
141
    loaded is located
146
142
  */
147
 
  util::string::ptr schema(session->schema());
 
143
  util::string::const_shared_ptr schema(session->schema());
148
144
  const char *tdb= (schema and not schema->empty()) ? schema->c_str() : table_list->getSchemaName(); // Result should never be null
149
145
  assert(tdb);
150
146
  uint32_t skip_lines= ex->skip_lines;
151
147
  bool transactional_table;
 
148
  Session::killed_state_t killed_status= Session::NOT_KILLED;
152
149
 
153
150
  /* Escape and enclosed character may be a utf8 4-byte character */
154
151
  if (escaped->length() > 4 || enclosed->length() > 4)
160
157
  if (session->openTablesLock(table_list))
161
158
    return(true);
162
159
 
163
 
  if (setup_tables_and_check_access(session, &session->lex().select_lex.context,
164
 
                                    &session->lex().select_lex.top_join_list,
 
160
  if (setup_tables_and_check_access(session, &session->lex->select_lex.context,
 
161
                                    &session->lex->select_lex.top_join_list,
165
162
                                    table_list,
166
 
                                    &session->lex().select_lex.leaf_tables, true))
 
163
                                    &session->lex->select_lex.leaf_tables, true))
167
164
     return(-1);
168
165
 
169
166
  /*
183
180
  table= table_list->table;
184
181
  transactional_table= table->cursor->has_transactions();
185
182
 
186
 
  if (!fields_vars.size())
 
183
  if (!fields_vars.elements)
187
184
  {
188
185
    Field **field;
189
186
    for (field= table->getFields(); *field ; field++)
229
226
 
230
227
  size_t tot_length=0;
231
228
  bool use_blobs= 0, use_vars= 0;
232
 
  List<Item>::iterator it(fields_vars.begin());
 
229
  List_iterator_fast<Item> it(fields_vars);
233
230
  Item *item;
234
231
 
235
232
  while ((item= it++))
398
395
     simulated killing in the middle of per-row loop
399
396
     must be effective for binlogging
400
397
  */
401
 
  if (error) 
 
398
  killed_status= (error == 0)? Session::NOT_KILLED : session->getKilled();
 
399
  if (error)
402
400
  {
403
401
    error= -1;                          // Error on read
404
402
    goto err;
434
432
                  List<Item> &set_values, READ_INFO &read_info,
435
433
                  uint32_t skip_lines, bool ignore_check_option_errors)
436
434
{
437
 
  List<Item>::iterator it(fields_vars.begin());
 
435
  List_iterator_fast<Item> it(fields_vars);
438
436
  Item_field *sql_field;
439
437
  Table *table= table_list->table;
 
438
  uint64_t id;
440
439
  bool err;
441
440
 
 
441
  id= 0;
 
442
 
442
443
  while (!read_info.read_fixed_length())
443
444
  {
444
445
    if (session->getKilled())
457
458
      skip_lines--;
458
459
      continue;
459
460
    }
460
 
    it= fields_vars.begin();
 
461
    it.rewind();
461
462
    unsigned char *pos=read_info.row_start;
462
463
#ifdef HAVE_VALGRIND
463
464
    read_info.row_end[0]=0;
552
553
               String &enclosed, uint32_t skip_lines,
553
554
               bool ignore_check_option_errors)
554
555
{
555
 
  List<Item>::iterator it(fields_vars.begin());
 
556
  List_iterator_fast<Item> it(fields_vars);
556
557
  Item *item;
557
558
  Table *table= table_list->table;
558
559
  uint32_t enclosed_length;
 
560
  uint64_t id;
559
561
  bool err;
560
562
 
561
563
  enclosed_length=enclosed.length();
 
564
  id= 0;
562
565
 
563
 
  for (;;it= fields_vars.begin())
 
566
  for (;;it.rewind())
564
567
  {
565
568
    if (session->getKilled())
566
569
    {
658
661
    if (item)
659
662
    {
660
663
      /* Have not read any field, thus input cursor is simply ended */
661
 
      if (item == &fields_vars.front())
 
664
      if (item == fields_vars.head())
662
665
        break;
663
666
      for (; item ; item= it++)
664
667
      {
756
759
 
757
760
 
758
761
READ_INFO::READ_INFO(int file_par, size_t tot_length,
759
 
                     const charset_info_st * const cs,
 
762
                     const CHARSET_INFO * const cs,
760
763
                     String &field_term, String &line_start, String &line_term,
761
764
                     String &enclosed_par, int escape, bool is_fifo)
762
765
  :cursor(file_par),escape_char(escape)