summaryrefslogtreecommitdiff
path: root/client/mysqlcheck.c
diff options
context:
space:
mode:
authorunknown <jani@hynda.mysql.fi>2002-04-02 20:29:53 +0300
committerunknown <jani@hynda.mysql.fi>2002-04-02 20:29:53 +0300
commita2e75474b51e41446af02081ba2917f0f296aee2 (patch)
tree1646f32146d233c71f082b8d74b469e6a1c1e70f /client/mysqlcheck.c
parent90a76d688ab49832f51462dbc906b4c11b4a09fb (diff)
downloadmariadb-git-a2e75474b51e41446af02081ba2917f0f296aee2.tar.gz
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
mysqlcheck and myisamchk to use new my_getopt struct. client/client_priv.h: Changes for my_getopt client/mysql.cc: Uses new my_getopt client/mysqladmin.c: Uses new my_getopt client/mysqlcheck.c: Uses new my_getopt client/mysqldump.c: Uses new my_getopt client/mysqlimport.c: Uses new my_getopt client/mysqlshow.c: Uses new my_getopt include/my_getopt.h: Added GET_BOOL type include/sslopt-case.h: This is shouldn't be needed anymore. include/sslopt-longopts.h: Uses new my_getopt myisam/myisamchk.c: Uses new my_getopt mysys/my_getopt.c: Some bug fixes and small feature adds to my_getopt sql/mysqld.cc: mysqld.cc will be changed next. sslopt-* had to be removed temporarily.
Diffstat (limited to 'client/mysqlcheck.c')
-rw-r--r--client/mysqlcheck.c393
1 files changed, 180 insertions, 213 deletions
diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c
index eccc08f59ec..86507bc0b31 100644
--- a/client/mysqlcheck.c
+++ b/client/mysqlcheck.c
@@ -16,9 +16,10 @@
/* By Jani Tolonen, 2001-04-20, MySQL Development Team */
-#define CHECK_VERSION "1.02"
+#define CHECK_VERSION "2.0"
#include "client_priv.h"
+#include <my_getopt.h>
#include <m_ctype.h>
#include "mysql_version.h"
#include "mysqld_error.h"
@@ -33,7 +34,8 @@ static MYSQL mysql_connection, *sock = 0;
static my_bool opt_alldbs = 0, opt_check_only_changed = 0, opt_extended = 0,
opt_compress = 0, opt_databases = 0, opt_fast = 0,
opt_medium_check = 0, opt_quick = 0, opt_all_in_1 = 0,
- opt_silent = 0, opt_auto_repair = 0, ignore_errors = 0;
+ opt_silent = 0, opt_auto_repair = 0, ignore_errors = 0,
+ tty_password = 0;
static uint verbose = 0, opt_mysql_port=0;
static my_string opt_mysql_unix_port = 0;
static char *opt_password = 0, *current_user = 0, *default_charset = 0,
@@ -43,45 +45,96 @@ DYNAMIC_ARRAY tables4repair;
enum operations {DO_CHECK, DO_REPAIR, DO_ANALYZE, DO_OPTIMIZE};
-static struct option long_options[] =
+static struct my_option my_long_options[] =
{
- {"all-databases", no_argument, 0, 'A'},
- {"all-in-1", no_argument, 0, '1'},
- {"auto-repair", no_argument, 0, OPT_AUTO_REPAIR},
- {"analyze", no_argument, 0, 'a'},
- {"character-sets-dir", required_argument, 0, OPT_CHARSETS_DIR},
- {"check", no_argument, 0, 'c'},
- {"check-only-changed", no_argument, 0, 'C'},
- {"compress", no_argument, 0, OPT_COMPRESS},
- {"databases", no_argument, 0, 'B'},
- {"debug", optional_argument, 0, '#'},
- {"default-character-set", required_argument, 0, OPT_DEFAULT_CHARSET},
- {"fast", no_argument, 0, 'F'},
- {"force", no_argument, 0, 'f'},
- {"extended", no_argument, 0, 'e'},
- {"help", no_argument, 0, '?'},
- {"host", required_argument, 0, 'h'},
- {"medium-check", no_argument, 0, 'm'},
- {"optimize", no_argument, 0, 'o'},
- {"password", optional_argument, 0, 'p'},
+ {"all-databases", 'A',
+ "Check all the databases. This will be same as --databases with all databases selected.",
+ (gptr*) &opt_alldbs, (gptr*) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
+ 0, 0},
+ {"analyze", 'a', "Analyze given tables.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
+ 0, 0, 0, 0},
+ {"all-in-1", '1',
+ "Instead of making one query for each table, execute all queries in 1 query separately for each database. Table names will be in a comma separeted list.",
+ (gptr*) &opt_all_in_1, (gptr*) &opt_all_in_1, 0, GET_BOOL, NO_ARG, 0, 0, 0,
+ 0, 0, 0},
+ {"auto-repair", OPT_AUTO_REPAIR,
+ "If a checked table is corrupted, automatically fix it. Repairing will be done after all tables have been checked, if corrupted ones were found.",
+ (gptr*) &opt_auto_repair, (gptr*) &opt_auto_repair, 0, GET_BOOL, NO_ARG, 0,
+ 0, 0, 0, 0, 0},
+ {"character-sets-dir", OPT_CHARSETS_DIR,
+ "Directory where character sets are", (gptr*) &charsets_dir,
+ (gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"check", 'c', "Check table for errors", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
+ 0, 0, 0, 0},
+ {"check-only-changed", 'C',
+ "Check only tables that have changed since last check or haven't been closed properly.",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"compress", OPT_COMPRESS, "Use compression in server/client protocol.",
+ (gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
+ 0, 0, 0},
+ {"databases", 'B',
+ "To check several databases. Note the difference in usage; In this case no tables are given. All name arguments are regarded as databasenames.",
+ (gptr*) &opt_databases, (gptr*) &opt_databases, 0, GET_BOOL, NO_ARG,
+ 0, 0, 0, 0, 0, 0},
+ {"debug", '#', "Output debug log. Often this is 'd:t:o,filename'",
+ 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
+ {"default-character-set", OPT_DEFAULT_CHARSET,
+ "Set the default character set", (gptr*) &default_charset,
+ (gptr*) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"fast",'F', "Check only tables that hasn't been closed properly",
+ (gptr*) &opt_fast, (gptr*) &opt_fast, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
+ 0},
+ {"force", 'f', "Continue even if we get an sql-error.",
+ (gptr*) &ignore_errors, (gptr*) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
+ 0, 0, 0, 0},
+ {"extended", 'e',
+ "If you are using this option with CHECK TABLE, it will ensure that the table is 100 percent consistent, but will take a long time. If you are using this option with REPAIR TABLE, it will run an extended repair on the table, which may not only take a long time to execute, but may produce a lot of garbage rows also!",
+ (gptr*) &opt_extended, (gptr*) &opt_extended, 0, GET_BOOL, NO_ARG, 0, 0, 0,
+ 0, 0, 0},
+ {"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
+ NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"host",'h', "Connect to host.", (gptr*) &current_host,
+ (gptr*) &current_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"medium-check", 'm',
+ "Faster than extended-check, but only finds 99.99 percent of all errors. Should be good enough for most cases.",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"optimize", 'o', "Optimize table.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0,
+ 0, 0},
+ {"password", 'p',
+ "Password to use when connecting to server. If password is not given it's solicited on the tty.",
+ 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
#ifdef __WIN__
- {"pipe", no_argument, 0, 'W'},
+ {"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG,
+ NO_ARG, 0, 0, 0, 0, 0, 0},
#endif
- {"port", required_argument, 0, 'P'},
- {"quick", no_argument, 0, 'q'},
- {"repair", no_argument, 0, 'r'},
- {"silent", no_argument, 0, 's'},
- {"socket", required_argument, 0, 'S'},
+ {"port", 'P', "Port number to use for connection.", 0, 0, 0, GET_LONG,
+ REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"quick", 'q',
+ "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.",
+ (gptr*) &opt_quick, (gptr*) &opt_quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
+ 0},
+ {"repair", 'r',
+ "Can fix almost anything except unique keys that aren't unique.",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"silent", 's', "Print only error messages.", (gptr*) &opt_silent,
+ (gptr*) &opt_silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"socket", 'S', "Socket file to use for connection.",
+ (gptr*) &opt_mysql_unix_port, (gptr*) &opt_mysql_unix_port, 0, GET_STR,
+ REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#include "sslopt-longopts.h"
- {"tables", no_argument, 0, OPT_TABLES},
+ {"tables", OPT_TABLES, "Overrides option --databases (-B).", 0, 0, 0,
+ GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
#ifndef DONT_ALLOW_USER_CHANGE
- {"user", required_argument, 0, 'u'},
+ {"user", 'u', "User for login if not current user.", (gptr*) &current_user,
+ (gptr*) &current_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#endif
- {"verbose", no_argument, 0, 'v'},
- {"version", no_argument, 0, 'V'},
- {0, 0, 0, 0}
+ {"verbose", 'v', "Print info about the various stages.", 0, 0, 0, GET_NO_ARG,
+ NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
+ NO_ARG, 0, 0, 0, 0, 0, 0},
+ {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
-
+
static const char *load_default_groups[] = { "mysqlcheck", "client", 0 };
@@ -131,78 +184,99 @@ static void usage(void)
printf("OR %s [OPTIONS] --databases DB1 [DB2 DB3...]\n",
my_progname);
printf("OR %s [OPTIONS] --all-databases\n", my_progname);
- printf("\
- -A, --all-databases Check all the databases. This will be same as\n\
- --databases with all databases selected\n\
- -1, --all-in-1 Instead of making one query for each table, execute\n\
- all queries in 1 query separately for each database.\n\
- Table names will be in a comma separeted list.\n\
- -a, --analyze Analyze given tables.\n\
- --auto-repair If a checked table is corrupted, automatically fix\n\
- it. Repairing will be done after all tables have\n\
- been checked, if corrupted ones were found.\n\
- -#, --debug=... Output debug log. Often this is 'd:t:o,filename'\n\
- --character-sets-dir=...\n\
- Directory where character sets are\n\
- -c, --check Check table for errors\n\
- -C, --check-only-changed\n\
- Check only tables that have changed since last check\n\
- or haven't been closed properly.\n\
- --compress Use compression in server/client protocol.\n\
- -?, --help Display this help message and exit.\n\
- -B, --databases To check several databases. Note the difference in\n\
- usage; In this case no tables are given. All name\n\
- arguments are regarded as databasenames.\n\
- --default-character-set=...\n\
- Set the default character set\n\
- -F, --fast Check only tables that hasn't been closed properly\n\
- -f, --force Continue even if we get an sql-error.\n\
- -e, --extended If you are using this option with CHECK TABLE,\n\
- it will ensure that the table is 100 percent\n\
- consistent, but will take a long time.\n\n");
-printf("\
- If you are using this option with REPAIR TABLE,\n\
- it will run an extended repair on the table, which\n\
- may not only take a long time to execute, but\n\
- may produce a lot of garbage rows also!\n\
- -h, --host=... Connect to host.\n\
- -m, --medium-check Faster than extended-check, but only finds 99.99 percent\n\
- of all errors. Should be good enough for most cases.\n\
- -o, --optimize Optimize table\n\
- -p, --password[=...] Password to use when connecting to server.\n\
- If password is not given it's solicited on the tty.\n");
-#ifdef __WIN__
- puts("-W, --pipe Use named pipes to connect to server");
-#endif
- printf("\
- -P, --port=... Port number to use for connection.\n\
- -q, --quick If you are using this option with CHECK TABLE, it\n\
- prevents the check from scanning the rows to check\n\
- for wrong links. This is the fastest check.\n\n\
- If you are using this option with REPAIR TABLE, it\n\
- will try to repair only the index tree. This is\n\
- the fastest repair method for a table.\n\
- -r, --repair Can fix almost anything except unique keys that aren't\n\
- unique.\n\
- -s, --silent Print only error messages.\n\
- -S, --socket=... Socket file to use for connection.\n\
- --tables Overrides option --databases (-B).\n");
-#include "sslopt-usage.h"
-#ifndef DONT_ALLOW_USER_CHANGE
- printf("\
- -u, --user=# User for login if not current user.\n");
-#endif
- printf("\
- -v, --verbose Print info about the various stages.\n\
- -V, --version Output version information and exit.\n");
print_defaults("my", load_default_groups);
+ my_print_help(my_long_options);
+ my_print_variables(my_long_options);
} /* usage */
+static my_bool
+get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
+ char *argument)
+{
+ switch(optid) {
+ case 'a':
+ what_to_do = DO_ANALYZE;
+ break;
+ case OPT_DEFAULT_CHARSET:
+ default_charset = argument;
+ break;
+ case OPT_CHARSETS_DIR:
+ charsets_dir = argument;
+ break;
+ case 'c':
+ what_to_do = DO_CHECK;
+ break;
+ case 'C':
+ what_to_do = DO_CHECK;
+ opt_check_only_changed = 1;
+ break;
+ case 'I': /* Fall through */
+ case '?':
+ usage();
+ exit(0);
+ case 'h':
+ my_free(current_host, MYF(MY_ALLOW_ZERO_PTR));
+ current_host = my_strdup(argument, MYF(MY_WME));
+ break;
+ case 'm':
+ what_to_do = DO_CHECK;
+ opt_medium_check = 1;
+ break;
+ case 'o':
+ what_to_do = DO_OPTIMIZE;
+ break;
+#ifndef DONT_ALLOW_USER_CHANGE
+ case 'u':
+ current_user = argument;
+ break;
+#endif
+ case 'p':
+ if (argument)
+ {
+ char *start = argument;
+ my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
+ opt_password = my_strdup(argument, MYF(MY_FAE));
+ while (*argument) *argument++= 'x'; /* Destroy argument */
+ if (*start)
+ start[1] = 0; /* Cut length of argument */
+ }
+ else
+ tty_password = 1;
+ break;
+ case 'P':
+ opt_mysql_port = (unsigned int) atoi(argument);
+ break;
+ case 'r':
+ what_to_do = DO_REPAIR;
+ break;
+ case 'S':
+ opt_mysql_unix_port = argument;
+ break;
+ case 'W':
+#ifdef __WIN__
+ opt_mysql_unix_port = MYSQL_NAMEDPIPE;
+#endif
+ break;
+ case '#':
+ DBUG_PUSH(argument ? argument : "d:t:o");
+ break;
+ case OPT_TABLES:
+ opt_databases = 0;
+ break;
+ case 'v':
+ verbose++;
+ break;
+ case 'V': print_version(); exit(0);
+#include "sslopt-case.h"
+ }
+ return 0;
+}
+
+
static int get_options(int *argc, char ***argv)
{
- int c, option_index;
- my_bool tty_password = 0;
+ int ho_error;
if (*argc == 1)
{
@@ -211,119 +285,14 @@ static int get_options(int *argc, char ***argv)
}
load_defaults("my", load_default_groups, argc, argv);
- while ((c = getopt_long(*argc, *argv, "#::p::h:u:P:S:BaAcCdeFfmqorsvVw:?I1",
- long_options, &option_index)) != EOF)
+
+ if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
{
- switch(c) {
- case 'a':
- what_to_do = DO_ANALYZE;
- break;
- case '1':
- opt_all_in_1 = 1;
- break;
- case 'A':
- opt_alldbs = 1;
- break;
- case OPT_AUTO_REPAIR:
- opt_auto_repair = 1;
- break;
- case OPT_DEFAULT_CHARSET:
- default_charset = optarg;
- break;
- case OPT_CHARSETS_DIR:
- charsets_dir = optarg;
- break;
- case 'c':
- what_to_do = DO_CHECK;
- break;
- case 'C':
- what_to_do = DO_CHECK;
- opt_check_only_changed = 1;
- break;
- case 'e':
- opt_extended = 1;
- break;
- case OPT_COMPRESS:
- opt_compress = 1;
- break;
- case 'B':
- opt_databases = 1;
- break;
- case 'F':
- opt_fast = 1;
- break;
- case 'f':
- ignore_errors = 1;
- break;
- case 'I': /* Fall through */
- case '?':
- usage();
- exit(0);
- case 'h':
- my_free(current_host, MYF(MY_ALLOW_ZERO_PTR));
- current_host = my_strdup(optarg, MYF(MY_WME));
- break;
- case 'm':
- what_to_do = DO_CHECK;
- opt_medium_check = 1;
- break;
- case 'o':
- what_to_do = DO_OPTIMIZE;
- break;
-#ifndef DONT_ALLOW_USER_CHANGE
- case 'u':
- current_user = optarg;
- break;
-#endif
- case 'p':
- if (optarg)
- {
- char *start = optarg;
- my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
- opt_password = my_strdup(optarg, MYF(MY_FAE));
- while (*optarg) *optarg++= 'x'; /* Destroy argument */
- if (*start)
- start[1] = 0; /* Cut length of argument */
- }
- else
- tty_password = 1;
- break;
- case 'P':
- opt_mysql_port = (unsigned int) atoi(optarg);
- break;
- case 'q':
- opt_quick = 1;
- break;
- case 'r':
- what_to_do = DO_REPAIR;
- break;
- case 'S':
- opt_mysql_unix_port = optarg;
- break;
- case 's':
- opt_silent = 1;
- break;
- case 'W':
-#ifdef __WIN__
- opt_mysql_unix_port = MYSQL_NAMEDPIPE;
-#endif
- break;
- case '#':
- DBUG_PUSH(optarg ? optarg : "d:t:o");
- break;
- case OPT_TABLES:
- opt_databases = 0;
- break;
- case 'v':
- verbose++;
- break;
- case 'V': print_version(); exit(0);
- default:
- fprintf(stderr, "%s: Illegal option character '%c'\n", my_progname,
- opterr);
-#include "sslopt-case.h"
- }
+ printf("%s: handle_options() failed with error %d\n", my_progname,
+ ho_error);
+ exit(1);
}
+
if (!what_to_do)
{
int pnlen = strlen(my_progname);
@@ -344,8 +313,6 @@ static int get_options(int *argc, char ***argv)
if (set_default_charset_by_name(default_charset, MYF(MY_WME)))
exit(1);
}
- (*argc) -= optind;
- (*argv) += optind;
if (*argc > 0 && opt_alldbs)
{
printf("You should give only options, no arguments at all, with option\n");