~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzleimport.cc

  • Committer: Mark Atwood
  • Date: 2008-10-16 11:33:16 UTC
  • mto: (520.1.13 drizzle)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: mark@fallenpegasus.com-20081016113316-ff6jdt31ck90sjdh
an implemention of the errmsg plugin

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
30
#include <string>
30
31
 
31
32
#include "client_priv.h"
57
58
static uint     opt_drizzle_port= 0, opt_protocol= 0;
58
59
static char * opt_drizzle_unix_port=0;
59
60
static int64_t opt_ignore_lines= -1;
60
 
static const CHARSET_INFO *charset_info= &my_charset_latin1;
 
61
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
61
62
 
62
63
static struct my_option my_long_options[] =
63
64
{
190
191
    if (argument)
191
192
    {
192
193
      char *start=argument;
193
 
      my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
 
194
      free(opt_password);
194
195
      opt_password=my_strdup(argument,MYF(MY_FAE));
195
196
      while (*argument) *argument++= 'x';    /* Destroy argument */
196
197
      if (*start)
201
202
      tty_password= 1;
202
203
    break;
203
204
  case OPT_DRIZZLE_PROTOCOL:
204
 
    opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
205
 
                                    opt->name);
206
205
    break;
207
206
  case 'V': print_version(); exit(0);
208
207
  case 'I':
247
246
  current_db= *((*argv)++);
248
247
  (*argc)--;
249
248
  if (tty_password)
250
 
    opt_password=get_tty_password(NullS);
 
249
    opt_password=get_tty_password(NULL);
251
250
  return(0);
252
251
}
253
252
 
260
259
 
261
260
  fn_format(tablename, filename, "", "", 1 | 2); /* removes path & ext. */
262
261
  if (!opt_local_file)
263
 
    stpcpy(hard_path,filename);
 
262
    my_stpcpy(hard_path,filename);
264
263
  else
265
264
    my_load_path(hard_path, filename, NULL); /* filename includes the path */
266
265
 
292
291
  sprintf(sql_statement, "LOAD DATA %s %s INFILE '%s'",
293
292
    opt_low_priority ? "LOW_PRIORITY" : "",
294
293
    opt_local_file ? "LOCAL" : "", hard_path);
295
 
  end= strend(sql_statement);
 
294
  end= strchr(sql_statement, '\0');
296
295
  if (opt_replace)
297
 
    end= stpcpy(end, " REPLACE");
 
296
    end= my_stpcpy(end, " REPLACE");
298
297
  if (ignore)
299
 
    end= stpcpy(end, " IGNORE");
300
 
  end= stpcpy(stpcpy(end, " INTO TABLE "), tablename);
 
298
    end= my_stpcpy(end, " IGNORE");
 
299
  end= my_stpcpy(my_stpcpy(end, " INTO TABLE "), tablename);
301
300
 
302
301
  if (fields_terminated || enclosed || opt_enclosed || escaped)
303
 
      end= stpcpy(end, " FIELDS");
 
302
      end= my_stpcpy(end, " FIELDS");
304
303
  end= add_load_option(end, fields_terminated, " TERMINATED BY");
305
304
  end= add_load_option(end, enclosed, " ENCLOSED BY");
306
305
  end= add_load_option(end, opt_enclosed,
308
307
  end= add_load_option(end, escaped, " ESCAPED BY");
309
308
  end= add_load_option(end, lines_terminated, " LINES TERMINATED BY");
310
309
  if (opt_ignore_lines >= 0)
311
 
    end= stpcpy(int64_t10_to_str(opt_ignore_lines,
312
 
          stpcpy(end, " IGNORE "),10), " LINES");
 
310
    end= my_stpcpy(int64_t10_to_str(opt_ignore_lines,
 
311
          my_stpcpy(end, " IGNORE "),10), " LINES");
313
312
  if (opt_columns)
314
 
    end= stpcpy(stpcpy(stpcpy(end, " ("), opt_columns), ")");
 
313
    end= my_stpcpy(my_stpcpy(my_stpcpy(end, " ("), opt_columns), ")");
315
314
  *end= '\0';
316
315
 
317
316
  if (drizzle_query(drizzle, sql_statement))
363
362
  if (!(drizzle= drizzle_create(NULL)))
364
363
    return 0;
365
364
  if (opt_compress)
366
 
    drizzle_options(drizzle,DRIZZLE_OPT_COMPRESS,NullS);
 
365
    drizzle_options(drizzle,DRIZZLE_OPT_COMPRESS,NULL);
367
366
  if (opt_local_file)
368
367
    drizzle_options(drizzle,DRIZZLE_OPT_LOCAL_INFILE,
369
368
      (char*) &opt_local_file);
432
431
  {
433
432
    /* Don't escape hex constants */
434
433
    if (object[0] == '0' && (object[1] == 'x' || object[1] == 'X'))
435
 
      ptr= strxmov(ptr," ",statement," ",object,NullS);
 
434
      ptr= strxmov(ptr," ",statement," ",object,NULL);
436
435
    else
437
436
    {
438
437
      /* char constant; escape */
439
 
      ptr= strxmov(ptr," ",statement," '",NullS);
 
438
      ptr= strxmov(ptr," ",statement," '",NULL);
440
439
      ptr= field_escape(ptr,object,(uint) strlen(object));
441
440
      *ptr++= '\'';
442
441
    }
482
481
  char *raw_table_name= (char *)arg;
483
482
  DRIZZLE *drizzle= 0;
484
483
 
485
 
  if (drizzle_thread_init())
486
 
    goto error;
487
 
 
488
484
  if (!(drizzle= db_connect(current_host,current_db,current_user,opt_password)))
489
485
  {
490
486
    goto error;
541
537
    pthread_attr_setdetachstate(&attr,
542
538
                                PTHREAD_CREATE_DETACHED);
543
539
 
544
 
    VOID(pthread_mutex_init(&counter_mutex, NULL));
545
 
    VOID(pthread_cond_init(&count_threshhold, NULL));
 
540
    pthread_mutex_init(&counter_mutex, NULL);
 
541
    pthread_cond_init(&count_threshhold, NULL);
546
542
 
547
543
    for (counter= 0; *argv != NULL; argv++) /* Loop through tables */
548
544
    {
581
577
      pthread_cond_timedwait(&count_threshhold, &counter_mutex, &abstime);
582
578
    }
583
579
    pthread_mutex_unlock(&counter_mutex);
584
 
    VOID(pthread_mutex_destroy(&counter_mutex));
585
 
    VOID(pthread_cond_destroy(&count_threshhold));
 
580
    pthread_mutex_destroy(&counter_mutex);
 
581
    pthread_cond_destroy(&count_threshhold);
586
582
    pthread_attr_destroy(&attr);
587
583
  }
588
584
  else
609
605
          exitcode= error;
610
606
    db_disconnect(current_host, drizzle);
611
607
  }
612
 
  my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
 
608
  free(opt_password);
613
609
  free_defaults(argv_to_free);
614
610
  my_end(my_end_arg);
615
611
  return(exitcode);