~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to drizzled/sql_load.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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,
178
180
  if (!fields_vars.elements)
179
181
  {
180
182
    Field **field;
181
 
    for (field=table->field; *field ; field++)
 
183
    for (field= table->getFields(); *field ; field++)
182
184
      fields_vars.push_back(new Item_field(*field));
183
185
    table->setWriteSet();
184
186
    table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
258
260
#endif
259
261
    if (!internal::dirname_length(ex->file_name))
260
262
    {
261
 
      strcpy(name, drizzle_real_data_home);
262
 
      strncat(name, tdb, FN_REFLEN-strlen(drizzle_real_data_home)-1);
 
263
      strcpy(name, getDataHomeCatalog().c_str());
 
264
      strncat(name, "/", 1);
 
265
      strncat(name, tdb, FN_REFLEN-getDataHomeCatalog().size());
263
266
      (void) internal::fn_format(name, ex->file_name, name, "",
264
267
                       MY_RELATIVE_PATH | MY_UNPACK_FILENAME);
265
268
    }
266
269
    else
267
270
    {
268
 
      (void) internal::fn_format(name, ex->file_name, drizzle_real_data_home, "",
 
271
      (void) internal::fn_format(name, ex->file_name, getDataHomeCatalog().c_str(), "",
269
272
                       MY_RELATIVE_PATH | MY_UNPACK_FILENAME);
270
273
 
271
 
      if (opt_secure_file_priv &&
272
 
          strncmp(opt_secure_file_priv, name, strlen(opt_secure_file_priv)))
 
274
      if (opt_secure_file_priv)
273
275
      {
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);
 
276
        fs::path secure_file_path(fs::system_complete(fs::path(opt_secure_file_priv)));
 
277
        fs::path target_path(fs::system_complete(fs::path(name)));
 
278
        if (target_path.file_string().substr(0, secure_file_path.file_string().size()) != secure_file_path.file_string())
 
279
        {
 
280
          /* Read only allowed from within dir specified by secure_file_priv */
 
281
          my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");
 
282
          return(true);
 
283
        }
277
284
      }
278
285
 
279
286
      struct stat stat_info;
302
309
    }
303
310
  }
304
311
 
305
 
  COPY_INFO info;
 
312
  CopyInfo info;
306
313
  memset(&info, 0, sizeof(info));
307
314
  info.ignore= ignore;
308
315
  info.handle_duplicates=handle_duplicates;
309
316
  info.escape_char=escaped->length() ? (*escaped)[0] : INT_MAX;
310
317
 
 
318
  SchemaIdentifier identifier(session->db);
311
319
  READ_INFO read_info(file, tot_length,
312
 
                      ex->cs ? ex->cs : plugin::StorageEngine::getSchemaCollation(session->db.c_str()),
313
 
                      *field_term,*ex->line_start, *ex->line_term, *enclosed,
 
320
                      ex->cs ? ex->cs : plugin::StorageEngine::getSchemaCollation(identifier),
 
321
                      *field_term, *ex->line_start, *ex->line_term, *enclosed,
314
322
                      info.escape_char, is_fifo);
315
323
  if (read_info.error)
316
324
  {
376
384
    internal::my_close(file,MYF(0));
377
385
  free_blobs(table);                            /* if pack_blob was used */
378
386
  table->copy_blobs=0;
379
 
  session->count_cuted_fields= CHECK_FIELD_IGNORE;
 
387
  session->count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
380
388
  /*
381
389
     simulated killing in the middle of per-row loop
382
390
     must be effective for binlogging
387
395
    error= -1;                          // Error on read
388
396
    goto err;
389
397
  }
390
 
  sprintf(name, ER(ER_LOAD_INFO), (uint32_t) info.records, (uint32_t) info.deleted,
391
 
          (uint32_t) (info.records - info.copied), (uint32_t) session->cuted_fields);
 
398
  snprintf(name, sizeof(name), ER(ER_LOAD_INFO), info.records, info.deleted,
 
399
           (info.records - info.copied), session->cuted_fields);
392
400
 
393
401
  if (session->transaction.stmt.hasModifiedNonTransData())
394
402
    session->transaction.all.markModifiedNonTransData();
410
418
****************************************************************************/
411
419
 
412
420
static int
413
 
read_fixed_length(Session *session, COPY_INFO &info, TableList *table_list,
 
421
read_fixed_length(Session *session, CopyInfo &info, TableList *table_list,
414
422
                  List<Item> &fields_vars, List<Item> &set_fields,
415
423
                  List<Item> &set_values, READ_INFO &read_info,
416
424
                  uint32_t skip_lines, bool ignore_check_option_errors)
529
537
 
530
538
 
531
539
static int
532
 
read_sep_field(Session *session, COPY_INFO &info, TableList *table_list,
 
540
read_sep_field(Session *session, CopyInfo &info, TableList *table_list,
533
541
               List<Item> &fields_vars, List<Item> &set_fields,
534
542
               List<Item> &set_values, READ_INFO &read_info,
535
543
               String &enclosed, uint32_t skip_lines,