~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzleimport.cc

  • Committer: Toru Maesaka
  • Date: 2008-12-17 07:16:37 UTC
  • mto: (685.1.40 devel) (713.1.5 devel)
  • mto: This revision was merged to the branch mainline in revision 713.
  • Revision ID: dev@torum.net-20081217071637-7j9040w7lpms77r2
Removed my_time() and added error checking

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
 
35
34
using namespace std;
124
123
   "Password to use when connecting to server. If password is not given it's asked from the tty.",
125
124
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
126
125
  {"port", 'P', "Port number to use for connection or 0 for default to, in "
127
 
   "order of preference, my.cnf, $DRIZZLE_TCP_PORT, "
 
126
   "order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
128
127
   "built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
129
128
   (char**) &opt_drizzle_port,
130
129
   (char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
177
176
file. The SQL command 'LOAD DATA INFILE' is used to import the rows.\n");
178
177
 
179
178
  printf("\nUsage: %s [OPTIONS] database textfile...",my_progname);
180
 
  print_defaults("my",load_default_groups);
 
179
  print_defaults("drizzle",load_default_groups);
181
180
  my_print_help(my_long_options);
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
extern "C"
 
185
bool get_one_option(int optid, const struct my_option *, char *argument)
188
186
{
189
187
  switch(optid) {
190
188
  case 'p':
191
189
    if (argument)
192
190
    {
193
191
      char *start=argument;
194
 
      free(opt_password);
195
 
      opt_password=my_strdup(argument,MYF(MY_FAE));
 
192
      if (opt_password)
 
193
        free(opt_password);
 
194
      opt_password = strdup(argument);
 
195
      if (opt_password == NULL)
 
196
      {
 
197
        fprintf(stderr, "Memory allocation error while copying password. "
 
198
                        "Aborting.\n");
 
199
        exit(ENOMEM);
 
200
      }
196
201
      while (*argument) *argument++= 'x';    /* Destroy argument */
197
202
      if (*start)
198
 
  start[1]=0;        /* Cut length of argument */
 
203
        start[1]=0;        /* Cut length of argument */
199
204
      tty_password= 0;
200
205
    }
201
206
    else
259
264
 
260
265
  fn_format(tablename, filename, "", "", 1 | 2); /* removes path & ext. */
261
266
  if (!opt_local_file)
262
 
    my_stpcpy(hard_path,filename);
 
267
    strcpy(hard_path,filename);
263
268
  else
264
269
    my_load_path(hard_path, filename, NULL); /* filename includes the path */
265
270
 
293
298
    opt_local_file ? "LOCAL" : "", hard_path);
294
299
  end= strchr(sql_statement, '\0');
295
300
  if (opt_replace)
296
 
    end= my_stpcpy(end, " REPLACE");
 
301
    end= strcpy(end, " REPLACE")+8;
297
302
  if (ignore)
298
 
    end= my_stpcpy(end, " IGNORE");
299
 
  end= my_stpcpy(my_stpcpy(end, " INTO TABLE "), tablename);
 
303
    end= strcpy(end, " IGNORE")+7;
 
304
 
 
305
  end+= sprintf(end, " INTO TABLE %s", tablename);
300
306
 
301
307
  if (fields_terminated || enclosed || opt_enclosed || escaped)
302
 
      end= my_stpcpy(end, " FIELDS");
 
308
      end= strcpy(end, " FIELDS")+7;
303
309
  end= add_load_option(end, fields_terminated, " TERMINATED BY");
304
310
  end= add_load_option(end, enclosed, " ENCLOSED BY");
305
311
  end= add_load_option(end, opt_enclosed,
307
313
  end= add_load_option(end, escaped, " ESCAPED BY");
308
314
  end= add_load_option(end, lines_terminated, " LINES TERMINATED BY");
309
315
  if (opt_ignore_lines >= 0)
310
 
    end= my_stpcpy(int64_t10_to_str(opt_ignore_lines,
311
 
          my_stpcpy(end, " IGNORE "),10), " LINES");
 
316
  {
 
317
    end= strcpy(end, " IGNORE ")+8;
 
318
    end= int64_t2str(opt_ignore_lines, end, 10);
 
319
    end= strcpy(end, " LINES")+6;
 
320
  }
312
321
  if (opt_columns)
313
 
    end= my_stpcpy(my_stpcpy(my_stpcpy(end, " ("), opt_columns), ")");
 
322
  {
 
323
    end= strcpy(end, " (")+2;
 
324
    end= strcpy(end, opt_columns)+strlen(opt_columns);
 
325
    end= strcpy(end, ")")+1;
 
326
  }
314
327
  *end= '\0';
315
328
 
316
329
  if (drizzle_query(drizzle, sql_statement))
431
444
  {
432
445
    /* Don't escape hex constants */
433
446
    if (object[0] == '0' && (object[1] == 'x' || object[1] == 'X'))
434
 
      ptr= strxmov(ptr," ",statement," ",object,NULL);
 
447
      ptr+= sprintf(ptr, " %s %s", statement, object);
435
448
    else
436
449
    {
437
450
      /* char constant; escape */
438
 
      ptr= strxmov(ptr," ",statement," '",NULL);
 
451
      ptr+= sprintf(ptr, " %s '", statement); 
439
452
      ptr= field_escape(ptr,object,(uint) strlen(object));
440
453
      *ptr++= '\'';
441
454
    }
469
482
  }
470
483
  /* Add missing backslashes if user has specified odd number of backs.*/
471
484
  if (end_backslashes)
472
 
    *to++= '\\';         
 
485
    *to++= '\\';
473
486
  return to;
474
487
}
475
488
 
476
489
int exitcode= 0;
477
490
 
478
 
static void * worker_thread(void *arg)
 
491
extern "C"
 
492
void * worker_thread(void *arg)
479
493
{
480
494
  int error;
481
495
  char *raw_table_name= (char *)arg;
519
533
  char **argv_to_free;
520
534
  MY_INIT(argv[0]);
521
535
 
522
 
  load_defaults("my",load_default_groups,&argc,&argv);
 
536
  load_defaults("drizzle",load_default_groups,&argc,&argv);
523
537
  /* argv is changed in the program */
524
538
  argv_to_free= argv;
525
539
  if (get_options(&argc, &argv))