85
87
void set_io_cache_arg(void* arg) { cache.arg = arg; }
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)
125
char name[FN_REFLEN];
127
128
Table *table= NULL;
129
130
String *field_term=ex->field_term,*escaped=ex->escaped;
130
131
String *enclosed=ex->enclosed;
132
char *db= table_list->db; // This is never null
134
assert(table_list->getSchemaName()); // This should never be null
135
137
If path for cursor is not defined, we will use the current database.
136
138
If this is not set, we will use the directory where the table to be
137
139
loaded is located
139
const char *tdb= session->db.empty() ? db : session->db.c_str(); // Result is never null
141
const char *tdb= session->db.empty() ? table_list->getSchemaName() : session->db.c_str(); // Result is never null
141
143
uint32_t skip_lines= ex->skip_lines;
142
144
bool transactional_table;
143
Session::killed_state killed_status= Session::NOT_KILLED;
145
Session::killed_state_t killed_status= Session::NOT_KILLED;
145
147
/* Escape and enclosed character may be a utf8 4-byte character */
146
148
if (escaped->length() > 4 || enclosed->length() > 4)
256
#ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS
257
ex->file_name+=dirname_length(ex->file_name);
259
if (!internal::dirname_length(ex->file_name))
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);
268
(void) internal::fn_format(name, ex->file_name, drizzle_real_data_home, "",
269
MY_RELATIVE_PATH | MY_UNPACK_FILENAME);
271
if (opt_secure_file_priv &&
272
strncmp(opt_secure_file_priv, name, strlen(opt_secure_file_priv)))
274
/* Read only allowed from within dir specified by secure_file_priv */
275
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");
279
struct stat stat_info;
280
if (stat(name,&stat_info))
282
my_error(ER_FILE_NOT_FOUND, MYF(0), name, errno);
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)))
292
my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), name);
295
if ((stat_info.st_mode & S_IFIFO) == S_IFIFO)
298
if ((file=internal::my_open(name,O_RDONLY,MYF(MY_WME))) < 0)
300
my_error(ER_CANT_OPEN_FILE, MYF(0), name, errno);
257
fs::path to_file(ex->file_name);
258
fs::path target_path(fs::system_complete(getDataHomeCatalog()));
259
if (not to_file.has_root_directory())
261
int count_elements= 0;
262
for (fs::path::iterator iter= to_file.begin();
263
iter != to_file.end();
264
++iter, ++count_elements)
267
if (count_elements == 1)
271
target_path /= to_file;
275
target_path= to_file;
278
if (not secure_file_priv.string().empty())
280
if (target_path.file_string().substr(0, secure_file_priv.file_string().size()) != secure_file_priv.file_string())
282
/* Read only allowed from within dir specified by secure_file_priv */
283
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");
288
struct stat stat_info;
289
if (stat(target_path.file_string().c_str(), &stat_info))
291
my_error(ER_FILE_NOT_FOUND, MYF(0), target_path.file_string().c_str(), errno);
295
// if we are not in slave thread, the cursor must be:
296
if (!((stat_info.st_mode & S_IROTH) == S_IROTH && // readable by others
297
(stat_info.st_mode & S_IFLNK) != S_IFLNK && // and not a symlink
298
((stat_info.st_mode & S_IFREG) == S_IFREG ||
299
(stat_info.st_mode & S_IFIFO) == S_IFIFO)))
301
my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), target_path.file_string().c_str());
304
if ((stat_info.st_mode & S_IFIFO) == S_IFIFO)
308
if ((file=internal::my_open(target_path.file_string().c_str(), O_RDONLY,MYF(MY_WME))) < 0)
310
my_error(ER_CANT_OPEN_FILE, MYF(0), target_path.file_string().c_str(), errno);
306
314
memset(&info, 0, sizeof(info));
307
315
info.ignore= ignore;
308
316
info.handle_duplicates=handle_duplicates;
377
385
internal::my_close(file,MYF(0));
378
386
free_blobs(table); /* if pack_blob was used */
379
387
table->copy_blobs=0;
380
session->count_cuted_fields= CHECK_FIELD_IGNORE;
388
session->count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
382
390
simulated killing in the middle of per-row loop
383
391
must be effective for binlogging
385
killed_status= (error == 0)? Session::NOT_KILLED : session->killed;
393
killed_status= (error == 0)? Session::NOT_KILLED : session->getKilled();
388
396
error= -1; // Error on read
391
sprintf(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);
401
snprintf(msg, sizeof(msg), ER(ER_LOAD_INFO), info.records, info.deleted,
402
(info.records - info.copied), session->cuted_fields);
394
404
if (session->transaction.stmt.hasModifiedNonTransData())
395
405
session->transaction.all.markModifiedNonTransData();
397
407
/* ok to client sent only after binlog write and engine commit */
398
session->my_ok(info.copied + info.deleted, 0, 0L, name);
408
session->my_ok(info.copied + info.deleted, 0, 0L, msg);
400
410
assert(transactional_table || !(info.copied || info.deleted) ||
401
411
session->transaction.stmt.hasModifiedNonTransData());
411
421
****************************************************************************/
414
read_fixed_length(Session *session, COPY_INFO &info, TableList *table_list,
424
read_fixed_length(Session *session, CopyInfo &info, TableList *table_list,
415
425
List<Item> &fields_vars, List<Item> &set_fields,
416
426
List<Item> &set_values, READ_INFO &read_info,
417
427
uint32_t skip_lines, bool ignore_check_option_errors)
533
read_sep_field(Session *session, COPY_INFO &info, TableList *table_list,
543
read_sep_field(Session *session, CopyInfo &info, TableList *table_list,
534
544
List<Item> &fields_vars, List<Item> &set_fields,
535
545
List<Item> &set_values, READ_INFO &read_info,
536
546
String &enclosed, uint32_t skip_lines,
787
797
end_of_buff=buffer+buff_length;
788
if (init_io_cache(&cache,(false) ? -1 : cursor, 0,
789
(false) ? internal::READ_NET :
790
(is_fifo ? internal::READ_FIFO : internal::READ_CACHE),0L,1,
798
if (cache.init_io_cache((false) ? -1 : cursor, 0,
799
(false) ? internal::READ_NET :
800
(is_fifo ? internal::READ_FIFO : internal::READ_CACHE),0L,1,
793
803
free((unsigned char*) buffer);