~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzleimport.cc

  • Committer: Brian Aker
  • Date: 2009-01-24 09:43:35 UTC
  • Revision ID: brian@gir-3.local-20090124094335-6qdtvc35gl5fvivz
Adding in an example singe thread scheduler

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2006 MySQL AB
2
 
   Copyright (C) 2008-2009 Sun Microsystems, Inc
 
1
/* Copyright (C) 2008 Drizzle Open Source Development Team
3
2
 
4
3
   This program is free software; you can redistribute it and/or modify
5
4
   it under the terms of the GNU General Public License as published by
29
28
 
30
29
#include "client_priv.h"
31
30
#include <string>
32
 
#include <sstream>
33
31
 
34
32
#include <pthread.h>
35
33
 
37
35
#include <drizzled/gettext.h>
38
36
 
39
37
using namespace std;
40
 
using namespace drizzled;
41
 
 
42
 
extern "C" void * worker_thread(void *arg);
43
 
 
44
 
int exitcode= 0;
45
38
 
46
39
/* Global Thread counter */
47
 
uint32_t counter;
 
40
uint counter;
48
41
pthread_mutex_t counter_mutex;
49
42
pthread_cond_t count_threshhold;
50
43
 
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);
 
44
static void db_error_with_table(DRIZZLE *drizzle, char *table);
 
45
static void db_error(DRIZZLE *drizzle);
 
46
static char *field_escape(char *to,const char *from,uint length);
54
47
static char *add_load_option(char *ptr,const char *object,
55
48
           const char *statement);
56
49
 
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;
61
 
 
62
 
static uint32_t opt_use_threads= 0, opt_local_file= 0;
 
52
            ignore= false, opt_compress= false, opt_low_priority= false,
 
53
            tty_password= 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;
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;
 
61
static uint opt_protocol= 0;
67
62
static uint32_t opt_drizzle_port= 0;
 
63
static char * opt_drizzle_unix_port= 0;
68
64
static int64_t opt_ignore_lines= -1;
 
65
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
69
66
 
70
 
static struct option my_long_options[] =
 
67
static struct my_option my_long_options[] =
71
68
{
 
69
  {"character-sets-dir", OPT_CHARSETS_DIR,
 
70
   "Directory where character sets are.", (char**) &charsets_dir,
 
71
   (char**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
72
  {"default-character-set", OPT_DEFAULT_CHARSET,
 
73
   "Set the default character set.", (char**) &default_charset,
 
74
   (char**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
72
75
  {"columns", 'c',
73
76
   "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
77
   (char**) &opt_columns, (char**) &opt_columns, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
75
78
   0, 0, 0},
 
79
  {"compress", 'C', "Use compression in server/client protocol.",
 
80
   (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
81
   0, 0, 0},
76
82
  {"debug",'#', "Output debug log. Often this is 'd:t:o,filename'.", 0, 0, 0,
77
83
   GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
84
  {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
 
85
   (char**) &debug_check_flag, (char**) &debug_check_flag, 0,
 
86
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
87
  {"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
 
88
   (char**) &debug_info_flag, (char**) &debug_info_flag,
 
89
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
78
90
  {"delete", 'd', "First delete all rows from table.", (char**) &opt_delete,
79
91
   (char**) &opt_delete, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
80
92
  {"fields-terminated-by", OPT_FTB,
97
109
  {"host", 'h', "Connect to host.", (char**) &current_host,
98
110
   (char**) &current_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
99
111
  {"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},
 
112
   (char**) &ignore, (char**) &ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
101
113
  {"ignore-lines", OPT_IGN_LINES, "Ignore first n lines of data infile.",
102
114
   (char**) &opt_ignore_lines, (char**) &opt_ignore_lines, 0, GET_LL,
103
115
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
112
124
  {"low-priority", OPT_LOW_PRIORITY,
113
125
   "Use LOW_PRIORITY when updating the table.", (char**) &opt_low_priority,
114
126
   (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,
117
 
   0, 0, 0},
118
127
  {"password", 'P',
119
128
   "Password to use when connecting to server. If password is not given it's asked from the tty.",
120
129
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
128
137
   (char**) &opt_replace, (char**) &opt_replace, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
129
138
  {"silent", 's', "Be more silent.", (char**) &silent, (char**) &silent, 0,
130
139
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
140
  {"socket", 'S', "Socket file to use for connection.",
 
141
   (char**) &opt_drizzle_unix_port, (char**) &opt_drizzle_unix_port, 0, GET_STR,
 
142
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
131
143
  {"use-threads", OPT_USE_THREADS,
132
144
   "Load files in parallel. The argument is the number "
133
145
   "of threads to use for loading data.",
134
146
   (char**) &opt_use_threads, (char**) &opt_use_threads, 0,
135
147
   GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
148
#ifndef DONT_ALLOW_USER_CHANGE
136
149
  {"user", 'u', "User for login if not current user.", (char**) &current_user,
137
150
   (char**) &current_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
151
#endif
138
152
  {"verbose", 'v', "Print info about the various stages.", (char**) &verbose,
139
153
   (char**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
140
154
  {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
147
161
 
148
162
static void print_version(void)
149
163
{
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);
 
164
  printf("%s  Ver %s Distrib %s, for %s (%s)\n" ,my_progname,
 
165
    IMPORT_VERSION, drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
152
166
}
153
167
 
154
168
 
164
178
read the text file directly. In other cases the client will open the text\n\
165
179
file. The SQL command 'LOAD DATA INFILE' is used to import the rows.\n");
166
180
 
167
 
  printf("\nUsage: %s [OPTIONS] database textfile...",internal::my_progname);
168
 
  internal::print_defaults("drizzle",load_default_groups);
 
181
  printf("\nUsage: %s [OPTIONS] database textfile...",my_progname);
 
182
  print_defaults("drizzle",load_default_groups);
169
183
  my_print_help(my_long_options);
170
184
  my_print_variables(my_long_options);
171
185
}
172
186
 
173
 
static int get_one_option(int optid, const struct option *, char *argument)
 
187
extern "C"
 
188
bool get_one_option(int optid, const struct my_option *, char *argument)
174
189
{
175
190
  char *endchar= NULL;
176
191
  uint64_t temp_drizzle_port= 0;
182
197
    if (strlen(endchar) != 0)
183
198
    {
184
199
      fprintf(stderr, _("Non-integer value supplied for port.  If you are trying to enter a password please use --password instead.\n"));
185
 
      return EXIT_ARGUMENT_INVALID;
 
200
      exit(1);
186
201
    }
187
202
    /* If the port number is > 65535 it is not a valid port
188
203
       This also helps with potential data loss casting unsigned long to a
190
205
    if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
191
206
    {
192
207
      fprintf(stderr, _("Value supplied for port is not valid.\n"));
193
 
      return EXIT_ARGUMENT_INVALID;
 
208
      exit(1);
194
209
    }
195
210
    else
196
211
    {
208
223
      {
209
224
        fprintf(stderr, "Memory allocation error while copying password. "
210
225
                        "Aborting.\n");
211
 
        return EXIT_OUT_OF_MEMORY;
 
226
        exit(ENOMEM);
212
227
      }
213
228
      while (*argument)
214
229
      {
243
258
 
244
259
  if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
245
260
    exit(ho_error);
 
261
  if (debug_info_flag)
 
262
    my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
 
263
  if (debug_check_flag)
 
264
    my_end_arg= MY_CHECK_ERROR;
246
265
 
247
266
  if (enclosed && opt_enclosed)
248
267
  {
249
268
    fprintf(stderr, "You can't use ..enclosed.. and ..optionally-enclosed.. at the same time.\n");
250
269
    return(1);
251
270
  }
252
 
  if (opt_replace && ignore_unique)
 
271
  if (opt_replace && ignore)
253
272
  {
254
 
    fprintf(stderr, "You can't use --ignore_unique (-i) and --replace (-r) at the same time.\n");
 
273
    fprintf(stderr, "You can't use --ignore (-i) and --replace (-r) at the same time.\n");
255
274
    return(1);
256
275
  }
 
276
  if (strcmp(default_charset, charset_info->csname) &&
 
277
      !(charset_info= get_charset_by_csname(default_charset,
 
278
                MY_CS_PRIMARY, MYF(MY_WME))))
 
279
    exit(1);
257
280
  if (*argc < 2)
258
281
  {
259
282
    usage();
262
285
  current_db= *((*argv)++);
263
286
  (*argc)--;
264
287
  if (tty_password)
265
 
    opt_password=client_get_tty_password(NULL);
 
288
    opt_password=get_tty_password(NULL);
266
289
  return(0);
267
290
}
268
291
 
269
292
 
270
293
 
271
 
static int write_to_table(char *filename, drizzle_con_st *con)
 
294
static int write_to_table(char *filename, DRIZZLE *drizzle)
272
295
{
273
296
  char tablename[FN_REFLEN], hard_path[FN_REFLEN],
274
297
       sql_statement[FN_REFLEN*16+256], *end;
275
 
  drizzle_result_st result;
276
 
  drizzle_return_t ret;
277
298
 
278
 
  internal::fn_format(tablename, filename, "", "", 1 | 2); /* removes path & ext. */
 
299
  fn_format(tablename, filename, "", "", 1 | 2); /* removes path & ext. */
279
300
  if (!opt_local_file)
280
301
    strcpy(hard_path,filename);
281
302
  else
282
 
    internal::my_load_path(hard_path, filename, NULL); /* filename includes the path */
 
303
    my_load_path(hard_path, filename, NULL); /* filename includes the path */
283
304
 
284
305
  if (opt_delete)
285
306
  {
286
307
    if (verbose)
287
308
      fprintf(stdout, "Deleting the old data from table %s\n", tablename);
288
309
#ifdef HAVE_SNPRINTF
289
 
    snprintf(sql_statement, sizeof(sql_statement), "DELETE FROM %s", tablename);
 
310
    snprintf(sql_statement, FN_REFLEN*16+256, "DELETE FROM %s", tablename);
290
311
#else
291
 
    snprintf(sql_statement, sizeof(sql_statement), "DELETE FROM %s", tablename);
 
312
    sprintf(sql_statement, "DELETE FROM %s", tablename);
292
313
#endif
293
 
    if (drizzle_query_str(con, &result, sql_statement, &ret) == NULL ||
294
 
        ret != DRIZZLE_RETURN_OK)
 
314
    if (drizzle_query(drizzle, sql_statement))
295
315
    {
296
 
      db_error(con, &result, ret, tablename);
 
316
      db_error_with_table(drizzle, tablename);
297
317
      return(1);
298
318
    }
299
 
    drizzle_result_free(&result);
300
319
  }
301
320
  if (verbose)
302
321
  {
307
326
      fprintf(stdout, "Loading data from SERVER file: %s into %s\n",
308
327
        hard_path, tablename);
309
328
  }
310
 
  snprintf(sql_statement, sizeof(sql_statement), "LOAD DATA %s %s INFILE '%s'",
 
329
  sprintf(sql_statement, "LOAD DATA %s %s INFILE '%s'",
311
330
    opt_low_priority ? "LOW_PRIORITY" : "",
312
331
    opt_local_file ? "LOCAL" : "", hard_path);
313
332
  end= strchr(sql_statement, '\0');
314
333
  if (opt_replace)
315
334
    end= strcpy(end, " REPLACE")+8;
316
 
  if (ignore_unique)
 
335
  if (ignore)
317
336
    end= strcpy(end, " IGNORE")+7;
318
337
 
319
338
  end+= sprintf(end, " INTO TABLE %s", tablename);
329
348
  if (opt_ignore_lines >= 0)
330
349
  {
331
350
    end= strcpy(end, " IGNORE ")+8;
332
 
    ostringstream buffer;
333
 
    buffer << opt_ignore_lines;
334
 
    end= strcpy(end, buffer.str().c_str())+ buffer.str().size();
 
351
    end= int64_t2str(opt_ignore_lines, end, 10);
335
352
    end= strcpy(end, " LINES")+6;
336
353
  }
337
354
  if (opt_columns)
342
359
  }
343
360
  *end= '\0';
344
361
 
345
 
  if (drizzle_query_str(con, &result, sql_statement, &ret) == NULL ||
346
 
      ret != DRIZZLE_RETURN_OK)
 
362
  if (drizzle_query(drizzle, sql_statement))
347
363
  {
348
 
    db_error(con, &result, ret, tablename);
 
364
    db_error_with_table(drizzle, tablename);
349
365
    return(1);
350
366
  }
351
367
  if (!silent)
352
368
  {
353
 
    if (strcmp(drizzle_result_info(&result), ""))
 
369
    if (drizzle_info(drizzle)) /* If NULL-pointer, print nothing */
354
370
    {
355
371
      fprintf(stdout, "%s.%s: %s\n", current_db, tablename,
356
 
        drizzle_result_info(&result));
 
372
        drizzle_info(drizzle));
357
373
    }
358
374
  }
359
 
  drizzle_result_free(&result);
360
375
  return(0);
361
376
}
362
377
 
363
378
 
364
 
static void lock_table(drizzle_con_st *con, int tablecount, char **raw_tablename)
 
379
 
 
380
static void lock_table(DRIZZLE *drizzle, int tablecount, char **raw_tablename)
365
381
{
366
382
  string query;
367
383
  int i;
368
384
  char tablename[FN_REFLEN];
369
 
  drizzle_result_st result;
370
 
  drizzle_return_t ret;
371
385
 
372
386
  if (verbose)
373
387
    fprintf(stdout, "Locking tables for write\n");
374
388
  query.append("LOCK TABLES ");
375
389
  for (i=0 ; i < tablecount ; i++)
376
390
  {
377
 
    internal::fn_format(tablename, raw_tablename[i], "", "", 1 | 2);
 
391
    fn_format(tablename, raw_tablename[i], "", "", 1 | 2);
378
392
    query.append(tablename);
379
393
    query.append(" WRITE,");
380
394
  }
381
 
  if (drizzle_query(con, &result, query.c_str(), query.length()-1,
382
 
                    &ret) == NULL ||
383
 
      ret != DRIZZLE_RETURN_OK)
384
 
  {
385
 
    db_error(con, &result, ret, NULL);
386
 
    /* We shall countinue here, if --force was given */
387
 
    return;
388
 
  }
389
 
  drizzle_result_free(&result);
 
395
  if (drizzle_real_query(drizzle, query.c_str(), query.length()-1))
 
396
    db_error(drizzle); /* We shall countinue here, if --force was given */
390
397
}
391
398
 
392
399
 
393
 
static drizzle_con_st *db_connect(char *host, char *database,
394
 
                                  char *user, char *passwd)
 
400
 
 
401
 
 
402
static DRIZZLE *db_connect(char *host, char *database,
 
403
                         char *user, char *passwd)
395
404
{
396
 
  drizzle_st *drizzle;
397
 
  drizzle_con_st *con;
398
 
  drizzle_return_t ret;
399
 
 
 
405
  DRIZZLE *drizzle;
400
406
  if (verbose)
401
407
    fprintf(stdout, "Connecting to %s\n", host ? host : "localhost");
402
408
  if (!(drizzle= drizzle_create(NULL)))
403
409
    return 0;
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)))
406
 
  {
407
 
    return 0;
408
 
  }
409
 
 
410
 
  if ((ret= drizzle_con_connect(con)) != DRIZZLE_RETURN_OK)
 
410
  if (opt_compress)
 
411
    drizzle_options(drizzle,DRIZZLE_OPT_COMPRESS,NULL);
 
412
  if (opt_local_file)
 
413
    drizzle_options(drizzle,DRIZZLE_OPT_LOCAL_INFILE,
 
414
      (char*) &opt_local_file);
 
415
  if (opt_protocol)
 
416
    drizzle_options(drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
 
417
  if (!(drizzle_connect(drizzle,host,user,passwd,
 
418
                           database,opt_drizzle_port,opt_drizzle_unix_port,
 
419
                           0)))
411
420
  {
412
421
    ignore_errors=0;    /* NO RETURN FROM db_error */
413
 
    db_error(con, NULL, ret, NULL);
 
422
    db_error(drizzle);
414
423
  }
415
 
 
 
424
  drizzle->reconnect= 0;
416
425
  if (verbose)
417
426
    fprintf(stdout, "Selecting database %s\n", database);
418
 
 
419
 
  return con;
 
427
  if (drizzle_select_db(drizzle, database))
 
428
  {
 
429
    ignore_errors=0;
 
430
    db_error(drizzle);
 
431
  }
 
432
  return drizzle;
420
433
}
421
434
 
422
435
 
423
436
 
424
 
static void db_disconnect(char *host, drizzle_con_st *con)
 
437
static void db_disconnect(char *host, DRIZZLE *drizzle)
425
438
{
426
439
  if (verbose)
427
440
    fprintf(stdout, "Disconnecting from %s\n", host ? host : "localhost");
428
 
  drizzle_free(drizzle_con_drizzle(con));
 
441
  drizzle_close(drizzle);
429
442
}
430
443
 
431
444
 
432
445
 
433
 
static void safe_exit(int error, drizzle_con_st *con)
 
446
static void safe_exit(int error, DRIZZLE *drizzle)
434
447
{
435
448
  if (ignore_errors)
436
449
    return;
437
 
  if (con)
438
 
    drizzle_free(drizzle_con_drizzle(con));
 
450
  if (drizzle)
 
451
    drizzle_close(drizzle);
439
452
  exit(error);
440
453
}
441
454
 
442
455
 
443
456
 
444
 
static void db_error(drizzle_con_st *con, drizzle_result_st *result,
445
 
                     drizzle_return_t ret, char *table)
446
 
{
447
 
  if (ret == DRIZZLE_RETURN_ERROR_CODE)
448
 
  {
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);
454
 
  }
455
 
  else
456
 
  {
457
 
    my_printf_error(0,"Error: %d, %s%s%s", MYF(0), ret, drizzle_con_error(con),
458
 
                    table ? ", when using table: " : "", table ? table : "");
459
 
  }
460
 
 
461
 
  safe_exit(1, con);
 
457
static void db_error_with_table(DRIZZLE *drizzle, char *table)
 
458
{
 
459
  my_printf_error(0,"Error: %d, %s, when using table: %s",
 
460
      MYF(0), drizzle_errno(drizzle), drizzle_error(drizzle), table);
 
461
  safe_exit(1, drizzle);
 
462
}
 
463
 
 
464
 
 
465
 
 
466
static void db_error(DRIZZLE *drizzle)
 
467
{
 
468
  my_printf_error(0,"Error: %d %s", MYF(0), drizzle_errno(drizzle), drizzle_error(drizzle));
 
469
  safe_exit(1, drizzle);
462
470
}
463
471
 
464
472
 
474
482
    {
475
483
      /* char constant; escape */
476
484
      ptr+= sprintf(ptr, " %s '", statement); 
477
 
      ptr= field_escape(ptr,object,(uint32_t) strlen(object));
 
485
      ptr= field_escape(ptr,object,(uint) strlen(object));
478
486
      *ptr++= '\'';
479
487
    }
480
488
  }
488
496
** syntax errors from the SQL parser.
489
497
*/
490
498
 
491
 
static char *field_escape(char *to,const char *from,uint32_t length)
 
499
static char *field_escape(char *to,const char *from,uint length)
492
500
{
493
501
  const char *end;
494
 
  uint32_t end_backslashes=0;
 
502
  uint end_backslashes=0;
495
503
 
496
504
  for (end= from+length; from != end; from++)
497
505
  {
511
519
  return to;
512
520
}
513
521
 
 
522
int exitcode= 0;
 
523
 
 
524
extern "C"
514
525
void * worker_thread(void *arg)
515
526
{
516
527
  int error;
517
528
  char *raw_table_name= (char *)arg;
518
 
  drizzle_con_st *con= NULL;
519
 
  drizzle_result_st result;
520
 
  drizzle_return_t ret;
 
529
  DRIZZLE *drizzle= 0;
521
530
 
522
 
  if (!(con= db_connect(current_host,current_db,current_user,opt_password)))
 
531
  if (!(drizzle= db_connect(current_host,current_db,current_user,opt_password)))
523
532
  {
524
533
    goto error;
525
534
  }
526
535
 
527
 
  if (drizzle_query_str(con, &result,
528
 
                        "/*!40101 set @@character_set_database=binary */;",
529
 
                        &ret) == NULL ||
530
 
      ret != DRIZZLE_RETURN_OK)
 
536
  if (drizzle_query(drizzle, "/*!40101 set @@character_set_database=binary */;"))
531
537
  {
532
 
    db_error(con, &result, ret, NULL);
533
 
    /* We shall countinue here, if --force was given */
 
538
    db_error(drizzle); /* We shall countinue here, if --force was given */
534
539
    goto error;
535
540
  }
536
541
 
537
542
  /*
538
543
    We are not currently catching the error here.
539
544
  */
540
 
  if((error= write_to_table(raw_table_name, con)))
 
545
  if((error= write_to_table(raw_table_name, drizzle)))
541
546
    if (exitcode == 0)
542
547
      exitcode= error;
543
548
 
544
549
error:
545
 
  if (con)
546
 
    db_disconnect(current_host, con);
 
550
  if (drizzle)
 
551
    db_disconnect(current_host, drizzle);
547
552
 
548
553
  pthread_mutex_lock(&counter_mutex);
549
554
  counter--;
550
555
  pthread_cond_signal(&count_threshhold);
551
556
  pthread_mutex_unlock(&counter_mutex);
552
 
  internal::my_thread_end();
 
557
  my_thread_end();
553
558
 
554
559
  return 0;
555
560
}
561
566
  char **argv_to_free;
562
567
  MY_INIT(argv[0]);
563
568
 
564
 
  internal::load_defaults("drizzle",load_default_groups,&argc,&argv);
 
569
  load_defaults("drizzle",load_default_groups,&argc,&argv);
565
570
  /* argv is changed in the program */
566
571
  argv_to_free= argv;
567
572
  if (get_options(&argc, &argv))
568
573
  {
569
 
    internal::free_defaults(argv_to_free);
 
574
    free_defaults(argv_to_free);
570
575
    return(1);
571
576
  }
572
577
 
603
608
        counter--;
604
609
        pthread_mutex_unlock(&counter_mutex);
605
610
        fprintf(stderr,"%s: Could not create thread\n",
606
 
                internal::my_progname);
 
611
                my_progname);
607
612
      }
608
613
    }
609
614
 
626
631
  else
627
632
#endif
628
633
  {
629
 
    drizzle_con_st *con= 0;
630
 
    drizzle_result_st result;
631
 
    drizzle_return_t ret;
632
 
    if (!(con= db_connect(current_host,current_db,current_user,opt_password)))
633
 
    {
634
 
      internal::free_defaults(argv_to_free);
635
 
      return(1);
636
 
    }
637
 
 
638
 
    if (drizzle_query_str(con, &result,
639
 
                          "/*!40101 set @@character_set_database=binary */;",
640
 
                          &ret) == NULL ||
641
 
        ret != DRIZZLE_RETURN_OK)
642
 
    {
643
 
      db_error(con, &result, ret, NULL);
644
 
      /* We shall countinue here, if --force was given */
645
 
      return(1);
646
 
    }
647
 
 
648
 
    drizzle_result_free(&result);
 
634
    DRIZZLE *drizzle= 0;
 
635
    if (!(drizzle= db_connect(current_host,current_db,current_user,opt_password)))
 
636
    {
 
637
      free_defaults(argv_to_free);
 
638
      return(1); /* purecov: deadcode */
 
639
    }
 
640
 
 
641
    if (drizzle_query(drizzle, "/*!40101 set @@character_set_database=binary */;"))
 
642
    {
 
643
      db_error(drizzle); /* We shall countinue here, if --force was given */
 
644
      return(1);
 
645
    }
649
646
 
650
647
    if (lock_tables)
651
 
      lock_table(con, argc, argv);
 
648
      lock_table(drizzle, argc, argv);
652
649
    for (; *argv != NULL; argv++)
653
 
      if ((error= write_to_table(*argv, con)))
 
650
      if ((error= write_to_table(*argv, drizzle)))
654
651
        if (exitcode == 0)
655
652
          exitcode= error;
656
 
    db_disconnect(current_host, con);
 
653
    db_disconnect(current_host, drizzle);
657
654
  }
658
655
  free(opt_password);
659
 
  internal::free_defaults(argv_to_free);
660
 
  internal::my_end();
 
656
  free_defaults(argv_to_free);
 
657
  my_end(my_end_arg);
661
658
  return(exitcode);
662
659
}