15
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
** drizzleimport.c - Imports all given files
17
** mysqlimport.c - Imports all given files
21
** *************************
23
** * AUTHOR: Monty & Jani *
24
** * DATE: June 24, 1997 *
26
** *************************
20
** *************************
22
** * AUTHOR: Monty & Jani *
23
** * DATE: June 24, 1997 *
25
** *************************
28
27
#define IMPORT_VERSION "3.7"
30
29
#include "client_priv.h"
36
/* Added this for string translation. */
37
#include <drizzled/gettext.h>
40
using namespace drizzled;
42
extern "C" void * worker_thread(void *arg);
30
#include "mysql_version.h"
31
#ifdef HAVE_LIBPTHREAD
32
#include <my_pthread.h>
46
36
/* Global Thread counter */
38
#ifdef HAVE_LIBPTHREAD
48
39
pthread_mutex_t counter_mutex;
49
40
pthread_cond_t count_threshhold;
51
static void db_error(drizzle_con_st *con, drizzle_result_st *result,
52
drizzle_return_t ret, char *table);
53
static char *field_escape(char *to,const char *from,uint32_t length);
43
static void db_error_with_table(MYSQL *mysql, char *table);
44
static void db_error(MYSQL *mysql);
45
static char *field_escape(char *to,const char *from,uint length);
54
46
static char *add_load_option(char *ptr,const char *object,
55
const char *statement);
57
static bool verbose= false, lock_tables= false, ignore_errors= false,
58
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;
63
static char *opt_password= NULL, *current_user= NULL,
64
*current_host= NULL, *current_db= NULL, *fields_terminated= NULL,
65
*lines_terminated= NULL, *enclosed= NULL, *opt_enclosed= NULL,
66
*escaped= NULL, *opt_columns= NULL;
67
static uint32_t opt_drizzle_port= 0;
68
static int64_t opt_ignore_lines= -1;
47
const char *statement);
49
static my_bool verbose=0,lock_tables=0,ignore_errors=0,opt_delete=0,
50
replace=0,silent=0,ignore=0,opt_compress=0,
51
opt_low_priority= 0, tty_password= 0;
52
static my_bool debug_info_flag= 0, debug_check_flag= 0;
53
static uint opt_use_threads=0, opt_local_file=0, my_end_arg= 0;
54
static char *opt_password=0, *current_user=0,
55
*current_host=0, *current_db=0, *fields_terminated=0,
56
*lines_terminated=0, *enclosed=0, *opt_enclosed=0,
57
*escaped=0, *opt_columns=0,
58
*default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
59
static uint opt_mysql_port= 0, opt_protocol= 0;
60
static char * opt_mysql_unix_port=0;
61
static longlong opt_ignore_lines= -1;
62
static CHARSET_INFO *charset_info= &my_charset_latin1;
65
static char *shared_memory_base_name=0;
70
68
static struct my_option my_long_options[] =
71
{"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.",
72
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
74
{"character-sets-dir", OPT_CHARSETS_DIR,
75
"Directory where character sets are.", (uchar**) &charsets_dir,
76
(uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
77
{"default-character-set", OPT_DEFAULT_CHARSET,
78
"Set the default character set.", (uchar**) &default_charset,
79
(uchar**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
73
81
"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
(char**) &opt_columns, (char**) &opt_columns, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
82
(uchar**) &opt_columns, (uchar**) &opt_columns, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
84
{"compress", 'C', "Use compression in server/client protocol.",
85
(uchar**) &opt_compress, (uchar**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
76
87
{"debug",'#', "Output debug log. Often this is 'd:t:o,filename'.", 0, 0, 0,
77
88
GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
78
{"delete", 'd', "First delete all rows from table.", (char**) &opt_delete,
79
(char**) &opt_delete, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
89
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
90
(uchar**) &debug_check_flag, (uchar**) &debug_check_flag, 0,
91
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
92
{"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
93
(uchar**) &debug_info_flag, (uchar**) &debug_info_flag,
94
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
95
{"delete", 'd', "First delete all rows from table.", (uchar**) &opt_delete,
96
(uchar**) &opt_delete, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
80
97
{"fields-terminated-by", OPT_FTB,
81
"Fields in the textfile are terminated by ...", (char**) &fields_terminated,
82
(char**) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
98
"Fields in the textfile are terminated by ...", (uchar**) &fields_terminated,
99
(uchar**) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
83
100
{"fields-enclosed-by", OPT_ENC,
84
"Fields in the importfile are enclosed by ...", (char**) &enclosed,
85
(char**) &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
101
"Fields in the importfile are enclosed by ...", (uchar**) &enclosed,
102
(uchar**) &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
86
103
{"fields-optionally-enclosed-by", OPT_O_ENC,
87
"Fields in the i.file are opt. enclosed by ...", (char**) &opt_enclosed,
88
(char**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
104
"Fields in the i.file are opt. enclosed by ...", (uchar**) &opt_enclosed,
105
(uchar**) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
89
106
{"fields-escaped-by", OPT_ESC, "Fields in the i.file are escaped by ...",
90
(char**) &escaped, (char**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0,
107
(uchar**) &escaped, (uchar**) &escaped, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0,
92
109
{"force", 'f', "Continue even if we get an sql-error.",
93
(char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
110
(uchar**) &ignore_errors, (uchar**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
95
112
{"help", '?', "Displays this help and exits.", 0, 0, 0, GET_NO_ARG, NO_ARG,
96
113
0, 0, 0, 0, 0, 0},
97
{"host", 'h', "Connect to host.", (char**) ¤t_host,
98
(char**) ¤t_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
114
{"host", 'h', "Connect to host.", (uchar**) ¤t_host,
115
(uchar**) ¤t_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
99
116
{"ignore", 'i', "If duplicate unique key was found, keep old row.",
100
(char**) &ignore_unique, (char**) &ignore_unique, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
117
(uchar**) &ignore, (uchar**) &ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
101
118
{"ignore-lines", OPT_IGN_LINES, "Ignore first n lines of data infile.",
102
(char**) &opt_ignore_lines, (char**) &opt_ignore_lines, 0, GET_LL,
119
(uchar**) &opt_ignore_lines, (uchar**) &opt_ignore_lines, 0, GET_LL,
103
120
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
104
121
{"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...",
105
(char**) &lines_terminated, (char**) &lines_terminated, 0, GET_STR,
122
(uchar**) &lines_terminated, (uchar**) &lines_terminated, 0, GET_STR,
106
123
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
107
{"local", 'L', "Read all files through the client.", (char**) &opt_local_file,
108
(char**) &opt_local_file, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
124
{"local", 'L', "Read all files through the client.", (uchar**) &opt_local_file,
125
(uchar**) &opt_local_file, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
109
126
{"lock-tables", 'l', "Lock all tables for write (this disables threads).",
110
(char**) &lock_tables, (char**) &lock_tables, 0, GET_BOOL, NO_ARG,
127
(uchar**) &lock_tables, (uchar**) &lock_tables, 0, GET_BOOL, NO_ARG,
111
128
0, 0, 0, 0, 0, 0},
112
129
{"low-priority", OPT_LOW_PRIORITY,
113
"Use LOW_PRIORITY when updating the table.", (char**) &opt_low_priority,
114
(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, 0, 0, 0,
130
"Use LOW_PRIORITY when updating the table.", (uchar**) &opt_low_priority,
131
(uchar**) &opt_low_priority, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
119
133
"Password to use when connecting to server. If password is not given it's asked from the tty.",
120
134
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
121
{"port", 'p', "Port number to use for connection or 0 for default to, in "
122
"order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
123
"built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
124
0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
125
{"protocol", OPT_DRIZZLE_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
136
{"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG,
137
NO_ARG, 0, 0, 0, 0, 0, 0},
139
{"port", 'P', "Port number to use for connection or 0 for default to, in "
140
"order of preference, my.cnf, $MYSQL_TCP_PORT, "
141
#if MYSQL_PORT_DEFAULT == 0
144
"built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
145
(uchar**) &opt_mysql_port,
146
(uchar**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
148
{"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
126
149
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
127
150
{"replace", 'r', "If duplicate unique key was found, replace old row.",
128
(char**) &opt_replace, (char**) &opt_replace, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
129
{"silent", 's', "Be more silent.", (char**) &silent, (char**) &silent, 0,
151
(uchar**) &replace, (uchar**) &replace, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
153
{"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
154
"Base name of shared memory.", (uchar**) &shared_memory_base_name, (uchar**) &shared_memory_base_name,
155
0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
157
{"silent", 's', "Be more silent.", (uchar**) &silent, (uchar**) &silent, 0,
130
158
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
159
{"socket", 'S', "Socket file to use for connection.",
160
(uchar**) &opt_mysql_unix_port, (uchar**) &opt_mysql_unix_port, 0, GET_STR,
161
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
131
162
{"use-threads", OPT_USE_THREADS,
132
163
"Load files in parallel. The argument is the number "
133
164
"of threads to use for loading data.",
134
(char**) &opt_use_threads, (char**) &opt_use_threads, 0,
165
(uchar**) &opt_use_threads, (uchar**) &opt_use_threads, 0,
135
166
GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
136
{"user", 'u', "User for login if not current user.", (char**) ¤t_user,
137
(char**) ¤t_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
138
{"verbose", 'v', "Print info about the various stages.", (char**) &verbose,
139
(char**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
167
#ifndef DONT_ALLOW_USER_CHANGE
168
{"user", 'u', "User for login if not current user.", (uchar**) ¤t_user,
169
(uchar**) ¤t_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
171
{"verbose", 'v', "Print info about the various stages.", (uchar**) &verbose,
172
(uchar**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
140
173
{"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
141
174
NO_ARG, 0, 0, 0, 0, 0, 0},
142
175
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
146
static const char *load_default_groups[]= { "drizzleimport","client",0 };
179
static const char *load_default_groups[]= { "mysqlimport","client",0 };
181
#include <help_start.h>
148
183
static void print_version(void)
150
printf("%s Ver %s Distrib %s, for %s-%s (%s)\n" ,internal::my_progname,
151
IMPORT_VERSION, drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
185
printf("%s Ver %s Distrib %s, for %s (%s)\n" ,my_progname,
186
IMPORT_VERSION, MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
187
NETWARE_SET_SCREEN_MODE(1);
155
191
static void usage(void)
158
puts("Copyright (C) 2008 Drizzle Open Source Development Team");
194
puts("Copyright (C) 2000-2006 MySQL AB");
159
195
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
161
197
Loads tables from text files in various formats. The base name of the\n\
162
198
text file must be the name of the table that should be used.\n\
163
If one uses sockets to connect to the Drizzle server, the server will open and\n\
199
If one uses sockets to connect to the MySQL server, the server will open and\n\
164
200
read the text file directly. In other cases the client will open the text\n\
165
201
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);
203
printf("\nUsage: %s [OPTIONS] database textfile...",my_progname);
204
print_defaults("my",load_default_groups);
169
205
my_print_help(my_long_options);
170
206
my_print_variables(my_long_options);
173
static bool get_one_option(int optid, const struct my_option *, char *argument)
209
#include <help_end.h>
212
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
176
uint64_t temp_drizzle_port= 0;
218
setscreenmode(SCR_AUTOCLOSE_ON_EXIT);
180
temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
181
/* if there is an alpha character this is not a valid port */
182
if (strlen(endchar) != 0)
184
fprintf(stderr, _("Non-integer value supplied for port. If you are trying to enter a password please use --password instead.\n"));
187
/* If the port number is > 65535 it is not a valid port
188
This also helps with potential data loss casting unsigned long to a
190
if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
192
fprintf(stderr, _("Value supplied for port is not valid.\n"));
197
opt_drizzle_port= (uint32_t) temp_drizzle_port;
203
224
char *start=argument;
206
opt_password = strdup(argument);
207
if (opt_password == NULL)
209
fprintf(stderr, "Memory allocation error while copying password. "
215
/* Overwriting password with 'x' */
225
my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
226
opt_password=my_strdup(argument,MYF(MY_FAE));
227
while (*argument) *argument++= 'x'; /* Destroy argument */
220
/* Cut length of argument */
229
start[1]=0; /* Cut length of argument */
228
case OPT_DRIZZLE_PROTOCOL:
237
opt_protocol = MYSQL_PROTOCOL_PIPE;
241
case OPT_MYSQL_PROTOCOL:
242
opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
246
DBUG_PUSH(argument ? argument : "d:t:o");
230
249
case 'V': print_version(); exit(0);
291
318
sprintf(sql_statement, "DELETE FROM %s", tablename);
293
if (drizzle_query_str(con, &result, sql_statement, &ret) == NULL ||
294
ret != DRIZZLE_RETURN_OK)
320
if (mysql_query(mysql, sql_statement))
296
db_error(con, &result, ret, tablename);
322
db_error_with_table(mysql, tablename);
299
drizzle_result_free(&result);
326
to_unix_path(hard_path);
303
329
if (opt_local_file)
304
330
fprintf(stdout, "Loading data from LOCAL file: %s into %s\n",
305
hard_path, tablename);
331
hard_path, tablename);
307
333
fprintf(stdout, "Loading data from SERVER file: %s into %s\n",
308
hard_path, tablename);
334
hard_path, tablename);
310
336
sprintf(sql_statement, "LOAD DATA %s %s INFILE '%s'",
311
opt_low_priority ? "LOW_PRIORITY" : "",
312
opt_local_file ? "LOCAL" : "", hard_path);
313
end= strchr(sql_statement, '\0');
315
end= strcpy(end, " REPLACE")+8;
317
end= strcpy(end, " IGNORE")+7;
319
end+= sprintf(end, " INTO TABLE %s", tablename);
337
opt_low_priority ? "LOW_PRIORITY" : "",
338
opt_local_file ? "LOCAL" : "", hard_path);
339
end= strend(sql_statement);
341
end= strmov(end, " REPLACE");
343
end= strmov(end, " IGNORE");
344
end= strmov(strmov(end, " INTO TABLE "), tablename);
321
346
if (fields_terminated || enclosed || opt_enclosed || escaped)
322
end= strcpy(end, " FIELDS")+7;
347
end= strmov(end, " FIELDS");
323
348
end= add_load_option(end, fields_terminated, " TERMINATED BY");
324
349
end= add_load_option(end, enclosed, " ENCLOSED BY");
325
350
end= add_load_option(end, opt_enclosed,
326
" OPTIONALLY ENCLOSED BY");
351
" OPTIONALLY ENCLOSED BY");
327
352
end= add_load_option(end, escaped, " ESCAPED BY");
328
353
end= add_load_option(end, lines_terminated, " LINES TERMINATED BY");
329
354
if (opt_ignore_lines >= 0)
331
end= strcpy(end, " IGNORE ")+8;
332
ostringstream buffer;
333
buffer << opt_ignore_lines;
334
end= strcpy(end, buffer.str().c_str())+ buffer.str().size();
335
end= strcpy(end, " LINES")+6;
355
end= strmov(longlong10_to_str(opt_ignore_lines,
356
strmov(end, " IGNORE "),10), " LINES");
339
end= strcpy(end, " (")+2;
340
end= strcpy(end, opt_columns)+strlen(opt_columns);
341
end= strcpy(end, ")")+1;
358
end= strmov(strmov(strmov(end, " ("), opt_columns), ")");
345
if (drizzle_query_str(con, &result, sql_statement, &ret) == NULL ||
346
ret != DRIZZLE_RETURN_OK)
361
if (mysql_query(mysql, sql_statement))
348
db_error(con, &result, ret, tablename);
363
db_error_with_table(mysql, tablename);
353
if (strcmp(drizzle_result_info(&result), ""))
368
if (mysql_info(mysql)) /* If NULL-pointer, print nothing */
355
370
fprintf(stdout, "%s.%s: %s\n", current_db, tablename,
356
drizzle_result_info(&result));
359
drizzle_result_free(&result);
364
static void lock_table(drizzle_con_st *con, int tablecount, char **raw_tablename)
379
static void lock_table(MYSQL *mysql, int tablecount, char **raw_tablename)
381
DYNAMIC_STRING query;
368
383
char tablename[FN_REFLEN];
369
drizzle_result_st result;
370
drizzle_return_t ret;
373
386
fprintf(stdout, "Locking tables for write\n");
374
query.append("LOCK TABLES ");
387
init_dynamic_string(&query, "LOCK TABLES ", 256, 1024);
375
388
for (i=0 ; i < tablecount ; i++)
377
internal::fn_format(tablename, raw_tablename[i], "", "", 1 | 2);
378
query.append(tablename);
379
query.append(" WRITE,");
381
if (drizzle_query(con, &result, query.c_str(), query.length()-1,
383
ret != DRIZZLE_RETURN_OK)
385
db_error(con, &result, ret, NULL);
386
/* We shall countinue here, if --force was given */
389
drizzle_result_free(&result);
390
fn_format(tablename, raw_tablename[i], "", "", 1 | 2);
391
dynstr_append(&query, tablename);
392
dynstr_append(&query, " WRITE,");
394
if (mysql_real_query(mysql, query.str, query.length-1))
395
db_error(mysql); /* We shall countinue here, if --force was given */
393
static drizzle_con_st *db_connect(char *host, char *database,
394
char *user, char *passwd)
401
static MYSQL *db_connect(char *host, char *database,
402
char *user, char *passwd)
398
drizzle_return_t ret;
401
406
fprintf(stdout, "Connecting to %s\n", host ? host : "localhost");
402
if (!(drizzle= drizzle_create(NULL)))
404
if (!(con= drizzle_con_add_tcp(drizzle,NULL,host,opt_drizzle_port,user,passwd,
405
database, opt_mysql ? DRIZZLE_CON_MYSQL : DRIZZLE_CON_NONE)))
410
if ((ret= drizzle_con_connect(con)) != DRIZZLE_RETURN_OK)
412
ignore_errors=0; /* NO RETURN FROM db_error */
413
db_error(con, NULL, ret, NULL);
407
if (!(mysql= mysql_init(NULL)))
410
mysql_options(mysql,MYSQL_OPT_COMPRESS,NullS);
412
mysql_options(mysql,MYSQL_OPT_LOCAL_INFILE,
413
(char*) &opt_local_file);
416
mysql_ssl_set(mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
417
opt_ssl_capath, opt_ssl_cipher);
418
mysql_options(mysql,MYSQL_OPT_SSL_VERIFY_SERVER_CERT,
419
(char*)&opt_ssl_verify_server_cert);
422
mysql_options(mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
424
if (shared_memory_base_name)
425
mysql_options(mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
427
if (!(mysql_real_connect(mysql,host,user,passwd,
428
database,opt_mysql_port,opt_mysql_unix_port,
431
ignore_errors=0; /* NO RETURN FROM db_error */
417
436
fprintf(stdout, "Selecting database %s\n", database);
437
if (mysql_select_db(mysql, database))
424
static void db_disconnect(char *host, drizzle_con_st *con)
447
static void db_disconnect(char *host, MYSQL *mysql)
427
450
fprintf(stdout, "Disconnecting from %s\n", host ? host : "localhost");
428
drizzle_free(drizzle_con_drizzle(con));
433
static void safe_exit(int error, drizzle_con_st *con)
456
static void safe_exit(int error, MYSQL *mysql)
435
458
if (ignore_errors)
438
drizzle_free(drizzle_con_drizzle(con));
444
static void db_error(drizzle_con_st *con, drizzle_result_st *result,
445
drizzle_return_t ret, char *table)
447
if (ret == DRIZZLE_RETURN_ERROR_CODE)
449
my_printf_error(0,"Error: %d, %s%s%s", MYF(0),
450
drizzle_result_error_code(result),
451
drizzle_result_error(result),
452
table ? ", when using table: " : "", table ? table : "");
453
drizzle_result_free(result);
457
my_printf_error(0,"Error: %d, %s%s%s", MYF(0), ret, drizzle_con_error(con),
458
table ? ", when using table: " : "", table ? table : "");
467
static void db_error_with_table(MYSQL *mysql, char *table)
469
my_printf_error(0,"Error: %d, %s, when using table: %s",
470
MYF(0), mysql_errno(mysql), mysql_error(mysql), table);
476
static void db_error(MYSQL *mysql)
478
my_printf_error(0,"Error: %d %s", MYF(0), mysql_errno(mysql), mysql_error(mysql));
465
483
static char *add_load_option(char *ptr, const char *object,
466
const char *statement)
484
const char *statement)
470
488
/* Don't escape hex constants */
471
489
if (object[0] == '0' && (object[1] == 'x' || object[1] == 'X'))
472
ptr+= sprintf(ptr, " %s %s", statement, object);
490
ptr= strxmov(ptr," ",statement," ",object,NullS);
475
493
/* char constant; escape */
476
ptr+= sprintf(ptr, " %s '", statement);
477
ptr= field_escape(ptr,object,(uint32_t) strlen(object));
494
ptr= strxmov(ptr," ",statement," '",NullS);
495
ptr= field_escape(ptr,object,(uint) strlen(object));