~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzledump.cc

Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
#include <drizzled/error.h>
45
45
 
46
46
using namespace std;
 
47
using namespace drizzled;
47
48
 
48
49
/* Exit codes */
49
50
 
400
401
 
401
402
static void print_version(void)
402
403
{
403
 
  printf(_("%s  Drizzle %s libdrizzle %s, for %s-%s (%s)\n"), my_progname,
 
404
  printf(_("%s  Drizzle %s libdrizzle %s, for %s-%s (%s)\n"), internal::my_progname,
404
405
         VERSION, drizzle_version(), HOST_VENDOR, HOST_OS, HOST_CPU);
405
406
} /* print_version */
406
407
 
407
408
 
408
409
static void short_usage_sub(void)
409
410
{
410
 
  printf(_("Usage: %s [OPTIONS] database [tables]\n"), my_progname);
 
411
  printf(_("Usage: %s [OPTIONS] database [tables]\n"), internal::my_progname);
411
412
  printf(_("OR     %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n"),
412
 
         my_progname);
413
 
  printf(_("OR     %s [OPTIONS] --all-databases [OPTIONS]\n"), my_progname);
 
413
         internal::my_progname);
 
414
  printf(_("OR     %s [OPTIONS] --all-databases [OPTIONS]\n"), internal::my_progname);
414
415
}
415
416
 
416
417
 
421
422
  puts(_("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n"));
422
423
  puts(_("Dumps definitions and data from a Drizzle database server"));
423
424
  short_usage_sub();
424
 
  print_defaults("drizzle",load_default_groups);
 
425
  internal::print_defaults("drizzle",load_default_groups);
425
426
  my_print_help(my_long_options);
426
427
  my_print_variables(my_long_options);
427
428
} /* usage */
430
431
static void short_usage(void)
431
432
{
432
433
  short_usage_sub();
433
 
  printf(_("For more options, use %s --help\n"), my_progname);
 
434
  printf(_("For more options, use %s --help\n"), internal::my_progname);
434
435
}
435
436
 
436
437
static void write_header(FILE *sql_file, char *db_name)
501
502
      if (opt_dump_date)
502
503
      {
503
504
        char time_str[20];
504
 
        get_date(time_str, GETDATE_DATE_TIME, 0);
 
505
        internal::get_date(time_str, GETDATE_DATE_TIME, 0);
505
506
        fprintf(sql_file, "-- Dump completed on %s\n",
506
507
                time_str);
507
508
      }
513
514
} /* write_footer */
514
515
 
515
516
 
516
 
extern "C" bool get_one_option(int optid, const struct my_option *, char *argument);
517
 
 
518
 
extern "C" bool get_one_option(int optid, const struct my_option *, char *argument)
 
517
static bool get_one_option(int optid, const struct my_option *, char *argument)
519
518
{
520
519
  char *endchar= NULL;
521
520
  uint64_t temp_drizzle_port= 0;
674
673
  int ho_error;
675
674
 
676
675
  md_result_file= stdout;
677
 
  load_defaults("drizzle",load_default_groups,argc,argv);
 
676
  internal::load_defaults("drizzle",load_default_groups,argc,argv);
678
677
  defaults_argv= *argv;
679
678
 
680
679
  if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
684
683
                fields_terminated))
685
684
  {
686
685
    fprintf(stderr,
687
 
            _("%s: You must use option --tab with --fields-...\n"), my_progname);
 
686
            _("%s: You must use option --tab with --fields-...\n"), internal::my_progname);
688
687
    return(EX_USAGE);
689
688
  }
690
689
 
691
690
  if (opt_single_transaction && opt_lock_all_tables)
692
691
  {
693
692
    fprintf(stderr, _("%s: You can't use --single-transaction and "
694
 
            "--lock-all-tables at the same time.\n"), my_progname);
 
693
            "--lock-all-tables at the same time.\n"), internal::my_progname);
695
694
    return(EX_USAGE);
696
695
  }
697
696
  if (enclosed && opt_enclosed)
698
697
  {
699
 
    fprintf(stderr, _("%s: You can't use ..enclosed.. and ..optionally-enclosed.. at the same time.\n"), my_progname);
 
698
    fprintf(stderr, _("%s: You can't use ..enclosed.. and ..optionally-enclosed.. at the same time.\n"), internal::my_progname);
700
699
    return(EX_USAGE);
701
700
  }
702
701
  if ((opt_databases || opt_alldbs) && path)
703
702
  {
704
703
    fprintf(stderr,
705
704
            _("%s: --databases or --all-databases can't be used with --tab.\n"),
706
 
            my_progname);
 
705
            internal::my_progname);
707
706
    return(EX_USAGE);
708
707
  }
709
708
  if ((*argc < 1 && !opt_alldbs) || (*argc > 0 && opt_alldbs))
760
759
  vsnprintf(buffer, sizeof(buffer), fmt_reason, args);
761
760
  va_end(args);
762
761
 
763
 
  fprintf(stderr, "%s: %s\n", my_progname, buffer);
 
762
  fprintf(stderr, "%s: %s\n", internal::my_progname, buffer);
764
763
  fflush(stderr);
765
764
 
766
765
  ignore_errors= 0; /* force the exit */
794
793
  vsnprintf(buffer, sizeof(buffer), fmt_reason, args);
795
794
  va_end(args);
796
795
 
797
 
  fprintf(stderr, "%s: %s\n", my_progname, buffer);
 
796
  fprintf(stderr, "%s: %s\n", internal::my_progname, buffer);
798
797
  fflush(stderr);
799
798
 
800
799
  maybe_exit(error_num);
873
872
{
874
873
  FILE* res;
875
874
  char filename[FN_REFLEN], tmp_path[FN_REFLEN];
876
 
  convert_dirname(tmp_path,path,NULL);
877
 
  res= fopen(fn_format(filename, table, tmp_path, ".sql", 4), "w");
 
875
  internal::convert_dirname(tmp_path,path,NULL);
 
876
  res= fopen(internal::fn_format(filename, table, tmp_path, ".sql", 4), "w");
878
877
 
879
878
  return res;
880
879
}
886
885
    fclose(md_result_file);
887
886
  free(opt_password);
888
887
  if (defaults_argv)
889
 
    free_defaults(defaults_argv);
890
 
  my_end();
 
888
    internal::free_defaults(defaults_argv);
 
889
  internal::my_end();
891
890
}
892
891
 
893
892
 
1419
1418
  else
1420
1419
  {
1421
1420
    verbose_msg(_("%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n"),
1422
 
                my_progname, drizzle_con_error(&dcon));
 
1421
                internal::my_progname, drizzle_con_error(&dcon));
1423
1422
 
1424
1423
    snprintf(query_buff, sizeof(query_buff), "show fields from %s",
1425
1424
             result_table);
1526
1525
      if (drizzleclient_query_with_error_report(&dcon, &result, buff, false))
1527
1526
      {
1528
1527
        fprintf(stderr, _("%s: Can't get keys for table %s\n"),
1529
 
                my_progname, result_table);
 
1528
                internal::my_progname, result_table);
1530
1529
        if (path)
1531
1530
          fclose(sql_file);
1532
1531
        return false;
1792
1791
      Convert the path to native os format
1793
1792
      and resolve to the full filepath.
1794
1793
    */
1795
 
    convert_dirname(tmp_path,path,NULL);
1796
 
    my_load_path(tmp_path, tmp_path, NULL);
1797
 
    fn_format(filename, table, tmp_path, ".txt", MYF(MY_UNPACK_FILENAME));
 
1794
    internal::convert_dirname(tmp_path,path,NULL);
 
1795
    internal::my_load_path(tmp_path, tmp_path, NULL);
 
1796
    internal::fn_format(filename, table, tmp_path, ".txt", MYF(MY_UNPACK_FILENAME));
1798
1797
 
1799
1798
    /* Must delete the file that 'INTO OUTFILE' will write to */
1800
 
    my_delete(filename, MYF(0));
 
1799
    internal::my_delete(filename, MYF(0));
1801
1800
 
1802
1801
    /* now build the query string */
1803
1802
 
1888
1887
    if (drizzle_result_column_count(&result) != num_fields)
1889
1888
    {
1890
1889
      fprintf(stderr,_("%s: Error in field count for table: %s !  Aborting.\n"),
1891
 
              my_progname, result_table);
 
1890
              internal::my_progname, result_table);
1892
1891
      error= EX_CONSCHECK;
1893
1892
      drizzle_result_free(&result);
1894
1893
      goto err;
1932
1931
        {
1933
1932
          fprintf(stderr,
1934
1933
                _("%s: Error reading rows for table: %s (%d:%s) ! Aborting.\n"),
1935
 
                  my_progname, result_table, ret, drizzle_con_error(&dcon));
 
1934
                  internal::my_progname, result_table, ret, drizzle_con_error(&dcon));
1936
1935
          drizzle_result_free(&result);
1937
1936
          goto err;
1938
1937
        }