57
50
static bool verbose= false, lock_tables= false, ignore_errors= false,
58
51
opt_delete= false, opt_replace= false, silent= false,
59
ignore_unique= false, opt_low_priority= false,
60
tty_password= false, opt_mysql= false;
62
static uint32_t opt_use_threads= 0, opt_local_file= 0;
52
ignore_unique= false, opt_compress= false, opt_low_priority= false,
54
static bool debug_info_flag= false, debug_check_flag= false;
55
static uint32_t opt_use_threads= 0, opt_local_file= 0, my_end_arg= 0;
63
56
static char *opt_password= NULL, *current_user= NULL,
64
57
*current_host= NULL, *current_db= NULL, *fields_terminated= NULL,
65
58
*lines_terminated= NULL, *enclosed= NULL, *opt_enclosed= NULL,
66
*escaped= NULL, *opt_columns= NULL;
59
*escaped= NULL, *opt_columns= NULL,
60
*default_charset= (char*) DRIZZLE_DEFAULT_CHARSET_NAME;
67
61
static uint32_t opt_drizzle_port= 0;
62
static char * opt_drizzle_unix_port= 0;
68
63
static int64_t opt_ignore_lines= -1;
64
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
70
static struct option my_long_options[] =
66
static struct my_option my_long_options[] =
68
{"default-character-set", OPT_DEFAULT_CHARSET,
69
"Set the default character set.", (char**) &default_charset,
70
(char**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
73
72
"Use only these columns to import the data to. Give the column names in a comma separated list. This is same as giving columns to LOAD DATA INFILE.",
74
73
(char**) &opt_columns, (char**) &opt_columns, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
75
{"compress", 'C', "Use compression in server/client protocol.",
76
(char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
76
78
{"debug",'#', "Output debug log. Often this is 'd:t:o,filename'.", 0, 0, 0,
77
79
GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
80
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
81
(char**) &debug_check_flag, (char**) &debug_check_flag, 0,
82
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
83
{"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
84
(char**) &debug_info_flag, (char**) &debug_info_flag,
85
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
78
86
{"delete", 'd', "First delete all rows from table.", (char**) &opt_delete,
79
87
(char**) &opt_delete, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
80
88
{"fields-terminated-by", OPT_FTB,
112
120
{"low-priority", OPT_LOW_PRIORITY,
113
121
"Use LOW_PRIORITY when updating the table.", (char**) &opt_low_priority,
114
122
(char**) &opt_low_priority, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
115
{"mysql", 'm', N_("Use MySQL Protocol."),
116
(char**) &opt_mysql, (char**) &opt_mysql, 0, GET_BOOL, NO_ARG, 1, 0, 0,
118
123
{"password", 'P',
119
124
"Password to use when connecting to server. If password is not given it's asked from the tty.",
120
125
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
128
133
(char**) &opt_replace, (char**) &opt_replace, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
129
134
{"silent", 's', "Be more silent.", (char**) &silent, (char**) &silent, 0,
130
135
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
136
{"socket", 'S', "Socket file to use for connection.",
137
(char**) &opt_drizzle_unix_port, (char**) &opt_drizzle_unix_port, 0, GET_STR,
138
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
131
139
{"use-threads", OPT_USE_THREADS,
132
140
"Load files in parallel. The argument is the number "
133
141
"of threads to use for loading data.",
134
142
(char**) &opt_use_threads, (char**) &opt_use_threads, 0,
135
143
GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
144
#ifndef DONT_ALLOW_USER_CHANGE
136
145
{"user", 'u', "User for login if not current user.", (char**) ¤t_user,
137
146
(char**) ¤t_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
138
148
{"verbose", 'v', "Print info about the various stages.", (char**) &verbose,
139
149
(char**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
140
150
{"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
164
174
read the text file directly. In other cases the client will open the text\n\
165
175
file. The SQL command 'LOAD DATA INFILE' is used to import the rows.\n");
167
printf("\nUsage: %s [OPTIONS] database textfile...",internal::my_progname);
168
internal::print_defaults("drizzle",load_default_groups);
177
printf("\nUsage: %s [OPTIONS] database textfile...",my_progname);
178
print_defaults("drizzle",load_default_groups);
169
179
my_print_help(my_long_options);
170
180
my_print_variables(my_long_options);
173
static int get_one_option(int optid, const struct option *, char *argument)
184
bool get_one_option(int optid, const struct my_option *, char *argument)
175
186
char *endchar= NULL;
176
187
uint64_t temp_drizzle_port= 0;
275
293
drizzle_result_st result;
276
294
drizzle_return_t ret;
278
internal::fn_format(tablename, filename, "", "", 1 | 2); /* removes path & ext. */
296
fn_format(tablename, filename, "", "", 1 | 2); /* removes path & ext. */
279
297
if (!opt_local_file)
280
298
strcpy(hard_path,filename);
282
internal::my_load_path(hard_path, filename, NULL); /* filename includes the path */
300
my_load_path(hard_path, filename, NULL); /* filename includes the path */
287
305
fprintf(stdout, "Deleting the old data from table %s\n", tablename);
288
306
#ifdef HAVE_SNPRINTF
289
snprintf(sql_statement, sizeof(sql_statement), "DELETE FROM %s", tablename);
307
snprintf(sql_statement, FN_REFLEN*16+256, "DELETE FROM %s", tablename);
291
snprintf(sql_statement, sizeof(sql_statement), "DELETE FROM %s", tablename);
309
sprintf(sql_statement, "DELETE FROM %s", tablename);
293
311
if (drizzle_query_str(con, &result, sql_statement, &ret) == NULL ||
294
312
ret != DRIZZLE_RETURN_OK)