~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzleimport.cc

  • Committer: Brian Aker
  • Date: 2009-05-15 17:06:35 UTC
  • mto: This revision was merged to the branch mainline in revision 1023.
  • Revision ID: brian@gaz-20090515170635-croy1u63a3gqdn9n
Dead convert functions for character sets.

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
 
37
39
/* Global Thread counter */
38
 
uint counter;
 
40
uint32_t counter;
39
41
pthread_mutex_t counter_mutex;
40
42
pthread_cond_t count_threshhold;
41
43
 
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);
 
44
static void db_error(drizzle_con_st *con, drizzle_result_st *result,
 
45
                     drizzle_return_t ret, char *table);
 
46
static char *field_escape(char *to,const char *from,uint32_t length);
45
47
static char *add_load_option(char *ptr,const char *object,
46
48
           const char *statement);
47
49
 
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_unique= 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 uint32_t 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 uint32_t opt_drizzle_port= 0;
 
62
static char * opt_drizzle_unix_port= 0;
60
63
static int64_t opt_ignore_lines= -1;
61
64
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
62
65
 
63
66
static struct my_option my_long_options[] =
64
67
{
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
68
  {"default-character-set", OPT_DEFAULT_CHARSET,
69
69
   "Set the default character set.", (char**) &default_charset,
70
70
   (char**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
105
105
  {"host", 'h', "Connect to host.", (char**) &current_host,
106
106
   (char**) &current_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
107
107
  {"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},
 
108
   (char**) &ignore_unique, (char**) &ignore_unique, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
109
109
  {"ignore-lines", OPT_IGN_LINES, "Ignore first n lines of data infile.",
110
110
   (char**) &opt_ignore_lines, (char**) &opt_ignore_lines, 0, GET_LL,
111
111
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
120
120
  {"low-priority", OPT_LOW_PRIORITY,
121
121
   "Use LOW_PRIORITY when updating the table.", (char**) &opt_low_priority,
122
122
   (char**) &opt_low_priority, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
123
 
  {"password", 'p',
 
123
  {"password", 'P',
124
124
   "Password to use when connecting to server. If password is not given it's asked from the tty.",
125
125
   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, "
 
126
  {"port", 'p', "Port number to use for connection or 0 for default to, in "
 
127
   "order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
128
128
   "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},
 
129
   0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
132
130
  {"protocol", OPT_DRIZZLE_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
133
131
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
134
132
  {"replace", 'r', "If duplicate unique key was found, replace old row.",
160
158
static void print_version(void)
161
159
{
162
160
  printf("%s  Ver %s Distrib %s, for %s (%s)\n" ,my_progname,
163
 
    IMPORT_VERSION, drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
 
161
    IMPORT_VERSION, drizzle_version(),SYSTEM_TYPE,MACHINE_TYPE);
164
162
}
165
163
 
166
164
 
177
175
file. The SQL command 'LOAD DATA INFILE' is used to import the rows.\n");
178
176
 
179
177
  printf("\nUsage: %s [OPTIONS] database textfile...",my_progname);
180
 
  print_defaults("my",load_default_groups);
 
178
  print_defaults("drizzle",load_default_groups);
181
179
  my_print_help(my_long_options);
182
180
  my_print_variables(my_long_options);
183
181
}
184
182
 
185
 
static bool
186
 
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
187
 
         char *argument)
 
183
extern "C"
 
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
272
  if (strcmp(default_charset, charset_info->csname) &&
238
 
      !(charset_info= get_charset_by_csname(default_charset,
239
 
                MY_CS_PRIMARY, MYF(MY_WME))))
 
273
      !(charset_info= get_charset_by_csname(default_charset, MY_CS_PRIMARY)))
240
274
    exit(1);
241
275
  if (*argc < 2)
242
276
  {
246
280
  current_db= *((*argv)++);
247
281
  (*argc)--;
248
282
  if (tty_password)
249
 
    opt_password=get_tty_password(NULL);
 
283
    opt_password=client_get_tty_password(NULL);
250
284
  return(0);
251
285
}
252
286
 
253
287
 
254
288
 
255
 
static int write_to_table(char *filename, DRIZZLE *drizzle)
 
289
static int write_to_table(char *filename, drizzle_con_st *con)
256
290
{
257
291
  char tablename[FN_REFLEN], hard_path[FN_REFLEN],
258
292
       sql_statement[FN_REFLEN*16+256], *end;
 
293
  drizzle_result_st result;
 
294
  drizzle_return_t ret;
259
295
 
260
296
  fn_format(tablename, filename, "", "", 1 | 2); /* removes path & ext. */
261
297
  if (!opt_local_file)
262
 
    my_stpcpy(hard_path,filename);
 
298
    strcpy(hard_path,filename);
263
299
  else
264
300
    my_load_path(hard_path, filename, NULL); /* filename includes the path */
265
301
 
272
308
#else
273
309
    sprintf(sql_statement, "DELETE FROM %s", tablename);
274
310
#endif
275
 
    if (drizzle_query(drizzle, sql_statement))
 
311
    if (drizzle_query_str(con, &result, sql_statement, &ret) == NULL ||
 
312
        ret != DRIZZLE_RETURN_OK)
276
313
    {
277
 
      db_error_with_table(drizzle, tablename);
 
314
      db_error(con, &result, ret, tablename);
278
315
      return(1);
279
316
    }
 
317
    drizzle_result_free(&result);
280
318
  }
281
 
  to_unix_path(hard_path);
282
319
  if (verbose)
283
320
  {
284
321
    if (opt_local_file)
293
330
    opt_local_file ? "LOCAL" : "", hard_path);
294
331
  end= strchr(sql_statement, '\0');
295
332
  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);
 
333
    end= strcpy(end, " REPLACE")+8;
 
334
  if (ignore_unique)
 
335
    end= strcpy(end, " IGNORE")+7;
 
336
 
 
337
  end+= sprintf(end, " INTO TABLE %s", tablename);
300
338
 
301
339
  if (fields_terminated || enclosed || opt_enclosed || escaped)
302
 
      end= my_stpcpy(end, " FIELDS");
 
340
      end= strcpy(end, " FIELDS")+7;
303
341
  end= add_load_option(end, fields_terminated, " TERMINATED BY");
304
342
  end= add_load_option(end, enclosed, " ENCLOSED BY");
305
343
  end= add_load_option(end, opt_enclosed,
307
345
  end= add_load_option(end, escaped, " ESCAPED BY");
308
346
  end= add_load_option(end, lines_terminated, " LINES TERMINATED BY");
309
347
  if (opt_ignore_lines >= 0)
310
 
    end= my_stpcpy(int64_t10_to_str(opt_ignore_lines,
311
 
          my_stpcpy(end, " IGNORE "),10), " LINES");
 
348
  {
 
349
    end= strcpy(end, " IGNORE ")+8;
 
350
    ostringstream buffer;
 
351
    buffer << opt_ignore_lines;
 
352
    end= strcpy(end, buffer.str().c_str())+ buffer.str().size();
 
353
    end= strcpy(end, " LINES")+6;
 
354
  }
312
355
  if (opt_columns)
313
 
    end= my_stpcpy(my_stpcpy(my_stpcpy(end, " ("), opt_columns), ")");
 
356
  {
 
357
    end= strcpy(end, " (")+2;
 
358
    end= strcpy(end, opt_columns)+strlen(opt_columns);
 
359
    end= strcpy(end, ")")+1;
 
360
  }
314
361
  *end= '\0';
315
362
 
316
 
  if (drizzle_query(drizzle, sql_statement))
 
363
  if (drizzle_query_str(con, &result, sql_statement, &ret) == NULL ||
 
364
      ret != DRIZZLE_RETURN_OK)
317
365
  {
318
 
    db_error_with_table(drizzle, tablename);
 
366
    db_error(con, &result, ret, tablename);
319
367
    return(1);
320
368
  }
321
369
  if (!silent)
322
370
  {
323
 
    if (drizzle_info(drizzle)) /* If NULL-pointer, print nothing */
 
371
    if (strcmp(drizzle_result_info(&result), ""))
324
372
    {
325
373
      fprintf(stdout, "%s.%s: %s\n", current_db, tablename,
326
 
        drizzle_info(drizzle));
 
374
        drizzle_result_info(&result));
327
375
    }
328
376
  }
 
377
  drizzle_result_free(&result);
329
378
  return(0);
330
379
}
331
380
 
332
381
 
333
 
 
334
 
static void lock_table(DRIZZLE *drizzle, int tablecount, char **raw_tablename)
 
382
static void lock_table(drizzle_con_st *con, int tablecount, char **raw_tablename)
335
383
{
336
384
  string query;
337
385
  int i;
338
386
  char tablename[FN_REFLEN];
 
387
  drizzle_result_st result;
 
388
  drizzle_return_t ret;
339
389
 
340
390
  if (verbose)
341
391
    fprintf(stdout, "Locking tables for write\n");
346
396
    query.append(tablename);
347
397
    query.append(" WRITE,");
348
398
  }
349
 
  if (drizzle_real_query(drizzle, query.c_str(), query.length()-1))
350
 
    db_error(drizzle); /* We shall countinue here, if --force was given */
 
399
  if (drizzle_query(con, &result, query.c_str(), query.length()-1,
 
400
                    &ret) == NULL ||
 
401
      ret != DRIZZLE_RETURN_OK)
 
402
  {
 
403
    db_error(con, &result, ret, NULL);
 
404
    /* We shall countinue here, if --force was given */
 
405
    return;
 
406
  }
 
407
  drizzle_result_free(&result);
351
408
}
352
409
 
353
410
 
354
 
 
355
 
 
356
 
static DRIZZLE *db_connect(char *host, char *database,
357
 
                         char *user, char *passwd)
 
411
static drizzle_con_st *db_connect(char *host, char *database,
 
412
                                  char *user, char *passwd)
358
413
{
359
 
  DRIZZLE *drizzle;
 
414
  drizzle_st *drizzle;
 
415
  drizzle_con_st *con;
 
416
  drizzle_return_t ret;
 
417
 
360
418
  if (verbose)
361
419
    fprintf(stdout, "Connecting to %s\n", host ? host : "localhost");
362
420
  if (!(drizzle= drizzle_create(NULL)))
363
421
    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)))
 
422
  if (!(con= drizzle_con_add_tcp(drizzle,NULL,host,opt_drizzle_port,user,passwd,
 
423
                                 database, DRIZZLE_CON_NONE)))
 
424
  {
 
425
    return 0;
 
426
  }
 
427
 
 
428
  if ((ret= drizzle_con_connect(con)) != DRIZZLE_RETURN_OK)
374
429
  {
375
430
    ignore_errors=0;    /* NO RETURN FROM db_error */
376
 
    db_error(drizzle);
 
431
    db_error(con, NULL, ret, NULL);
377
432
  }
378
 
  drizzle->reconnect= 0;
 
433
 
379
434
  if (verbose)
380
435
    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;
 
436
 
 
437
  return con;
387
438
}
388
439
 
389
440
 
390
441
 
391
 
static void db_disconnect(char *host, DRIZZLE *drizzle)
 
442
static void db_disconnect(char *host, drizzle_con_st *con)
392
443
{
393
444
  if (verbose)
394
445
    fprintf(stdout, "Disconnecting from %s\n", host ? host : "localhost");
395
 
  drizzle_close(drizzle);
 
446
  drizzle_free(drizzle_con_drizzle(con));
396
447
}
397
448
 
398
449
 
399
450
 
400
 
static void safe_exit(int error, DRIZZLE *drizzle)
 
451
static void safe_exit(int error, drizzle_con_st *con)
401
452
{
402
453
  if (ignore_errors)
403
454
    return;
404
 
  if (drizzle)
405
 
    drizzle_close(drizzle);
 
455
  if (con)
 
456
    drizzle_free(drizzle_con_drizzle(con));
406
457
  exit(error);
407
458
}
408
459
 
409
460
 
410
461
 
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);
 
462
static void db_error(drizzle_con_st *con, drizzle_result_st *result,
 
463
                     drizzle_return_t ret, char *table)
 
464
{
 
465
  if (ret == DRIZZLE_RETURN_ERROR_CODE)
 
466
  {
 
467
    my_printf_error(0,"Error: %d, %s%s%s", MYF(0),
 
468
                    drizzle_result_error_code(result),
 
469
                    drizzle_result_error(result),
 
470
                    table ? ", when using table: " : "", table ? table : "");
 
471
    drizzle_result_free(result);
 
472
  }
 
473
  else
 
474
  {
 
475
    my_printf_error(0,"Error: %d, %s%s%s", MYF(0), ret, drizzle_con_error(con),
 
476
                    table ? ", when using table: " : "", table ? table : "");
 
477
  }
 
478
 
 
479
  safe_exit(1, con);
424
480
}
425
481
 
426
482
 
431
487
  {
432
488
    /* Don't escape hex constants */
433
489
    if (object[0] == '0' && (object[1] == 'x' || object[1] == 'X'))
434
 
      ptr= strxmov(ptr," ",statement," ",object,NULL);
 
490
      ptr+= sprintf(ptr, " %s %s", statement, object);
435
491
    else
436
492
    {
437
493
      /* char constant; escape */
438
 
      ptr= strxmov(ptr," ",statement," '",NULL);
439
 
      ptr= field_escape(ptr,object,(uint) strlen(object));
 
494
      ptr+= sprintf(ptr, " %s '", statement); 
 
495
      ptr= field_escape(ptr,object,(uint32_t) strlen(object));
440
496
      *ptr++= '\'';
441
497
    }
442
498
  }
450
506
** syntax errors from the SQL parser.
451
507
*/
452
508
 
453
 
static char *field_escape(char *to,const char *from,uint length)
 
509
static char *field_escape(char *to,const char *from,uint32_t length)
454
510
{
455
511
  const char *end;
456
 
  uint end_backslashes=0;
 
512
  uint32_t end_backslashes=0;
457
513
 
458
514
  for (end= from+length; from != end; from++)
459
515
  {
469
525
  }
470
526
  /* Add missing backslashes if user has specified odd number of backs.*/
471
527
  if (end_backslashes)
472
 
    *to++= '\\';         
 
528
    *to++= '\\';
473
529
  return to;
474
530
}
475
531
 
476
532
int exitcode= 0;
477
533
 
478
 
static void * worker_thread(void *arg)
 
534
extern "C"
 
535
void * worker_thread(void *arg)
479
536
{
480
537
  int error;
481
538
  char *raw_table_name= (char *)arg;
482
 
  DRIZZLE *drizzle= 0;
 
539
  drizzle_con_st *con= NULL;
 
540
  drizzle_result_st result;
 
541
  drizzle_return_t ret;
483
542
 
484
 
  if (!(drizzle= db_connect(current_host,current_db,current_user,opt_password)))
 
543
  if (!(con= db_connect(current_host,current_db,current_user,opt_password)))
485
544
  {
486
545
    goto error;
487
546
  }
488
547
 
489
 
  if (drizzle_query(drizzle, "/*!40101 set @@character_set_database=binary */;"))
 
548
  if (drizzle_query_str(con, &result,
 
549
                        "/*!40101 set @@character_set_database=binary */;",
 
550
                        &ret) == NULL ||
 
551
      ret != DRIZZLE_RETURN_OK)
490
552
  {
491
 
    db_error(drizzle); /* We shall countinue here, if --force was given */
 
553
    db_error(con, &result, ret, NULL);
 
554
    /* We shall countinue here, if --force was given */
492
555
    goto error;
493
556
  }
494
557
 
495
558
  /*
496
559
    We are not currently catching the error here.
497
560
  */
498
 
  if((error= write_to_table(raw_table_name, drizzle)))
 
561
  if((error= write_to_table(raw_table_name, con)))
499
562
    if (exitcode == 0)
500
563
      exitcode= error;
501
564
 
502
565
error:
503
 
  if (drizzle)
504
 
    db_disconnect(current_host, drizzle);
 
566
  if (con)
 
567
    db_disconnect(current_host, con);
505
568
 
506
569
  pthread_mutex_lock(&counter_mutex);
507
570
  counter--;
519
582
  char **argv_to_free;
520
583
  MY_INIT(argv[0]);
521
584
 
522
 
  load_defaults("my",load_default_groups,&argc,&argv);
 
585
  load_defaults("drizzle",load_default_groups,&argc,&argv);
523
586
  /* argv is changed in the program */
524
587
  argv_to_free= argv;
525
588
  if (get_options(&argc, &argv))
584
647
  else
585
648
#endif
586
649
  {
587
 
    DRIZZLE *drizzle= 0;
588
 
    if (!(drizzle= db_connect(current_host,current_db,current_user,opt_password)))
 
650
    drizzle_con_st *con= 0;
 
651
    drizzle_result_st result;
 
652
    drizzle_return_t ret;
 
653
    if (!(con= db_connect(current_host,current_db,current_user,opt_password)))
589
654
    {
590
655
      free_defaults(argv_to_free);
591
656
      return(1); /* purecov: deadcode */
592
657
    }
593
658
 
594
 
    if (drizzle_query(drizzle, "/*!40101 set @@character_set_database=binary */;"))
 
659
    if (drizzle_query_str(con, &result,
 
660
                          "/*!40101 set @@character_set_database=binary */;",
 
661
                          &ret) == NULL ||
 
662
        ret != DRIZZLE_RETURN_OK)
595
663
    {
596
 
      db_error(drizzle); /* We shall countinue here, if --force was given */
 
664
      db_error(con, &result, ret, NULL);
 
665
      /* We shall countinue here, if --force was given */
597
666
      return(1);
598
667
    }
599
668
 
 
669
    drizzle_result_free(&result);
 
670
 
600
671
    if (lock_tables)
601
 
      lock_table(drizzle, argc, argv);
 
672
      lock_table(con, argc, argv);
602
673
    for (; *argv != NULL; argv++)
603
 
      if ((error= write_to_table(*argv, drizzle)))
 
674
      if ((error= write_to_table(*argv, con)))
604
675
        if (exitcode == 0)
605
676
          exitcode= error;
606
 
    db_disconnect(current_host, drizzle);
 
677
    db_disconnect(current_host, con);
607
678
  }
608
679
  free(opt_password);
609
680
  free_defaults(argv_to_free);