45
47
static char *add_load_option(char *ptr,const char *object,
46
48
const char *statement);
48
static bool verbose=0,lock_tables=0,ignore_errors=0,opt_delete=0,
49
opt_replace=0,silent=0,ignore=0,opt_compress=0,
50
opt_low_priority= 0, tty_password= 0;
51
static bool debug_info_flag= 0, debug_check_flag= 0;
52
static uint opt_use_threads=0, opt_local_file=0, my_end_arg= 0;
53
static char *opt_password=0, *current_user=0,
54
*current_host=0, *current_db=0, *fields_terminated=0,
55
*lines_terminated=0, *enclosed=0, *opt_enclosed=0,
56
*escaped=0, *opt_columns=0,
50
static bool verbose= false, lock_tables= false, ignore_errors= false,
51
opt_delete= false, opt_replace= false, silent= false,
52
ignore= false, opt_compress= false, opt_low_priority= false,
54
static bool debug_info_flag= false, debug_check_flag= false;
55
static uint opt_use_threads= 0, opt_local_file= 0, my_end_arg= 0;
56
static char *opt_password= NULL, *current_user= NULL,
57
*current_host= NULL, *current_db= NULL, *fields_terminated= NULL,
58
*lines_terminated= NULL, *enclosed= NULL, *opt_enclosed= NULL,
59
*escaped= NULL, *opt_columns= NULL,
57
60
*default_charset= (char*) DRIZZLE_DEFAULT_CHARSET_NAME;
58
static uint opt_drizzle_port= 0, opt_protocol= 0;
59
static char * opt_drizzle_unix_port=0;
61
static uint opt_protocol= 0;
62
static uint32_t opt_drizzle_port= 0;
63
static char * opt_drizzle_unix_port= 0;
60
64
static int64_t opt_ignore_lines= -1;
61
65
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
63
67
static struct my_option my_long_options[] =
65
{"character-sets-dir", OPT_CHARSETS_DIR,
66
"Directory where character sets are.", (char**) &charsets_dir,
67
(char**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
68
69
{"default-character-set", OPT_DEFAULT_CHARSET,
69
70
"Set the default character set.", (char**) &default_charset,
70
71
(char**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
120
121
{"low-priority", OPT_LOW_PRIORITY,
121
122
"Use LOW_PRIORITY when updating the table.", (char**) &opt_low_priority,
122
123
(char**) &opt_low_priority, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
124
125
"Password to use when connecting to server. If password is not given it's asked from the tty.",
125
126
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
126
{"port", 'P', "Port number to use for connection or 0 for default to, in "
127
"order of preference, my.cnf, $DRIZZLE_TCP_PORT, "
127
{"port", 'p', "Port number to use for connection or 0 for default to, in "
128
"order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
128
129
"built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
129
(char**) &opt_drizzle_port,
130
(char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
130
0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
132
131
{"protocol", OPT_DRIZZLE_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
133
132
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
134
133
{"replace", 'r', "If duplicate unique key was found, replace old row.",
177
176
file. The SQL command 'LOAD DATA INFILE' is used to import the rows.\n");
179
178
printf("\nUsage: %s [OPTIONS] database textfile...",my_progname);
180
print_defaults("my",load_default_groups);
179
print_defaults("drizzle",load_default_groups);
181
180
my_print_help(my_long_options);
182
181
my_print_variables(my_long_options);
186
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
185
bool get_one_option(int optid, const struct my_option *, char *argument)
188
uint64_t temp_drizzle_port= 0;
192
temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
193
/* if there is an alpha character this is not a valid port */
194
if (strlen(endchar) != 0)
196
fprintf(stderr, _("Non-integer value supplied for port. If you are trying to enter a password please use --password instead.\n"));
199
/* If the port number is > 65535 it is not a valid port
200
This also helps with potential data loss casting unsigned long to a
202
if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
204
fprintf(stderr, _("Value supplied for port is not valid.\n"));
209
opt_drizzle_port= (uint32_t) temp_drizzle_port;
193
215
char *start=argument;
195
opt_password=my_strdup(argument,MYF(MY_FAE));
196
while (*argument) *argument++= 'x'; /* Destroy argument */
218
opt_password = strdup(argument);
219
if (opt_password == NULL)
221
fprintf(stderr, "Memory allocation error while copying password. "
227
/* Overwriting password with 'x' */
198
start[1]=0; /* Cut length of argument */
232
/* Cut length of argument */
293
327
opt_local_file ? "LOCAL" : "", hard_path);
294
328
end= strchr(sql_statement, '\0');
296
end= my_stpcpy(end, " REPLACE");
330
end= strcpy(end, " REPLACE")+8;
298
end= my_stpcpy(end, " IGNORE");
299
end= my_stpcpy(my_stpcpy(end, " INTO TABLE "), tablename);
332
end= strcpy(end, " IGNORE")+7;
334
end+= sprintf(end, " INTO TABLE %s", tablename);
301
336
if (fields_terminated || enclosed || opt_enclosed || escaped)
302
end= my_stpcpy(end, " FIELDS");
337
end= strcpy(end, " FIELDS")+7;
303
338
end= add_load_option(end, fields_terminated, " TERMINATED BY");
304
339
end= add_load_option(end, enclosed, " ENCLOSED BY");
305
340
end= add_load_option(end, opt_enclosed,
307
342
end= add_load_option(end, escaped, " ESCAPED BY");
308
343
end= add_load_option(end, lines_terminated, " LINES TERMINATED BY");
309
344
if (opt_ignore_lines >= 0)
310
end= my_stpcpy(int64_t10_to_str(opt_ignore_lines,
311
my_stpcpy(end, " IGNORE "),10), " LINES");
346
end= strcpy(end, " IGNORE ")+8;
347
end= int64_t2str(opt_ignore_lines, end, 10);
348
end= strcpy(end, " LINES")+6;
313
end= my_stpcpy(my_stpcpy(my_stpcpy(end, " ("), opt_columns), ")");
352
end= strcpy(end, " (")+2;
353
end= strcpy(end, opt_columns)+strlen(opt_columns);
354
end= strcpy(end, ")")+1;
316
if (drizzle_query(drizzle, sql_statement))
358
if (drizzleclient_query(drizzle, sql_statement))
318
360
db_error_with_table(drizzle, tablename);
323
if (drizzle_info(drizzle)) /* If NULL-pointer, print nothing */
365
if (drizzleclient_info(drizzle)) /* If NULL-pointer, print nothing */
325
367
fprintf(stdout, "%s.%s: %s\n", current_db, tablename,
326
drizzle_info(drizzle));
368
drizzleclient_info(drizzle));
359
401
DRIZZLE *drizzle;
361
403
fprintf(stdout, "Connecting to %s\n", host ? host : "localhost");
362
if (!(drizzle= drizzle_create(NULL)))
404
if (!(drizzle= drizzleclient_create(NULL)))
364
406
if (opt_compress)
365
drizzle_options(drizzle,DRIZZLE_OPT_COMPRESS,NULL);
407
drizzleclient_options(drizzle,DRIZZLE_OPT_COMPRESS,NULL);
366
408
if (opt_local_file)
367
drizzle_options(drizzle,DRIZZLE_OPT_LOCAL_INFILE,
409
drizzleclient_options(drizzle,DRIZZLE_OPT_LOCAL_INFILE,
368
410
(char*) &opt_local_file);
369
411
if (opt_protocol)
370
drizzle_options(drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
371
if (!(drizzle_connect(drizzle,host,user,passwd,
412
drizzleclient_options(drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
413
if (!(drizzleclient_connect(drizzle,host,user,passwd,
372
414
database,opt_drizzle_port,opt_drizzle_unix_port,
432
474
/* Don't escape hex constants */
433
475
if (object[0] == '0' && (object[1] == 'x' || object[1] == 'X'))
434
ptr= strxmov(ptr," ",statement," ",object,NULL);
476
ptr+= sprintf(ptr, " %s %s", statement, object);
437
479
/* char constant; escape */
438
ptr= strxmov(ptr," ",statement," '",NULL);
480
ptr+= sprintf(ptr, " %s '", statement);
439
481
ptr= field_escape(ptr,object,(uint) strlen(object));