87
84
void set_io_cache_arg(void* arg) { cache.arg = arg; }
90
static int read_fixed_length(Session *session, CopyInfo &info, TableList *table_list,
87
static int read_fixed_length(Session *session, COPY_INFO &info, TableList *table_list,
91
88
List<Item> &fields_vars, List<Item> &set_fields,
92
89
List<Item> &set_values, READ_INFO &read_info,
93
90
uint32_t skip_lines,
94
91
bool ignore_check_option_errors);
95
static int read_sep_field(Session *session, CopyInfo &info, TableList *table_list,
92
static int read_sep_field(Session *session, COPY_INFO &info, TableList *table_list,
96
93
List<Item> &fields_vars, List<Item> &set_fields,
97
94
List<Item> &set_values, READ_INFO &read_info,
98
95
String &enclosed, uint32_t skip_lines,
124
121
List<Item> &set_values,
125
122
enum enum_duplicates handle_duplicates, bool ignore)
124
char name[FN_REFLEN];
128
126
Table *table= NULL;
130
128
String *field_term=ex->field_term,*escaped=ex->escaped;
131
129
String *enclosed=ex->enclosed;
134
assert(table_list->getSchemaName()); // This should never be null
131
char *db= table_list->db; // This is never null
137
134
If path for cursor is not defined, we will use the current database.
138
135
If this is not set, we will use the directory where the table to be
139
136
loaded is located
141
util::string::const_shared_ptr schema(session->schema());
142
const char *tdb= (schema and not schema->empty()) ? schema->c_str() : table_list->getSchemaName(); // Result should never be null
138
const char *tdb= session->db.empty() ? db : session->db.c_str(); // Result is never null
144
140
uint32_t skip_lines= ex->skip_lines;
145
141
bool transactional_table;
146
Session::killed_state_t killed_status= Session::NOT_KILLED;
142
Session::killed_state killed_status= Session::NOT_KILLED;
148
144
/* Escape and enclosed character may be a utf8 4-byte character */
149
145
if (escaped->length() > 4 || enclosed->length() > 4)
260
fs::path to_file(ex->file_name);
261
fs::path target_path(fs::system_complete(getDataHomeCatalog()));
262
if (not to_file.has_root_directory())
264
int count_elements= 0;
265
for (fs::path::iterator iter= to_file.begin();
266
iter != to_file.end();
267
++iter, ++count_elements)
270
if (count_elements == 1)
274
target_path /= to_file;
278
target_path= to_file;
281
if (not secure_file_priv.string().empty())
283
if (target_path.file_string().substr(0, secure_file_priv.file_string().size()) != secure_file_priv.file_string())
285
/* Read only allowed from within dir specified by secure_file_priv */
286
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");
255
#ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS
256
ex->file_name+=dirname_length(ex->file_name);
258
if (!dirname_length(ex->file_name))
260
strcpy(name, drizzle_real_data_home);
261
strncat(name, tdb, FN_REFLEN-strlen(drizzle_real_data_home)-1);
262
(void) fn_format(name, ex->file_name, name, "",
263
MY_RELATIVE_PATH | MY_UNPACK_FILENAME);
267
(void) fn_format(name, ex->file_name, drizzle_real_data_home, "",
268
MY_RELATIVE_PATH | MY_UNPACK_FILENAME);
270
if (opt_secure_file_priv &&
271
strncmp(opt_secure_file_priv, name, strlen(opt_secure_file_priv)))
273
/* Read only allowed from within dir specified by secure_file_priv */
274
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");
278
struct stat stat_info;
279
if (stat(name,&stat_info))
281
my_error(ER_FILE_NOT_FOUND, MYF(0), name, errno);
285
// if we are not in slave thread, the cursor must be:
286
if (!((stat_info.st_mode & S_IROTH) == S_IROTH && // readable by others
287
(stat_info.st_mode & S_IFLNK) != S_IFLNK && // and not a symlink
288
((stat_info.st_mode & S_IFREG) == S_IFREG ||
289
(stat_info.st_mode & S_IFIFO) == S_IFIFO)))
291
my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), name);
294
if ((stat_info.st_mode & S_IFIFO) == S_IFIFO)
297
if ((file=my_open(name,O_RDONLY,MYF(MY_WME))) < 0)
299
my_error(ER_CANT_OPEN_FILE, MYF(0), name, errno);
291
struct stat stat_info;
292
if (stat(target_path.file_string().c_str(), &stat_info))
294
my_error(ER_FILE_NOT_FOUND, MYF(0), target_path.file_string().c_str(), errno);
298
// if we are not in slave thread, the cursor must be:
299
if (!((stat_info.st_mode & S_IROTH) == S_IROTH && // readable by others
300
(stat_info.st_mode & S_IFLNK) != S_IFLNK && // and not a symlink
301
((stat_info.st_mode & S_IFREG) == S_IFREG ||
302
(stat_info.st_mode & S_IFIFO) == S_IFIFO)))
304
my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), target_path.file_string().c_str());
307
if ((stat_info.st_mode & S_IFIFO) == S_IFIFO)
311
if ((file=internal::my_open(target_path.file_string().c_str(), O_RDONLY,MYF(MY_WME))) < 0)
313
my_error(ER_CANT_OPEN_FILE, MYF(0), target_path.file_string().c_str(), errno);
317
305
memset(&info, 0, sizeof(info));
318
306
info.ignore= ignore;
319
307
info.handle_duplicates=handle_duplicates;
320
308
info.escape_char=escaped->length() ? (*escaped)[0] : INT_MAX;
322
SchemaIdentifier identifier(*schema);
323
310
READ_INFO read_info(file, tot_length,
324
ex->cs ? ex->cs : plugin::StorageEngine::getSchemaCollation(identifier),
325
*field_term, *ex->line_start, *ex->line_term, *enclosed,
311
ex->cs ? ex->cs : get_default_db_collation(session->db.c_str()),
312
*field_term,*ex->line_start, *ex->line_term, *enclosed,
326
313
info.escape_char, is_fifo);
327
314
if (read_info.error)
330
internal::my_close(file,MYF(0)); // no files in net reading
317
my_close(file,MYF(0)); // no files in net reading
331
318
return(true); // Can't allocate buffers
385
372
table->next_number_field=0;
388
internal::my_close(file,MYF(0));
375
my_close(file,MYF(0));
389
376
free_blobs(table); /* if pack_blob was used */
390
377
table->copy_blobs=0;
391
session->count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
378
session->count_cuted_fields= CHECK_FIELD_IGNORE;
393
380
simulated killing in the middle of per-row loop
394
381
must be effective for binlogging
396
killed_status= (error == 0)? Session::NOT_KILLED : session->getKilled();
383
killed_status= (error == 0)? Session::NOT_KILLED : session->killed;
399
386
error= -1; // Error on read
404
snprintf(msg, sizeof(msg), ER(ER_LOAD_INFO), info.records, info.deleted,
405
(info.records - info.copied), session->cuted_fields);
407
if (session->transaction.stmt.hasModifiedNonTransData())
408
session->transaction.all.markModifiedNonTransData();
389
sprintf(name, ER(ER_LOAD_INFO), (uint32_t) info.records, (uint32_t) info.deleted,
390
(uint32_t) (info.records - info.copied), (uint32_t) session->cuted_fields);
392
if (session->transaction.stmt.modified_non_trans_table)
393
session->transaction.all.modified_non_trans_table= true;
410
395
/* ok to client sent only after binlog write and engine commit */
411
session->my_ok(info.copied + info.deleted, 0, 0L, msg);
396
session->my_ok(info.copied + info.deleted, 0, 0L, name);
413
398
assert(transactional_table || !(info.copied || info.deleted) ||
414
session->transaction.stmt.hasModifiedNonTransData());
399
session->transaction.stmt.modified_non_trans_table);
415
400
table->cursor->ha_release_auto_increment();
416
401
table->auto_increment_field_not_null= false;
417
402
session->abort_on_warning= 0;