46
42
const char *statement);
48
44
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;
45
replace=0,silent=0,ignore=0,opt_compress=0,
46
opt_low_priority= 0, tty_password= 0;
51
47
static bool debug_info_flag= 0, debug_check_flag= 0;
52
48
static uint opt_use_threads=0, opt_local_file=0, my_end_arg= 0;
53
49
static char *opt_password=0, *current_user=0,
54
50
*current_host=0, *current_db=0, *fields_terminated=0,
55
51
*lines_terminated=0, *enclosed=0, *opt_enclosed=0,
56
52
*escaped=0, *opt_columns=0,
57
*default_charset= (char*) DRIZZLE_DEFAULT_CHARSET_NAME;
53
*default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
58
54
static uint opt_drizzle_port= 0, opt_protocol= 0;
59
55
static char * opt_drizzle_unix_port=0;
60
56
static int64_t opt_ignore_lines= -1;
61
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
57
static CHARSET_INFO *charset_info= &my_charset_latin1;
63
59
static struct my_option my_long_options[] =
124
120
"Password to use when connecting to server. If password is not given it's asked from the tty.",
125
121
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
126
122
{"port", 'P', "Port number to use for connection or 0 for default to, in "
127
"order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
128
"built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
123
"order of preference, my.cnf, $MYSQL_TCP_PORT, "
124
#if MYSQL_PORT_DEFAULT == 0
127
"built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
129
128
(char**) &opt_drizzle_port,
130
129
(char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 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.",
135
(char**) &opt_replace, (char**) &opt_replace, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
134
(char**) &replace, (char**) &replace, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
136
135
{"silent", 's', "Be more silent.", (char**) &silent, (char**) &silent, 0,
137
136
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
138
137
{"socket", 'S', "Socket file to use for connection.",
291
292
sprintf(sql_statement, "LOAD DATA %s %s INFILE '%s'",
292
293
opt_low_priority ? "LOW_PRIORITY" : "",
293
294
opt_local_file ? "LOCAL" : "", hard_path);
294
end= strchr(sql_statement, '\0');
296
end= my_stpcpy(end, " REPLACE");
295
end= strend(sql_statement);
297
end= strmov(end, " REPLACE");
298
end= my_stpcpy(end, " IGNORE");
299
end= my_stpcpy(my_stpcpy(end, " INTO TABLE "), tablename);
299
end= strmov(end, " IGNORE");
300
end= strmov(strmov(end, " INTO TABLE "), tablename);
301
302
if (fields_terminated || enclosed || opt_enclosed || escaped)
302
end= my_stpcpy(end, " FIELDS");
303
end= strmov(end, " FIELDS");
303
304
end= add_load_option(end, fields_terminated, " TERMINATED BY");
304
305
end= add_load_option(end, enclosed, " ENCLOSED BY");
305
306
end= add_load_option(end, opt_enclosed,
307
308
end= add_load_option(end, escaped, " ESCAPED BY");
308
309
end= add_load_option(end, lines_terminated, " LINES TERMINATED BY");
309
310
if (opt_ignore_lines >= 0)
310
end= my_stpcpy(int64_t10_to_str(opt_ignore_lines,
311
my_stpcpy(end, " IGNORE "),10), " LINES");
311
end= strmov(int64_t10_to_str(opt_ignore_lines,
312
strmov(end, " IGNORE "),10), " LINES");
313
end= my_stpcpy(my_stpcpy(my_stpcpy(end, " ("), opt_columns), ")");
314
end= strmov(strmov(strmov(end, " ("), opt_columns), ")");
316
317
if (drizzle_query(drizzle, sql_statement))
334
335
static void lock_table(DRIZZLE *drizzle, int tablecount, char **raw_tablename)
337
DYNAMIC_STRING query;
338
339
char tablename[FN_REFLEN];
341
342
fprintf(stdout, "Locking tables for write\n");
342
query.append("LOCK TABLES ");
343
init_dynamic_string(&query, "LOCK TABLES ", 256, 1024);
343
344
for (i=0 ; i < tablecount ; i++)
345
346
fn_format(tablename, raw_tablename[i], "", "", 1 | 2);
346
query.append(tablename);
347
query.append(" WRITE,");
347
dynstr_append(&query, tablename);
348
dynstr_append(&query, " WRITE,");
349
if (drizzle_real_query(drizzle, query.c_str(), query.length()-1))
350
if (drizzle_real_query(drizzle, query.str, query.length-1))
350
351
db_error(drizzle); /* We shall countinue here, if --force was given */
432
433
/* Don't escape hex constants */
433
434
if (object[0] == '0' && (object[1] == 'x' || object[1] == 'X'))
434
ptr= strxmov(ptr," ",statement," ",object,NULL);
435
ptr= strxmov(ptr," ",statement," ",object,NullS);
437
438
/* char constant; escape */
438
ptr= strxmov(ptr," ",statement," '",NULL);
439
ptr= strxmov(ptr," ",statement," '",NullS);
439
440
ptr= field_escape(ptr,object,(uint) strlen(object));
537
541
pthread_attr_setdetachstate(&attr,
538
542
PTHREAD_CREATE_DETACHED);
540
pthread_mutex_init(&counter_mutex, NULL);
541
pthread_cond_init(&count_threshhold, NULL);
544
VOID(pthread_mutex_init(&counter_mutex, NULL));
545
VOID(pthread_cond_init(&count_threshhold, NULL));
543
547
for (counter= 0; *argv != NULL; argv++) /* Loop through tables */