~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_load.cc

  • Committer: Brian Aker
  • Date: 2010-10-20 20:25:52 UTC
  • mto: (1864.2.1 merge)
  • mto: This revision was merged to the branch mainline in revision 1865.
  • Revision ID: brian@tangent.org-20101020202552-51y5sz5ledoxbp7t
Add support for --with-valgrind

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
16
 
17
17
/* Copy data from a textfile to table */
31
31
#include <fcntl.h>
32
32
#include <algorithm>
33
33
#include <climits>
 
34
#include <boost/filesystem.hpp>
34
35
 
 
36
namespace fs=boost::filesystem;
35
37
using namespace std;
36
38
namespace drizzled
37
39
{
85
87
  void set_io_cache_arg(void* arg) { cache.arg = arg; }
86
88
};
87
89
 
88
 
static int read_fixed_length(Session *session, COPY_INFO &info, TableList *table_list,
 
90
static int read_fixed_length(Session *session, CopyInfo &info, TableList *table_list,
89
91
                             List<Item> &fields_vars, List<Item> &set_fields,
90
92
                             List<Item> &set_values, READ_INFO &read_info,
91
93
                             uint32_t skip_lines,
92
94
                             bool ignore_check_option_errors);
93
 
static int read_sep_field(Session *session, COPY_INFO &info, TableList *table_list,
 
95
static int read_sep_field(Session *session, CopyInfo &info, TableList *table_list,
94
96
                          List<Item> &fields_vars, List<Item> &set_fields,
95
97
                          List<Item> &set_values, READ_INFO &read_info,
96
98
                          String &enclosed, uint32_t skip_lines,
122
124
                List<Item> &set_values,
123
125
                enum enum_duplicates handle_duplicates, bool ignore)
124
126
{
125
 
  char name[FN_REFLEN];
126
127
  int file;
127
128
  Table *table= NULL;
128
129
  int error;
178
179
  if (!fields_vars.elements)
179
180
  {
180
181
    Field **field;
181
 
    for (field=table->field; *field ; field++)
 
182
    for (field= table->getFields(); *field ; field++)
182
183
      fields_vars.push_back(new Item_field(*field));
183
184
    table->setWriteSet();
184
185
    table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
252
253
    return(true);
253
254
  }
254
255
 
255
 
  {
256
 
#ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS
257
 
    ex->file_name+=dirname_length(ex->file_name);
258
 
#endif
259
 
    if (!internal::dirname_length(ex->file_name))
260
 
    {
261
 
      strcpy(name, drizzle_real_data_home);
262
 
      strncat(name, tdb, FN_REFLEN-strlen(drizzle_real_data_home)-1);
263
 
      (void) internal::fn_format(name, ex->file_name, name, "",
264
 
                       MY_RELATIVE_PATH | MY_UNPACK_FILENAME);
265
 
    }
266
 
    else
267
 
    {
268
 
      (void) internal::fn_format(name, ex->file_name, drizzle_real_data_home, "",
269
 
                       MY_RELATIVE_PATH | MY_UNPACK_FILENAME);
270
 
 
271
 
      if (opt_secure_file_priv &&
272
 
          strncmp(opt_secure_file_priv, name, strlen(opt_secure_file_priv)))
273
 
      {
274
 
        /* Read only allowed from within dir specified by secure_file_priv */
275
 
        my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");
276
 
        return(true);
277
 
      }
278
 
 
279
 
      struct stat stat_info;
280
 
      if (stat(name,&stat_info))
281
 
      {
282
 
        my_error(ER_FILE_NOT_FOUND, MYF(0), name, errno);
283
 
        return(true);
284
 
      }
285
 
 
286
 
      // if we are not in slave thread, the cursor must be:
287
 
      if (!((stat_info.st_mode & S_IROTH) == S_IROTH &&  // readable by others
288
 
            (stat_info.st_mode & S_IFLNK) != S_IFLNK && // and not a symlink
289
 
            ((stat_info.st_mode & S_IFREG) == S_IFREG ||
290
 
             (stat_info.st_mode & S_IFIFO) == S_IFIFO)))
291
 
      {
292
 
        my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), name);
293
 
        return(true);
294
 
      }
295
 
      if ((stat_info.st_mode & S_IFIFO) == S_IFIFO)
296
 
        is_fifo = 1;
297
 
    }
298
 
    if ((file=internal::my_open(name,O_RDONLY,MYF(MY_WME))) < 0)
299
 
    {
300
 
      my_error(ER_CANT_OPEN_FILE, MYF(0), name, errno);
 
256
  fs::path to_file(ex->file_name);
 
257
  fs::path target_path(fs::system_complete(getDataHomeCatalog()));
 
258
  if (not to_file.has_root_directory())
 
259
  {
 
260
    int count_elements= 0;
 
261
    for (fs::path::iterator iter= to_file.begin();
 
262
         iter != to_file.end();
 
263
         ++iter, ++count_elements)
 
264
    { }
 
265
 
 
266
    if (count_elements == 1)
 
267
    {
 
268
      target_path /= tdb;
 
269
    }
 
270
    target_path /= to_file;
 
271
  }
 
272
  else
 
273
  {
 
274
    target_path= to_file;
 
275
  }
 
276
 
 
277
  if (not secure_file_priv.string().empty())
 
278
  {
 
279
    if (target_path.file_string().substr(0, secure_file_priv.file_string().size()) != secure_file_priv.file_string())
 
280
    {
 
281
      /* Read only allowed from within dir specified by secure_file_priv */
 
282
      my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");
301
283
      return(true);
302
284
    }
303
285
  }
304
286
 
305
 
  COPY_INFO info;
 
287
  struct stat stat_info;
 
288
  if (stat(target_path.file_string().c_str(), &stat_info))
 
289
  {
 
290
    my_error(ER_FILE_NOT_FOUND, MYF(0), target_path.file_string().c_str(), errno);
 
291
    return(true);
 
292
  }
 
293
 
 
294
  // if we are not in slave thread, the cursor must be:
 
295
  if (!((stat_info.st_mode & S_IROTH) == S_IROTH &&  // readable by others
 
296
        (stat_info.st_mode & S_IFLNK) != S_IFLNK && // and not a symlink
 
297
        ((stat_info.st_mode & S_IFREG) == S_IFREG ||
 
298
         (stat_info.st_mode & S_IFIFO) == S_IFIFO)))
 
299
  {
 
300
    my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), target_path.file_string().c_str());
 
301
    return(true);
 
302
  }
 
303
  if ((stat_info.st_mode & S_IFIFO) == S_IFIFO)
 
304
    is_fifo = 1;
 
305
 
 
306
 
 
307
  if ((file=internal::my_open(target_path.file_string().c_str(), O_RDONLY,MYF(MY_WME))) < 0)
 
308
  {
 
309
    my_error(ER_CANT_OPEN_FILE, MYF(0), target_path.file_string().c_str(), errno);
 
310
    return(true);
 
311
  }
 
312
  CopyInfo info;
306
313
  memset(&info, 0, sizeof(info));
307
314
  info.ignore= ignore;
308
315
  info.handle_duplicates=handle_duplicates;
377
384
    internal::my_close(file,MYF(0));
378
385
  free_blobs(table);                            /* if pack_blob was used */
379
386
  table->copy_blobs=0;
380
 
  session->count_cuted_fields= CHECK_FIELD_IGNORE;
 
387
  session->count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
381
388
  /*
382
389
     simulated killing in the middle of per-row loop
383
390
     must be effective for binlogging
388
395
    error= -1;                          // Error on read
389
396
    goto err;
390
397
  }
391
 
  snprintf(name, sizeof(name), ER(ER_LOAD_INFO), (uint32_t) info.records, (uint32_t) info.deleted,
392
 
          (uint32_t) (info.records - info.copied), (uint32_t) session->cuted_fields);
 
398
 
 
399
  char msg[FN_REFLEN];
 
400
  snprintf(msg, sizeof(msg), ER(ER_LOAD_INFO), info.records, info.deleted,
 
401
           (info.records - info.copied), session->cuted_fields);
393
402
 
394
403
  if (session->transaction.stmt.hasModifiedNonTransData())
395
404
    session->transaction.all.markModifiedNonTransData();
396
405
 
397
406
  /* ok to client sent only after binlog write and engine commit */
398
 
  session->my_ok(info.copied + info.deleted, 0, 0L, name);
 
407
  session->my_ok(info.copied + info.deleted, 0, 0L, msg);
399
408
err:
400
409
  assert(transactional_table || !(info.copied || info.deleted) ||
401
410
              session->transaction.stmt.hasModifiedNonTransData());
411
420
****************************************************************************/
412
421
 
413
422
static int
414
 
read_fixed_length(Session *session, COPY_INFO &info, TableList *table_list,
 
423
read_fixed_length(Session *session, CopyInfo &info, TableList *table_list,
415
424
                  List<Item> &fields_vars, List<Item> &set_fields,
416
425
                  List<Item> &set_values, READ_INFO &read_info,
417
426
                  uint32_t skip_lines, bool ignore_check_option_errors)
444
453
    }
445
454
    it.rewind();
446
455
    unsigned char *pos=read_info.row_start;
447
 
#ifdef HAVE_purify
 
456
#ifdef HAVE_VALGRIND
448
457
    read_info.row_end[0]=0;
449
458
#endif
450
459
 
530
539
 
531
540
 
532
541
static int
533
 
read_sep_field(Session *session, COPY_INFO &info, TableList *table_list,
 
542
read_sep_field(Session *session, CopyInfo &info, TableList *table_list,
534
543
               List<Item> &fields_vars, List<Item> &set_fields,
535
544
               List<Item> &set_values, READ_INFO &read_info,
536
545
               String &enclosed, uint32_t skip_lines,
776
785
 
777
786
 
778
787
  /* Set of a stack for unget if long terminators */
779
 
  uint32_t length= max(field_term_length,line_term_length)+1;
780
 
  set_if_bigger(length,line_start.length());
 
788
  size_t length= max(field_term_length,line_term_length)+1;
 
789
  set_if_bigger(length, line_start.length());
781
790
  stack= stack_pos= (int*) memory::sql_alloc(sizeof(int)*length);
782
791
 
783
792
  if (!(buffer=(unsigned char*) calloc(1, buff_length+1)))