~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzlecheck.cc

  • Committer: devananda
  • Date: 2009-06-30 14:27:54 UTC
  • mfrom: (1030.2.4 trunk)
  • mto: (1093.1.7 captain)
  • mto: This revision was merged to the branch mainline in revision 1095.
  • Revision ID: devananda.vdv@gmail.com-20090630142754-vm9w374yxkf1pikc
mergeĀ fromĀ lp

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
static bool opt_alldbs= false, opt_check_only_changed= false,
41
41
            opt_extended= false, opt_databases= false,
42
42
            opt_fast= false, opt_medium_check= false, opt_quick= false,
43
 
            opt_all_in_1= false, opt_silent= false, opt_auto_repair= false,
 
43
            opt_all_in_1= false, opt_silent= false,
44
44
            ignore_errors= false, tty_password= false, opt_frm= false,
45
45
            debug_info_flag= false, debug_check_flag= false,
46
46
            opt_fix_table_names= false, opt_fix_db_names= false,
53
53
      *default_charset= (char *)DRIZZLE_DEFAULT_CHARSET_NAME,
54
54
      *current_host= NULL;
55
55
static int first_error= 0;
56
 
vector<string> tables4repair;
 
56
 
57
57
static const CHARSET_INFO *charset_info= &my_charset_utf8_general_ci;
58
58
 
59
 
enum operations { DO_CHECK, DO_REPAIR, DO_ANALYZE, DO_OPTIMIZE, DO_UPGRADE };
 
59
enum operations { DO_CHECK, DO_ANALYZE, DO_OPTIMIZE, DO_UPGRADE };
60
60
 
61
61
static struct my_option my_long_options[] =
62
62
{
70
70
   "Instead of issuing one query for each table, use one query per database, naming all tables in the database in a comma-separated list.",
71
71
   (char**) &opt_all_in_1, (char**) &opt_all_in_1, 0, GET_BOOL, NO_ARG, 0, 0, 0,
72
72
   0, 0, 0},
73
 
  {"auto-repair", OPT_AUTO_REPAIR,
74
 
   "If a checked table is corrupted, automatically fix it. Repairing will be done after all tables have been checked, if corrupted ones were found.",
75
 
   (char**) &opt_auto_repair, (char**) &opt_auto_repair, 0, GET_BOOL, NO_ARG, 0,
76
 
   0, 0, 0, 0, 0},
77
73
  {"check", 'c', "Check table for errors.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
78
74
   0, 0, 0, 0},
79
75
  {"check-only-changed", 'C',
137
133
   "If you are using this option with CHECK TABLE, it prevents the check from scanning the rows to check for wrong links. This is the fastest check. If you are using this option with REPAIR TABLE, it will try to repair only the index tree. This is the fastest repair method for a table.",
138
134
   (char**) &opt_quick, (char**) &opt_quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
139
135
   0},
140
 
  {"repair", 'r',
141
 
   "Can fix almost anything except unique keys that aren't unique.",
142
 
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
143
136
  {"silent", 's', "Print only error messages.", (char**) &opt_silent,
144
137
   (char**) &opt_silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
145
138
  {"socket", 'S', "Socket file to use for connection.",
303
296
    else
304
297
      tty_password = 1;
305
298
    break;
306
 
  case 'r':
307
 
    what_to_do = DO_REPAIR;
308
 
    break;
309
299
  case 'g':
310
300
    what_to_do= DO_CHECK;
311
301
    opt_upgrade= 1;
345
335
 
346
336
    if (pnlen < 6) /* name too short */
347
337
      what_to_do = DO_CHECK;
348
 
    else if (!strcmp("repair", my_progname + pnlen - 6))
349
 
      what_to_do = DO_REPAIR;
350
338
    else if (!strcmp("analyze", my_progname + pnlen - 7))
351
339
      what_to_do = DO_ANALYZE;
352
340
    else if  (!strcmp("optimize", my_progname + pnlen - 8))
701
689
    if (opt_check_only_changed) end = strcpy(end, " CHANGED")+8;
702
690
    if (opt_upgrade)            end = strcpy(end, " FOR UPGRADE")+12;
703
691
    break;
704
 
  case DO_REPAIR:
705
 
    op= (opt_write_binlog) ? "REPAIR" : "REPAIR NO_WRITE_TO_BINLOG";
706
 
    if (opt_quick)              end = strcpy(end, " QUICK")+6;
707
 
    if (opt_extended)           end = strcpy(end, " EXTENDED")+9;
708
 
    if (opt_frm)                end = strcpy(end, " USE_FRM")+8;
709
 
    break;
710
692
  case DO_ANALYZE:
711
693
    op= (opt_write_binlog) ? "ANALYZE" : "ANALYZE NO_WRITE_TO_BINLOG";
712
694
    break;
772
754
 
773
755
    if (status)
774
756
    {
775
 
      /*
776
 
        if there was an error with the table, we have --auto-repair set,
777
 
        and this isn't a repair op, then add the table to the tables4repair
778
 
        list
779
 
      */
780
 
      if (found_error && opt_auto_repair && what_to_do != DO_REPAIR &&
781
 
          strcmp((char *)row[3],"OK"))
782
 
        tables4repair.push_back(string(prev));
783
757
      found_error=0;
784
758
      if (opt_silent)
785
759
        continue;
797
771
    strcpy(prev, (char *)row[0]);
798
772
    putchar('\n');
799
773
  }
800
 
  /* add the last table to be repaired to the list */
801
 
  if (found_error && opt_auto_repair && what_to_do != DO_REPAIR)
802
 
    tables4repair.push_back(string(prev));
803
774
}
804
775
 
805
776
 
864
835
  if (dbConnect(current_host, current_user, opt_password))
865
836
    exit(EX_MYSQLERR);
866
837
 
867
 
  if (opt_auto_repair)
868
 
  {
869
 
    tables4repair.reserve(64);
870
 
    if (tables4repair.capacity() == 0)
871
 
    {
872
 
      first_error = 1;
873
 
      goto end;
874
 
    }
875
 
  }
876
 
 
877
 
 
878
838
  if (opt_alldbs)
879
839
    process_all_databases();
880
840
  /* Only one database and selected table(s) */
883
843
  /* One or more databases, all tables */
884
844
  else
885
845
    process_databases(argv);
886
 
  if (opt_auto_repair)
887
 
  {
888
846
 
889
 
    if (!opt_silent && (tables4repair.size() > 0))
890
 
      puts("\nRepairing tables");
891
 
    what_to_do = DO_REPAIR;
892
 
    vector<string>::iterator i;
893
 
    for ( i= tables4repair.begin() ; i < tables4repair.end() ; i++)
894
 
    {
895
 
      const char *name= (*i).c_str();
896
 
      handle_request_for_tables(name, fixed_name_length(name));
897
 
    }
898
 
  }
899
 
 end:
900
847
  dbDisconnect(current_host);
901
848
  free(opt_password);
902
849
  my_end(my_end_arg);