~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzleimport.cc

  • Committer: Monty Taylor
  • Date: 2009-09-30 07:01:32 UTC
  • mto: This revision was merged to the branch mainline in revision 1184.
  • Revision ID: mordred@inaugust.com-20090930070132-b1ol1xu1rpajdddy
Small namespace cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
*/
27
27
#define IMPORT_VERSION "3.7"
28
28
 
29
 
#include <config.h>
 
29
#include "client_priv.h"
30
30
#include <string>
31
31
 
32
 
#include "client_priv.h"
33
32
#include <pthread.h>
34
33
 
 
34
/* Added this for string translation. */
 
35
#include <drizzled/gettext.h>
 
36
 
35
37
using namespace std;
36
38
 
 
39
extern "C"
 
40
{
 
41
  bool get_one_option(int optid, const struct my_option *, char *argument);
 
42
  void * worker_thread(void *arg);
 
43
}
 
44
 
 
45
int exitcode= 0;
 
46
 
37
47
/* Global Thread counter */
38
 
uint counter;
 
48
uint32_t counter;
39
49
pthread_mutex_t counter_mutex;
40
50
pthread_cond_t count_threshhold;
41
51
 
42
 
static void db_error_with_table(DRIZZLE *drizzle, char *table);
43
 
static void db_error(DRIZZLE *drizzle);
44
 
static char *field_escape(char *to,const char *from,uint length);
 
52
static void db_error(drizzle_con_st *con, drizzle_result_st *result,
 
53
                     drizzle_return_t ret, char *table);
 
54
static char *field_escape(char *to,const char *from,uint32_t length);
45
55
static char *add_load_option(char *ptr,const char *object,
46
56
           const char *statement);
47
57
 
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,
57
 
    *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;
 
58
static bool verbose= false, lock_tables= false, ignore_errors= false,
 
59
            opt_delete= false, opt_replace= false, silent= false,
 
60
            ignore_unique= false, opt_compress= false, opt_low_priority= false,
 
61
            tty_password= false;
 
62
static bool debug_info_flag= false, debug_check_flag= false;
 
63
static uint32_t opt_use_threads= 0, opt_local_file= 0, my_end_arg= 0;
 
64
static char  *opt_password= NULL, *current_user= NULL,
 
65
    *current_host= NULL, *current_db= NULL, *fields_terminated= NULL,
 
66
    *lines_terminated= NULL, *enclosed= NULL, *opt_enclosed= NULL,
 
67
    *escaped= NULL, *opt_columns= NULL;
 
68
static uint32_t opt_drizzle_port= 0;
 
69
static char * opt_drizzle_unix_port= 0;
60
70
static int64_t opt_ignore_lines= -1;
61
 
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
62
71
 
63
72
static struct my_option my_long_options[] =
64
73
{
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
 
  {"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},
71
74
  {"columns", 'c',
72
75
   "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.",
73
76
   (char**) &opt_columns, (char**) &opt_columns, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
105
108
  {"host", 'h', "Connect to host.", (char**) &current_host,
106
109
   (char**) &current_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
107
110
  {"ignore", 'i', "If duplicate unique key was found, keep old row.",
108
 
   (char**) &ignore, (char**) &ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
111
   (char**) &ignore_unique, (char**) &ignore_unique, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
109
112
  {"ignore-lines", OPT_IGN_LINES, "Ignore first n lines of data infile.",
110
113
   (char**) &opt_ignore_lines, (char**) &opt_ignore_lines, 0, GET_LL,
111
114
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
120
123
  {"low-priority", OPT_LOW_PRIORITY,
121
124
   "Use LOW_PRIORITY when updating the table.", (char**) &opt_low_priority,
122
125
   (char**) &opt_low_priority, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
123
 
  {"password", 'p',
 
126
  {"password", 'P',
124
127
   "Password to use when connecting to server. If password is not given it's asked from the tty.",
125
128
   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 "
 
129
  {"port", 'p', "Port number to use for connection or 0 for default to, in "
127
130
   "order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
128
131
   "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,
131
 
   0},
 
132
   0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
132
133
  {"protocol", OPT_DRIZZLE_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
133
134
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
134
135
  {"replace", 'r', "If duplicate unique key was found, replace old row.",
143
144
   "of threads to use for loading data.",
144
145
   (char**) &opt_use_threads, (char**) &opt_use_threads, 0,
145
146
   GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
146
 
#ifndef DONT_ALLOW_USER_CHANGE
147
147
  {"user", 'u', "User for login if not current user.", (char**) &current_user,
148
148
   (char**) &current_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
149
 
#endif
150
149
  {"verbose", 'v', "Print info about the various stages.", (char**) &verbose,
151
150
   (char**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
152
151
  {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
159
158
 
160
159
static void print_version(void)
161
160
{
162
 
  printf("%s  Ver %s Distrib %s, for %s (%s)\n" ,my_progname,
163
 
    IMPORT_VERSION, drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
 
161
  printf("%s  Ver %s Distrib %s, for %s-%s (%s)\n" ,my_progname,
 
162
    IMPORT_VERSION, drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
164
163
}
165
164
 
166
165
 
182
181
  my_print_variables(my_long_options);
183
182
}
184
183
 
185
 
static bool
186
 
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
187
 
         char *argument)
 
184
bool get_one_option(int optid, const struct my_option *, char *argument)
188
185
{
 
186
  char *endchar= NULL;
 
187
  uint64_t temp_drizzle_port= 0;
 
188
 
189
189
  switch(optid) {
190
190
  case 'p':
 
191
    temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
 
192
    /* if there is an alpha character this is not a valid port */
 
193
    if (strlen(endchar) != 0)
 
194
    {
 
195
      fprintf(stderr, _("Non-integer value supplied for port.  If you are trying to enter a password please use --password instead.\n"));
 
196
      exit(1);
 
197
    }
 
198
    /* If the port number is > 65535 it is not a valid port
 
199
       This also helps with potential data loss casting unsigned long to a
 
200
       uint32_t. */
 
201
    if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
 
202
    {
 
203
      fprintf(stderr, _("Value supplied for port is not valid.\n"));
 
204
      exit(1);
 
205
    }
 
206
    else
 
207
    {
 
208
      opt_drizzle_port= (uint32_t) temp_drizzle_port;
 
209
    }
 
210
    break;
 
211
  case 'P':
191
212
    if (argument)
192
213
    {
193
214
      char *start=argument;
194
 
      free(opt_password);
195
 
      opt_password=my_strdup(argument,MYF(MY_FAE));
196
 
      while (*argument) *argument++= 'x';    /* Destroy argument */
 
215
      if (opt_password)
 
216
        free(opt_password);
 
217
      opt_password = strdup(argument);
 
218
      if (opt_password == NULL)
 
219
      {
 
220
        fprintf(stderr, "Memory allocation error while copying password. "
 
221
                        "Aborting.\n");
 
222
        exit(ENOMEM);
 
223
      }
 
224
      while (*argument)
 
225
      {
 
226
        /* Overwriting password with 'x' */
 
227
        *argument++= 'x';
 
228
      }
197
229
      if (*start)
198
 
  start[1]=0;        /* Cut length of argument */
 
230
      {
 
231
        /* Cut length of argument */
 
232
        start[1]= 0;
 
233
      }
199
234
      tty_password= 0;
200
235
    }
201
236
    else
229
264
    fprintf(stderr, "You can't use ..enclosed.. and ..optionally-enclosed.. at the same time.\n");
230
265
    return(1);
231
266
  }
232
 
  if (opt_replace && ignore)
 
267
  if (opt_replace && ignore_unique)
233
268
  {
234
 
    fprintf(stderr, "You can't use --ignore (-i) and --replace (-r) at the same time.\n");
 
269
    fprintf(stderr, "You can't use --ignore_unique (-i) and --replace (-r) at the same time.\n");
235
270
    return(1);
236
271
  }
237
 
  if (strcmp(default_charset, charset_info->csname) &&
238
 
      !(charset_info= get_charset_by_csname(default_charset,
239
 
                MY_CS_PRIMARY, MYF(MY_WME))))
240
 
    exit(1);
241
272
  if (*argc < 2)
242
273
  {
243
274
    usage();
246
277
  current_db= *((*argv)++);
247
278
  (*argc)--;
248
279
  if (tty_password)
249
 
    opt_password=get_tty_password(NULL);
 
280
    opt_password=client_get_tty_password(NULL);
250
281
  return(0);
251
282
}
252
283
 
253
284
 
254
285
 
255
 
static int write_to_table(char *filename, DRIZZLE *drizzle)
 
286
static int write_to_table(char *filename, drizzle_con_st *con)
256
287
{
257
288
  char tablename[FN_REFLEN], hard_path[FN_REFLEN],
258
289
       sql_statement[FN_REFLEN*16+256], *end;
 
290
  drizzle_result_st result;
 
291
  drizzle_return_t ret;
259
292
 
260
293
  fn_format(tablename, filename, "", "", 1 | 2); /* removes path & ext. */
261
294
  if (!opt_local_file)
262
 
    my_stpcpy(hard_path,filename);
 
295
    strcpy(hard_path,filename);
263
296
  else
264
297
    my_load_path(hard_path, filename, NULL); /* filename includes the path */
265
298
 
272
305
#else
273
306
    sprintf(sql_statement, "DELETE FROM %s", tablename);
274
307
#endif
275
 
    if (drizzle_query(drizzle, sql_statement))
 
308
    if (drizzle_query_str(con, &result, sql_statement, &ret) == NULL ||
 
309
        ret != DRIZZLE_RETURN_OK)
276
310
    {
277
 
      db_error_with_table(drizzle, tablename);
 
311
      db_error(con, &result, ret, tablename);
278
312
      return(1);
279
313
    }
 
314
    drizzle_result_free(&result);
280
315
  }
281
 
  to_unix_path(hard_path);
282
316
  if (verbose)
283
317
  {
284
318
    if (opt_local_file)
293
327
    opt_local_file ? "LOCAL" : "", hard_path);
294
328
  end= strchr(sql_statement, '\0');
295
329
  if (opt_replace)
296
 
    end= my_stpcpy(end, " REPLACE");
297
 
  if (ignore)
298
 
    end= my_stpcpy(end, " IGNORE");
299
 
  end= my_stpcpy(my_stpcpy(end, " INTO TABLE "), tablename);
 
330
    end= strcpy(end, " REPLACE")+8;
 
331
  if (ignore_unique)
 
332
    end= strcpy(end, " IGNORE")+7;
 
333
 
 
334
  end+= sprintf(end, " INTO TABLE %s", tablename);
300
335
 
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");
 
345
  {
 
346
    end= strcpy(end, " IGNORE ")+8;
 
347
    ostringstream buffer;
 
348
    buffer << opt_ignore_lines;
 
349
    end= strcpy(end, buffer.str().c_str())+ buffer.str().size();
 
350
    end= strcpy(end, " LINES")+6;
 
351
  }
312
352
  if (opt_columns)
313
 
    end= my_stpcpy(my_stpcpy(my_stpcpy(end, " ("), opt_columns), ")");
 
353
  {
 
354
    end= strcpy(end, " (")+2;
 
355
    end= strcpy(end, opt_columns)+strlen(opt_columns);
 
356
    end= strcpy(end, ")")+1;
 
357
  }
314
358
  *end= '\0';
315
359
 
316
 
  if (drizzle_query(drizzle, sql_statement))
 
360
  if (drizzle_query_str(con, &result, sql_statement, &ret) == NULL ||
 
361
      ret != DRIZZLE_RETURN_OK)
317
362
  {
318
 
    db_error_with_table(drizzle, tablename);
 
363
    db_error(con, &result, ret, tablename);
319
364
    return(1);
320
365
  }
321
366
  if (!silent)
322
367
  {
323
 
    if (drizzle_info(drizzle)) /* If NULL-pointer, print nothing */
 
368
    if (strcmp(drizzle_result_info(&result), ""))
324
369
    {
325
370
      fprintf(stdout, "%s.%s: %s\n", current_db, tablename,
326
 
        drizzle_info(drizzle));
 
371
        drizzle_result_info(&result));
327
372
    }
328
373
  }
 
374
  drizzle_result_free(&result);
329
375
  return(0);
330
376
}
331
377
 
332
378
 
333
 
 
334
 
static void lock_table(DRIZZLE *drizzle, int tablecount, char **raw_tablename)
 
379
static void lock_table(drizzle_con_st *con, int tablecount, char **raw_tablename)
335
380
{
336
381
  string query;
337
382
  int i;
338
383
  char tablename[FN_REFLEN];
 
384
  drizzle_result_st result;
 
385
  drizzle_return_t ret;
339
386
 
340
387
  if (verbose)
341
388
    fprintf(stdout, "Locking tables for write\n");
346
393
    query.append(tablename);
347
394
    query.append(" WRITE,");
348
395
  }
349
 
  if (drizzle_real_query(drizzle, query.c_str(), query.length()-1))
350
 
    db_error(drizzle); /* We shall countinue here, if --force was given */
 
396
  if (drizzle_query(con, &result, query.c_str(), query.length()-1,
 
397
                    &ret) == NULL ||
 
398
      ret != DRIZZLE_RETURN_OK)
 
399
  {
 
400
    db_error(con, &result, ret, NULL);
 
401
    /* We shall countinue here, if --force was given */
 
402
    return;
 
403
  }
 
404
  drizzle_result_free(&result);
351
405
}
352
406
 
353
407
 
354
 
 
355
 
 
356
 
static DRIZZLE *db_connect(char *host, char *database,
357
 
                         char *user, char *passwd)
 
408
static drizzle_con_st *db_connect(char *host, char *database,
 
409
                                  char *user, char *passwd)
358
410
{
359
 
  DRIZZLE *drizzle;
 
411
  drizzle_st *drizzle;
 
412
  drizzle_con_st *con;
 
413
  drizzle_return_t ret;
 
414
 
360
415
  if (verbose)
361
416
    fprintf(stdout, "Connecting to %s\n", host ? host : "localhost");
362
417
  if (!(drizzle= drizzle_create(NULL)))
363
418
    return 0;
364
 
  if (opt_compress)
365
 
    drizzle_options(drizzle,DRIZZLE_OPT_COMPRESS,NULL);
366
 
  if (opt_local_file)
367
 
    drizzle_options(drizzle,DRIZZLE_OPT_LOCAL_INFILE,
368
 
      (char*) &opt_local_file);
369
 
  if (opt_protocol)
370
 
    drizzle_options(drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
371
 
  if (!(drizzle_connect(drizzle,host,user,passwd,
372
 
                           database,opt_drizzle_port,opt_drizzle_unix_port,
373
 
                           0)))
 
419
  if (!(con= drizzle_con_add_tcp(drizzle,NULL,host,opt_drizzle_port,user,passwd,
 
420
                                 database, DRIZZLE_CON_NONE)))
 
421
  {
 
422
    return 0;
 
423
  }
 
424
 
 
425
  if ((ret= drizzle_con_connect(con)) != DRIZZLE_RETURN_OK)
374
426
  {
375
427
    ignore_errors=0;    /* NO RETURN FROM db_error */
376
 
    db_error(drizzle);
 
428
    db_error(con, NULL, ret, NULL);
377
429
  }
378
 
  drizzle->reconnect= 0;
 
430
 
379
431
  if (verbose)
380
432
    fprintf(stdout, "Selecting database %s\n", database);
381
 
  if (drizzle_select_db(drizzle, database))
382
 
  {
383
 
    ignore_errors=0;
384
 
    db_error(drizzle);
385
 
  }
386
 
  return drizzle;
 
433
 
 
434
  return con;
387
435
}
388
436
 
389
437
 
390
438
 
391
 
static void db_disconnect(char *host, DRIZZLE *drizzle)
 
439
static void db_disconnect(char *host, drizzle_con_st *con)
392
440
{
393
441
  if (verbose)
394
442
    fprintf(stdout, "Disconnecting from %s\n", host ? host : "localhost");
395
 
  drizzle_close(drizzle);
 
443
  drizzle_free(drizzle_con_drizzle(con));
396
444
}
397
445
 
398
446
 
399
447
 
400
 
static void safe_exit(int error, DRIZZLE *drizzle)
 
448
static void safe_exit(int error, drizzle_con_st *con)
401
449
{
402
450
  if (ignore_errors)
403
451
    return;
404
 
  if (drizzle)
405
 
    drizzle_close(drizzle);
 
452
  if (con)
 
453
    drizzle_free(drizzle_con_drizzle(con));
406
454
  exit(error);
407
455
}
408
456
 
409
457
 
410
458
 
411
 
static void db_error_with_table(DRIZZLE *drizzle, char *table)
412
 
{
413
 
  my_printf_error(0,"Error: %d, %s, when using table: %s",
414
 
      MYF(0), drizzle_errno(drizzle), drizzle_error(drizzle), table);
415
 
  safe_exit(1, drizzle);
416
 
}
417
 
 
418
 
 
419
 
 
420
 
static void db_error(DRIZZLE *drizzle)
421
 
{
422
 
  my_printf_error(0,"Error: %d %s", MYF(0), drizzle_errno(drizzle), drizzle_error(drizzle));
423
 
  safe_exit(1, drizzle);
 
459
static void db_error(drizzle_con_st *con, drizzle_result_st *result,
 
460
                     drizzle_return_t ret, char *table)
 
461
{
 
462
  if (ret == DRIZZLE_RETURN_ERROR_CODE)
 
463
  {
 
464
    my_printf_error(0,"Error: %d, %s%s%s", MYF(0),
 
465
                    drizzle_result_error_code(result),
 
466
                    drizzle_result_error(result),
 
467
                    table ? ", when using table: " : "", table ? table : "");
 
468
    drizzle_result_free(result);
 
469
  }
 
470
  else
 
471
  {
 
472
    my_printf_error(0,"Error: %d, %s%s%s", MYF(0), ret, drizzle_con_error(con),
 
473
                    table ? ", when using table: " : "", table ? table : "");
 
474
  }
 
475
 
 
476
  safe_exit(1, con);
424
477
}
425
478
 
426
479
 
431
484
  {
432
485
    /* Don't escape hex constants */
433
486
    if (object[0] == '0' && (object[1] == 'x' || object[1] == 'X'))
434
 
      ptr= strxmov(ptr," ",statement," ",object,NULL);
 
487
      ptr+= sprintf(ptr, " %s %s", statement, object);
435
488
    else
436
489
    {
437
490
      /* char constant; escape */
438
 
      ptr= strxmov(ptr," ",statement," '",NULL);
439
 
      ptr= field_escape(ptr,object,(uint) strlen(object));
 
491
      ptr+= sprintf(ptr, " %s '", statement); 
 
492
      ptr= field_escape(ptr,object,(uint32_t) strlen(object));
440
493
      *ptr++= '\'';
441
494
    }
442
495
  }
450
503
** syntax errors from the SQL parser.
451
504
*/
452
505
 
453
 
static char *field_escape(char *to,const char *from,uint length)
 
506
static char *field_escape(char *to,const char *from,uint32_t length)
454
507
{
455
508
  const char *end;
456
 
  uint end_backslashes=0;
 
509
  uint32_t end_backslashes=0;
457
510
 
458
511
  for (end= from+length; from != end; from++)
459
512
  {
469
522
  }
470
523
  /* Add missing backslashes if user has specified odd number of backs.*/
471
524
  if (end_backslashes)
472
 
    *to++= '\\';         
 
525
    *to++= '\\';
473
526
  return to;
474
527
}
475
528
 
476
 
int exitcode= 0;
477
 
 
478
 
static void * worker_thread(void *arg)
 
529
void * worker_thread(void *arg)
479
530
{
480
531
  int error;
481
532
  char *raw_table_name= (char *)arg;
482
 
  DRIZZLE *drizzle= 0;
 
533
  drizzle_con_st *con= NULL;
 
534
  drizzle_result_st result;
 
535
  drizzle_return_t ret;
483
536
 
484
 
  if (!(drizzle= db_connect(current_host,current_db,current_user,opt_password)))
 
537
  if (!(con= db_connect(current_host,current_db,current_user,opt_password)))
485
538
  {
486
539
    goto error;
487
540
  }
488
541
 
489
 
  if (drizzle_query(drizzle, "/*!40101 set @@character_set_database=binary */;"))
 
542
  if (drizzle_query_str(con, &result,
 
543
                        "/*!40101 set @@character_set_database=binary */;",
 
544
                        &ret) == NULL ||
 
545
      ret != DRIZZLE_RETURN_OK)
490
546
  {
491
 
    db_error(drizzle); /* We shall countinue here, if --force was given */
 
547
    db_error(con, &result, ret, NULL);
 
548
    /* We shall countinue here, if --force was given */
492
549
    goto error;
493
550
  }
494
551
 
495
552
  /*
496
553
    We are not currently catching the error here.
497
554
  */
498
 
  if((error= write_to_table(raw_table_name, drizzle)))
 
555
  if((error= write_to_table(raw_table_name, con)))
499
556
    if (exitcode == 0)
500
557
      exitcode= error;
501
558
 
502
559
error:
503
 
  if (drizzle)
504
 
    db_disconnect(current_host, drizzle);
 
560
  if (con)
 
561
    db_disconnect(current_host, con);
505
562
 
506
563
  pthread_mutex_lock(&counter_mutex);
507
564
  counter--;
584
641
  else
585
642
#endif
586
643
  {
587
 
    DRIZZLE *drizzle= 0;
588
 
    if (!(drizzle= db_connect(current_host,current_db,current_user,opt_password)))
 
644
    drizzle_con_st *con= 0;
 
645
    drizzle_result_st result;
 
646
    drizzle_return_t ret;
 
647
    if (!(con= db_connect(current_host,current_db,current_user,opt_password)))
589
648
    {
590
649
      free_defaults(argv_to_free);
591
 
      return(1); /* purecov: deadcode */
 
650
      return(1);
592
651
    }
593
652
 
594
 
    if (drizzle_query(drizzle, "/*!40101 set @@character_set_database=binary */;"))
 
653
    if (drizzle_query_str(con, &result,
 
654
                          "/*!40101 set @@character_set_database=binary */;",
 
655
                          &ret) == NULL ||
 
656
        ret != DRIZZLE_RETURN_OK)
595
657
    {
596
 
      db_error(drizzle); /* We shall countinue here, if --force was given */
 
658
      db_error(con, &result, ret, NULL);
 
659
      /* We shall countinue here, if --force was given */
597
660
      return(1);
598
661
    }
599
662
 
 
663
    drizzle_result_free(&result);
 
664
 
600
665
    if (lock_tables)
601
 
      lock_table(drizzle, argc, argv);
 
666
      lock_table(con, argc, argv);
602
667
    for (; *argv != NULL; argv++)
603
 
      if ((error= write_to_table(*argv, drizzle)))
 
668
      if ((error= write_to_table(*argv, con)))
604
669
        if (exitcode == 0)
605
670
          exitcode= error;
606
 
    db_disconnect(current_host, drizzle);
 
671
    db_disconnect(current_host, con);
607
672
  }
608
673
  free(opt_password);
609
674
  free_defaults(argv_to_free);