Commit c143f01d authored by jani@hynda.mysql.fi's avatar jani@hynda.mysql.fi

Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,

mysqlcheck and myisamchk to use new my_getopt struct.
parent 697978b5
...@@ -31,4 +31,9 @@ enum options { OPT_CHARSETS_DIR=256, OPT_DEFAULT_CHARSET, ...@@ -31,4 +31,9 @@ enum options { OPT_CHARSETS_DIR=256, OPT_DEFAULT_CHARSET,
OPT_LOW_PRIORITY, OPT_AUTO_REPAIR, OPT_COMPRESS, OPT_LOW_PRIORITY, OPT_AUTO_REPAIR, OPT_COMPRESS,
OPT_DROP, OPT_LOCKS, OPT_KEYWORDS, OPT_DELAYED, OPT_OPTIMIZE, OPT_DROP, OPT_LOCKS, OPT_KEYWORDS, OPT_DELAYED, OPT_OPTIMIZE,
OPT_FTB, OPT_LTB, OPT_ENC, OPT_O_ENC, OPT_ESC, OPT_TABLES, OPT_FTB, OPT_LTB, OPT_ENC, OPT_O_ENC, OPT_ESC, OPT_TABLES,
OPT_MASTER_DATA, OPT_AUTOCOMMIT}; OPT_MASTER_DATA, OPT_AUTOCOMMIT, OPT_AUTO_REHASH,
OPT_LINE_NUMBERS, OPT_COLUMN_NAMES, OPT_CONNECT_TIMEOUT,
OPT_MAX_ALLOWED_PACKET, OPT_NET_BUFFER_LENGTH,
OPT_SELECT_LIMIT, OPT_MAX_JOIN_SIZE, OPT_SSL_SSL,
OPT_SSL_KEY, OPT_SSL_CERT, OPT_SSL_CA, OPT_SSL_CAPATH,
OPT_SSL_CIPHER, OPT_SHUTDOWN_TIMEOUT};
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#include "client_priv.h" #include "client_priv.h"
#include <m_ctype.h> #include <m_ctype.h>
#include <stdarg.h>
#include <my_getopt.h>
#include <my_dir.h> #include <my_dir.h>
#ifndef __GNU_LIBRARY__ #ifndef __GNU_LIBRARY__
#define __GNU_LIBRARY__ // Skip warnings in getopt.h #define __GNU_LIBRARY__ // Skip warnings in getopt.h
...@@ -38,7 +40,7 @@ ...@@ -38,7 +40,7 @@
#include <signal.h> #include <signal.h>
#include <violite.h> #include <violite.h>
const char *VER="11.19"; const char *VER= "12.0";
/* Don't try to make a nice table if the data is too big */ /* Don't try to make a nice table if the data is too big */
#define MAX_COLUMN_LENGTH 1024 #define MAX_COLUMN_LENGTH 1024
...@@ -113,13 +115,14 @@ enum enum_info_type { INFO_INFO,INFO_ERROR,INFO_RESULT}; ...@@ -113,13 +115,14 @@ enum enum_info_type { INFO_INFO,INFO_ERROR,INFO_RESULT};
typedef enum enum_info_type INFO_TYPE; typedef enum enum_info_type INFO_TYPE;
static MYSQL mysql; /* The connection */ static MYSQL mysql; /* The connection */
static bool info_flag=0,ignore_errors=0,wait_flag=0,quick=0, static my_bool info_flag=0,ignore_errors=0,wait_flag=0,quick=0,
connected=0,opt_raw_data=0,unbuffered=0,output_tables=0, connected=0,opt_raw_data=0,unbuffered=0,output_tables=0,
no_rehash=0,skip_updates=0,safe_updates=0,one_database=0, no_rehash=0,skip_updates=0,safe_updates=0,one_database=0,
opt_compress=0, opt_compress=0,
vertical=0,skip_line_numbers=0,skip_column_names=0,opt_html=0, vertical=0, line_numbers=1, column_names=1,opt_html=0,
opt_xml=0,opt_nopager=1, opt_outfile=0, no_named_cmds=1; opt_xml=0,opt_nopager=1, opt_outfile=0, named_cmds= 0,
static uint verbose=0,opt_silent=0,opt_mysql_port=0; tty_password= 0;
static uint verbose=0, opt_silent=0, opt_mysql_port=0;
static my_string opt_mysql_unix_port=0; static my_string opt_mysql_unix_port=0;
static int connect_flag=CLIENT_INTERACTIVE; static int connect_flag=CLIENT_INTERACTIVE;
static char *current_host,*current_db,*current_user=0,*opt_password=0, static char *current_host,*current_db,*current_user=0,*opt_password=0,
...@@ -135,7 +138,7 @@ static const char *xmlmeta[] = { ...@@ -135,7 +138,7 @@ static const char *xmlmeta[] = {
"<", "&lt;", "<", "&lt;",
0, 0 0, 0
}; };
static char default_pager[FN_REFLEN]; char default_pager[FN_REFLEN];
char pager[FN_REFLEN], outfile[FN_REFLEN]; char pager[FN_REFLEN], outfile[FN_REFLEN];
FILE *PAGER, *OUTFILE; FILE *PAGER, *OUTFILE;
MEM_ROOT hash_mem_root; MEM_ROOT hash_mem_root;
...@@ -295,7 +298,7 @@ int main(int argc,char *argv[]) ...@@ -295,7 +298,7 @@ int main(int argc,char *argv[])
status.add_to_history=1; status.add_to_history=1;
status.exit_status=1; status.exit_status=1;
load_defaults("my",load_default_groups,&argc,&argv); load_defaults("my",load_default_groups,&argc,&argv);
if (get_options(argc,(char **) argv)) if (get_options(argc, (char **) argv))
{ {
my_end(0); my_end(0);
exit(1); exit(1);
...@@ -416,73 +419,143 @@ sig_handler mysql_end(int sig) ...@@ -416,73 +419,143 @@ sig_handler mysql_end(int sig)
exit(status.exit_status); exit(status.exit_status);
} }
static struct option long_options[] =
static struct my_option my_long_options[] =
{ {
{"i-am-a-dummy", optional_argument, 0, 'U'}, {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
{"batch", no_argument, 0, 'B'}, 0, 0, 0, 0, 0},
{"character-sets-dir",required_argument, 0, OPT_CHARSETS_DIR}, {"auto-rehash", OPT_AUTO_REHASH,
{"compress", no_argument, 0, 'C'}, "Enable automatic rehashing. One doesn't need to use 'rehash' to get table and field completion, but startup and reconnecting may take a longer time. Disable with --disable-auto-rehash.",
(gptr*) &no_rehash, (gptr*) &no_rehash, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
0},
{"no-auto-rehash", 'A',
"No automatic rehashing. One has to use 'rehash' to get table and field completion. This gives a quicker start of mysql and disables rehashing on reconnect. WARNING: options depricated; use --disable-auto-rehash instead.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"batch", 'B',
"Print results with a tab as separator, each row on new line. Doesn't use history file.", 0, 0, 0, GET_NO_ARG, 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},
{"compress", 'C', "Use compression in server/client protocol.",
(gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
0, 0, 0},
#ifndef DBUG_OFF #ifndef DBUG_OFF
{"debug", optional_argument, 0, '#'}, {"debug", '#', "Output debug log.", (gptr*) &default_dbug_option,
(gptr*) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
#endif
{"database", 'D', "Database to use.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0,
0, 0, 0},
{"execute", 'e', "Execute command and quit. (Output like with --batch).", 0,
0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"vertical", 'E', "Print the output of a query (rows) vertically.",
(gptr*) &vertical, (gptr*) &vertical, 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},
{"no-named-commands", 'g', "Named commands are disabled. Use \\* form only, or use named commands only in the beginning of a line ending with a semicolon (;) Since version 10.9 the client now starts with this option ENABLED by default! Disable with '-G'. Long format commands still work from the first line. WARNING: option depricated; use --disable-named-commands instead.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"named-commands", 'G',
"Enable named commands. Disable with --disable-named-commands. This option is disabled by default.",
(gptr*) &named_cmds, (gptr*) &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
0, 0},
{"ignore-space", 'i', "Ignore space after function names.", 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},
{"html", 'H', "Produce HTML output.", (gptr*) &opt_html, (gptr*) &opt_html,
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"xml", 'X', "Produce XML output", (gptr*) &opt_xml, (gptr*) &opt_xml, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"line-numbers", OPT_LINE_NUMBERS, "Write line numbers for errors.",
(gptr*) &line_numbers, (gptr*) &line_numbers, 0, GET_BOOL,
NO_ARG, 0, 0, 0, 0, 0, 0},
{"skip-line-numbers", 'L', "Don't write line number for errors. WARNING: -L is depricated, use long version of this option instead.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
#ifndef __WIN__
{"no-pager", OPT_NOPAGER,
"Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option depricated; use --disable-pager instead.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
#endif #endif
{"database", required_argument, 0, 'D'}, {"no-tee", OPT_NOTEE, "Disable outfile. See interactive help (\\h) also. WARNING: option depricated; use --disable-tee instead", 0, 0, 0, GET_NO_ARG,
{"debug-info", no_argument, 0, 'T'}, NO_ARG, 0, 0, 0, 0, 0, 0},
{"default-character-set", required_argument,0, OPT_DEFAULT_CHARSET}, {"unbuffered", 'n', "Flush buffer after each query.", (gptr*) &unbuffered,
{"enable-named-commands", no_argument, 0, 'G'}, (gptr*) &unbuffered, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"execute", required_argument, 0, 'e'}, {"column-names", OPT_COLUMN_NAMES, "Write column names in results.",
{"force", no_argument, 0, 'f'}, (gptr*) &column_names, (gptr*) &column_names, 0, GET_BOOL,
{"help", no_argument, 0, '?'}, NO_ARG, 0, 0, 0, 0, 0, 0},
{"html", no_argument, 0, 'H'}, {"skip-column-names", 'N',
{"xml", no_argument, 0, 'X'}, "Don't write column names in results. WARNING: -N is depricated, use long version of this options instead.",
{"host", required_argument, 0, 'h'}, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"ignore-spaces", no_argument, 0, 'i'}, {"set-variable", 'O',
{"no-auto-rehash",no_argument, 0, 'A'}, "Change the value of a variable. Please note that this option is depricated; you can set variables directly with --variable-name=value.",
{"no-named-commands", no_argument, 0, 'g'}, 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"no-tee", no_argument, 0, OPT_NOTEE}, {"one-database", 'o',
"Only update the default database. This is useful for skipping updates to other database in the update log.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
#ifndef __WIN__ #ifndef __WIN__
{"no-pager", no_argument, 0, OPT_NOPAGER}, {"pager", OPT_PAGER,
{"nopager", no_argument, 0, OPT_NOPAGER}, /* we are kind */ "Pager to use to display results. If you don't supply an option the default pager is taken from your ENV variable PAGER. Valid pagers are less, more, cat [> filename], etc. See interactive help (\\h) also. This option does not work in batch mode.",
{"pager", optional_argument, 0, OPT_PAGER}, 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
#endif #endif
{"notee", no_argument, 0, OPT_NOTEE}, /* we are kind */ {"password", 'p',
{"tee", required_argument, 0, OPT_TEE}, "Password to use when connecting to server. If password is not given it's asked from the tty.",
{"one-database", no_argument, 0, 'o'}, 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"password", optional_argument, 0, 'p'},
#ifdef __WIN__ #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 #endif
{"port", required_argument, 0, 'P'}, {"port", 'P', "Port number to use for connection.", 0, 0, 0,
{"quick", no_argument, 0, 'q'}, GET_LONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"set-variable", required_argument, 0, 'O'}, {"quick", 'q',
{"raw", no_argument, 0, 'r'}, "Don't cache result, print it row by row. This may slow down the server if the output is suspended. Doesn't use history file. ",
{"safe-updates", optional_argument, 0, 'U'}, (gptr*) &quick, (gptr*) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"silent", no_argument, 0, 's'}, {"raw", 'r', "Write fields without conversion. Used with --batch",
{"skip-column-names",no_argument, 0, 'N'}, (gptr*) &opt_raw_data, (gptr*) &opt_raw_data, 0, GET_BOOL, NO_ARG, 0, 0, 0,
{"skip-line-numbers",no_argument, 0, 'L'}, 0, 0, 0},
{"socket", required_argument, 0, 'S'}, {"silent", 's', "Be more silent.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0,
0, 0},
{"socket", 'S', "Socket file to use for connection.",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#include "sslopt-longopts.h" #include "sslopt-longopts.h"
{"table", no_argument, 0, 't'}, {"table", 't', "Output in table format.", (gptr*) &output_tables,
(gptr*) &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"debug-info", 'T', "Print some debug info at exit.", (gptr*) &info_flag,
(gptr*) &info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"tee", OPT_TEE,
"Append everything into outfile. See interactive help (\\h) also. Does not work in batch mode.",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#ifndef DONT_ALLOW_USER_CHANGE #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 #endif
{"unbuffered", no_argument, 0, 'n'}, {"safe-updates", 'U', "Only allow UPDATE and DELETE that uses keys.",
{"verbose", no_argument, 0, 'v'}, (gptr*) &safe_updates, (gptr*) &safe_updates, 0, GET_BOOL, OPT_ARG, 0, 0,
{"version", no_argument, 0, 'V'}, 0, 0, 0, 0},
{"vertical", no_argument, 0, 'E'}, {"i-am-a-dummy", 'U', "Synonym for option --safe-updates, -U.", 0, 0, 0,
{"wait", optional_argument, 0, 'w'}, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0} {"verbose", 'v', "Write more. (-v -v -v gives the table output format)", 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},
CHANGEABLE_VAR changeable_vars[] = { {"wait", 'w', "Wait and retry if connection is down.", 0, 0, 0, GET_NO_ARG,
{ "connect_timeout", (long*) &opt_connect_timeout, 0, 0, 3600*12, 0, 1}, NO_ARG, 0, 0, 0, 0, 0, 0},
{ "max_allowed_packet", (long*) &max_allowed_packet,16*1024L*1024L,4096, {"connect_timeout", OPT_CONNECT_TIMEOUT, "", (gptr*) &opt_connect_timeout,
512*1024L*1024L, MALLOC_OVERHEAD,1024}, (gptr*) &opt_connect_timeout, 0, GET_LONG, REQUIRED_ARG, 0, 0, 3600*12, 0,
{ "net_buffer_length",(long*) &net_buffer_length,16384,1024,512*1024*1024L, 0, 1},
MALLOC_OVERHEAD,1024}, {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "",
{ "select_limit", (long*) &select_limit, 1000L, 1, ~0L, 0, 1}, (gptr*) &max_allowed_packet, (gptr*) &max_allowed_packet, 0, GET_LONG,
{ "max_join_size", (long*) &max_join_size, 1000000L, 1, ~0L, 0, 1}, REQUIRED_ARG, 16 *1024L*1024L, 4096, 512*1024L*1024L, MALLOC_OVERHEAD,
{ 0, 0, 0, 0, 0, 0, 0} 1024, 0},
{"net_buffer_length", OPT_NET_BUFFER_LENGTH, "",
(gptr*) &net_buffer_length, (gptr*) &net_buffer_length, 0, GET_LONG,
REQUIRED_ARG, 16384, 1024, 512*1024*1024L, MALLOC_OVERHEAD, 1024, 0},
{"select_limit", OPT_SELECT_LIMIT, "", (gptr*) &select_limit,
(gptr*) &select_limit, 0, GET_LONG, REQUIRED_ARG, 1000L, 1, ~0L, 0, 1, 0},
{"max_join_size", OPT_MAX_JOIN_SIZE, "", (gptr*) &max_join_size,
(gptr*) &max_join_size, 0, GET_LONG, REQUIRED_ARG, 1000000L, 1, ~0L, 0, 1,
0},
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
}; };
...@@ -495,293 +568,210 @@ static void usage(int version) ...@@ -495,293 +568,210 @@ static void usage(int version)
puts("Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB"); puts("Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB");
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"); 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");
printf("Usage: %s [OPTIONS] [database]\n", my_progname); printf("Usage: %s [OPTIONS] [database]\n", my_progname);
printf("\n\ print_defaults("my", load_default_groups);
-?, --help Display this help and exit.\n\ my_print_help(my_long_options);
-A, --no-auto-rehash No automatic rehashing. One has to use 'rehash' to\n\ my_print_variables(my_long_options);
get table and field completion. This gives a quicker\n\
start of mysql and disables rehashing on reconnect.\n\
-B, --batch Print results with a tab as separator, each row on\n\
a new line. Doesn't use history file.\n\
--character-sets-dir=...\n\
Directory where character sets are located.\n\
-C, --compress Use compression in server/client protocol.\n");
#ifndef DBUG_OFF
printf("\
-#, --debug[=...] Debug log. Default is '%s'.\n",default_dbug_option);
#endif
printf("\
-D, --database=.. Database to use.\n\
--default-character-set=...\n\
Set the default character set.\n\
-e, --execute=... Execute command and quit. (Output like with --batch)\n\
-E, --vertical Print the output of a query (rows) vertically.\n\
-f, --force Continue even if we get an sql error.\n\
-g, --no-named-commands\n\
Named commands are disabled. Use \\* form only, or\n\
use named commands only in the beginning of a line\n\
ending with a semicolon (;) Since version 10.9 the\n\
client now starts with this option ENABLED by\n\
default! Disable with '-G'. Long format commands\n\
still work from the first line.\n\
-G, --enable-named-commands\n\
Named commands are enabled. Opposite to -g.\n\
-i, --ignore-space Ignore space after function names.\n\
-h, --host=... Connect to host.\n\
-H, --html Produce HTML output.\n\
-X, --xml Produce XML output.\n\
-L, --skip-line-numbers\n\
Don't write line number for errors.\n");
#ifndef __WIN__
printf("\
--no-pager Disable pager and print to stdout. See interactive\n\
help (\\h) also.\n");
#endif
printf("\
--no-tee Disable outfile. See interactive help (\\h) also.\n\
-n, --unbuffered Flush buffer after each query.\n\
-N, --skip-column-names\n\
Don't write column names in results.\n\
-O, --set-variable var=option\n\
Give a variable an value. --help lists variables.\n\
-o, --one-database Only update the default database. This is useful\n\
for skipping updates to other database in the update\n\
log.\n");
#ifndef __WIN__
printf("\
--pager[=...] Pager to use to display results. If you don't supply\n\
an option the default pager is taken from your ENV\n\
variable PAGER (%s).\n\
Valid pagers are less, more, cat [> filename], etc.\n\
See interactive help (\\h) also. This option does\n\
not work in batch mode.\n", getenv("PAGER") ? getenv("PAGER") : "");
#endif
printf("\
-p[password], --password[=...]\n\
Password to use when connecting to server\n\
If password is not given it's asked from the tty.\n");
#ifdef __WIN__
puts(" -W, --pipe Use named pipes to connect to server");
#endif
printf("\n\
-P, --port=... Port number to use for connection.\n\
-q, --quick Don't cache result, print it row by row. This may\n\
slow down the server if the output is suspended.\n\
Doesn't use history file.\n\
-r, --raw Write fields without conversion. Used with --batch\n\
-s, --silent Be more silent.\n\
-S --socket=... Socket file to use for connection.\n");
#include "sslopt-usage.h"
printf("\
-t, --table Output in table format.\n\
-T, --debug-info Print some debug info at exit.\n\
--tee=... Append everything into outfile. See interactive help\n\
(\\h) also. Does not work in batch mode.\n");
#ifndef DONT_ALLOW_USER_CHANGE
printf("\
-u, --user=# User for login if not current user.\n");
#endif
printf("\
-U, --safe-updates[=#], --i-am-a-dummy[=#]\n\
Only allow UPDATE and DELETE that uses keys.\n\
-v, --verbose Write more. (-v -v -v gives the table output format)\n\
-V, --version Output version information and exit.\n\
-w, --wait Wait and retry if connection is down.\n");
print_defaults("my",load_default_groups);
printf("\nPossible variables for option --set-variable (-O) are:\n");
for (uint i=0 ; changeable_vars[i].name ; i++)
printf("%-20s current value: %lu\n",
changeable_vars[i].name,
(ulong) *changeable_vars[i].varptr);
} }
static my_bool
static int get_options(int argc, char **argv) get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{ {
int c,option_index=0; switch(optid) {
bool tty_password=0;
set_all_changeable_vars(changeable_vars);
while ((c=getopt_long(argc,argv,
(char*) "?ABCD:LfgGHXinNoqrstTU::vVw::WEe:h:O:P:S:u:#::p::",
long_options, &option_index)) != EOF)
{
switch(c) {
case OPT_DEFAULT_CHARSET: case OPT_DEFAULT_CHARSET:
default_charset= optarg; default_charset= argument;
break; break;
case OPT_CHARSETS_DIR: case OPT_CHARSETS_DIR:
strmov(mysql_charsets_dir, optarg); strmov(mysql_charsets_dir, argument);
charsets_dir = mysql_charsets_dir; charsets_dir = mysql_charsets_dir;
break; break;
case OPT_TEE: case OPT_TEE:
if (!opt_outfile && strlen(optarg)) if (argument == disabled_my_option)
{ {
strmov(outfile, optarg); if (opt_outfile)
opt_outfile=1; end_tee();
init_tee(); opt_outfile= 0;
} }
else
if (!opt_outfile)
{
strmov(outfile, argument);
opt_outfile= 1;
init_tee();
}
break; break;
case OPT_NOTEE: case OPT_NOTEE:
printf("WARNING: option depricated; use --disable-tee instead.\n");
if (opt_outfile) if (opt_outfile)
end_tee(); end_tee();
opt_outfile=0; opt_outfile= 0;
break; break;
case OPT_PAGER: case OPT_PAGER:
opt_nopager=0; opt_nopager= 0;
if (optarg) if (argument)
strmov(pager, optarg); strmov(pager, argument);
else else
{ strmov(pager, default_pager);
char *pagpoint = getenv("PAGER");
if (!((char*) (pagpoint)))
{
strmov(pager, "stdout");
opt_nopager=1;
}
else
strmov(pager, pagpoint);
}
strmov(default_pager, pager); strmov(default_pager, pager);
break; break;
case OPT_NOPAGER: case OPT_NOPAGER:
opt_nopager=1; printf("WARNING: option depricated; use --disable-pager instead.\n");
opt_nopager= 1;
break; break;
case 'D': case 'D':
my_free(current_db,MYF(MY_ALLOW_ZERO_PTR)); my_free(current_db, MYF(MY_ALLOW_ZERO_PTR));
current_db=my_strdup(optarg,MYF(MY_WME)); current_db= my_strdup(argument, MYF(MY_WME));
break; break;
case 'e': case 'e':
status.batch=1; status.batch= 1;
status.add_to_history=0; status.add_to_history= 0;
batch_readline_end(status.line_buff); // If multiple -e batch_readline_end(status.line_buff); // If multiple -e
if (!(status.line_buff=batch_readline_command(optarg))) if (!(status.line_buff= batch_readline_command(argument)))
return 1; return 1;
ignore_errors=0; ignore_errors= 0;
break;
case 'f':
ignore_errors=1;
break; break;
case 'h': case 'h':
my_free(current_host,MYF(MY_ALLOW_ZERO_PTR)); my_free(current_host, MYF(MY_ALLOW_ZERO_PTR));
current_host=my_strdup(optarg,MYF(MY_WME)); current_host= my_strdup(argument, MYF(MY_WME));
break; break;
#ifndef DONT_ALLOW_USER_CHANGE #ifndef DONT_ALLOW_USER_CHANGE
case 'u': case 'u':
my_free(current_user,MYF(MY_ALLOW_ZERO_PTR)); my_free(current_user, MYF(MY_ALLOW_ZERO_PTR));
current_user= my_strdup(optarg,MYF(MY_WME)); current_user= my_strdup(argument, MYF(MY_WME));
break; break;
#endif #endif
case 'U':
if (!optarg)
safe_updates=1;
else
safe_updates=atoi(optarg) != 0;
break;
case 'o': case 'o':
one_database=skip_updates=1; if (argument == disabled_my_option)
break; one_database= 0;
case 'O': else
if (set_changeable_var(optarg, changeable_vars)) one_database= skip_updates= 1;
{
usage(0);
return(1);
}
break; break;
case 'p': case 'p':
if (optarg) if (argument == disabled_my_option)
opt_password= "";
else
{ {
char *start=optarg; if (argument)
my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR)); {
opt_password=my_strdup(optarg,MYF(MY_FAE)); char *start= argument;
while (*optarg) *optarg++= 'x'; // Destroy argument my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
if (*start) opt_password= my_strdup(argument, MYF(MY_FAE));
start[1]=0; while (*argument) *argument++= 'x'; // Destroy argument
if (*start)
start[1]=0 ;
}
else
tty_password= 1;
} }
else
tty_password=1;
break; break;
case 't': case '#':
output_tables=1; DBUG_PUSH(argument ? argument : default_dbug_option);
info_flag= 1;
break; break;
case 'r': case 's':
opt_raw_data=1; if (argument == disabled_my_option)
opt_silent= 0;
else
opt_silent++;
break; break;
case '#': case 'v':
DBUG_PUSH(optarg ? optarg : default_dbug_option); if (argument == disabled_my_option)
info_flag=1; verbose= 0;
else
verbose++;
break; break;
case 'q': quick=1; break;
case 's': opt_silent++; break;
case 'T': info_flag=1; break;
case 'n': unbuffered=1; break;
case 'v': verbose++; break;
case 'E': vertical=1; break;
case 'w': case 'w':
wait_flag=1; if (argument == disabled_my_option)
if(optarg) wait_time = atoi(optarg) ; wait_flag= 0;
else
{
wait_flag= 1;
if (argument)
wait_time= atoi(argument);
}
break;
case 'A':
printf("WARNING: option depricated; use --disable-auto-rehash instead.\n");
no_rehash= 1;
break;
case 'g':
printf("WARNING: option depricated; use --disable-named-commands instead.\n");
named_cmds= 0;
break;
case 'i':
connect_flag|= CLIENT_IGNORE_SPACE;
break; break;
case 'A': no_rehash=1; break;
case 'G': no_named_cmds=0; break;
case 'g': no_named_cmds=1; break;
case 'H': opt_html=1; break;
case 'X': opt_xml=1; break;
case 'i': connect_flag|= CLIENT_IGNORE_SPACE; break;
case 'B': case 'B':
if (!status.batch) if (!status.batch)
{ {
status.batch=1; status.batch= 1;
status.add_to_history=0; status.add_to_history= 0;
opt_silent++; // more silent opt_silent++; // more silent
} }
break; break;
case 'C':
opt_compress=1;
break;
case 'L':
skip_line_numbers=1;
break;
case 'N':
skip_column_names=1;
break;
case 'P': case 'P':
opt_mysql_port= (unsigned int) atoi(optarg); opt_mysql_port= (unsigned int) atoi(argument);
break; break;
case 'S': case 'S':
my_free(opt_mysql_unix_port,MYF(MY_ALLOW_ZERO_PTR)); my_free(opt_mysql_unix_port, MYF(MY_ALLOW_ZERO_PTR));
opt_mysql_unix_port= my_strdup(optarg,MYF(0)); opt_mysql_unix_port= my_strdup(argument, MYF(0));
break; break;
case 'W': case 'W':
#ifdef __WIN__ #ifdef __WIN__
opt_mysql_unix_port=my_strdup(MYSQL_NAMEDPIPE,MYF(0)); opt_mysql_unix_port= my_strdup(MYSQL_NAMEDPIPE, MYF(0));
#endif #endif
break; break;
case 'V': usage(1); exit(0); case 'V':
usage(1);
exit(0);
case 'I': case 'I':
case '?': case '?':
usage(0); usage(0);
exit(0); exit(0);
#include "sslopt-case.h" #include "sslopt-case.h"
default:
tee_fprintf(stderr,"illegal option: -%c\n",opterr);
usage(0);
exit(1);
}
} }
return 0;
}
static int get_options(int argc, char **argv)
{
char *tmp, *pagpoint;
int ho_error;
tmp= (char *) getenv("MYSQL_HOST");
if (tmp)
current_host= my_strdup(tmp, MYF(MY_WME));
pagpoint= getenv("PAGER");
if (!((char*) (pagpoint)))
{
strmov(pager, "stdout");
opt_nopager= 1;
}
else
strmov(pager, pagpoint);
strmov(default_pager, pager);
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
{
printf("%s: handle_options() failed with error %d\n", my_progname,
ho_error);
exit(1);
}
if (status.batch) /* disable pager and outfile in this case */ if (status.batch) /* disable pager and outfile in this case */
{ {
strmov(default_pager, "stdout"); strmov(default_pager, "stdout");
strmov(pager, "stdout"); strmov(pager, "stdout");
opt_nopager=1; opt_nopager= 1;
opt_outfile=0; opt_outfile= 0;
} }
if (default_charset) if (default_charset)
{ {
if (set_default_charset_by_name(default_charset, MYF(MY_WME))) if (set_default_charset_by_name(default_charset, MYF(MY_WME)))
exit(1); exit(1);
} }
argc-=optind;
argv+=optind;
if (argc > 1) if (argc > 1)
{ {
usage(0); usage(0);
...@@ -789,17 +779,11 @@ static int get_options(int argc, char **argv) ...@@ -789,17 +779,11 @@ static int get_options(int argc, char **argv)
} }
if (argc == 1) if (argc == 1)
{ {
my_free(current_db,MYF(MY_ALLOW_ZERO_PTR)); my_free(current_db, MYF(MY_ALLOW_ZERO_PTR));
current_db= my_strdup(*argv,MYF(MY_WME)); current_db= my_strdup(*argv, MYF(MY_WME));
}
if (!current_host)
{ /* If we don't have a hostname have a look at MYSQL_HOST */
char *tmp=(char *) getenv("MYSQL_HOST");
if (tmp)
current_host = my_strdup(tmp,MYF(MY_WME));
} }
if (tty_password) if (tty_password)
opt_password=get_tty_password(NullS); opt_password= get_tty_password(NullS);
return(0); return(0);
} }
...@@ -875,7 +859,7 @@ static int read_lines(bool execute_commands) ...@@ -875,7 +859,7 @@ static int read_lines(bool execute_commands)
/* Check if line is a mysql command line */ /* Check if line is a mysql command line */
/* (We want to allow help, print and clear anywhere at line start */ /* (We want to allow help, print and clear anywhere at line start */
if (execute_commands && (!no_named_cmds || glob_buffer.is_empty()) if (execute_commands && (named_cmds || glob_buffer.is_empty())
&& !in_string && (com=find_command(line,0))) && !in_string && (com=find_command(line,0)))
{ {
if ((*com->func)(&glob_buffer,line) > 0) if ((*com->func)(&glob_buffer,line) > 0)
...@@ -1365,7 +1349,7 @@ com_help (String *buffer __attribute__((unused)), ...@@ -1365,7 +1349,7 @@ com_help (String *buffer __attribute__((unused)),
reg1 int i; reg1 int i;
put_info("\nMySQL commands:",INFO_INFO); put_info("\nMySQL commands:",INFO_INFO);
if (no_named_cmds) if (!named_cmds)
put_info("Note that all text commands must be first on line and end with ';'",INFO_INFO); put_info("Note that all text commands must be first on line and end with ';'",INFO_INFO);
for (i = 0; commands[i].name; i++) for (i = 0; commands[i].name; i++)
{ {
...@@ -1615,7 +1599,7 @@ print_table_data(MYSQL_RES *result) ...@@ -1615,7 +1599,7 @@ print_table_data(MYSQL_RES *result)
separator.copy("+",1); separator.copy("+",1);
while ((field = mysql_fetch_field(result))) while ((field = mysql_fetch_field(result)))
{ {
uint length=skip_column_names ? 0 : (uint) strlen(field->name); uint length= column_names ? (uint) strlen(field->name) : 0;
if (quick) if (quick)
length=max(length,field->length); length=max(length,field->length);
else else
...@@ -1627,7 +1611,7 @@ print_table_data(MYSQL_RES *result) ...@@ -1627,7 +1611,7 @@ print_table_data(MYSQL_RES *result)
separator.append('+'); separator.append('+');
} }
tee_puts(separator.c_ptr(), PAGER); tee_puts(separator.c_ptr(), PAGER);
if (!skip_column_names) if (column_names)
{ {
mysql_field_seek(result,0); mysql_field_seek(result,0);
(void) tee_fputs("|", PAGER); (void) tee_fputs("|", PAGER);
...@@ -1672,7 +1656,7 @@ print_table_data_html(MYSQL_RES *result) ...@@ -1672,7 +1656,7 @@ print_table_data_html(MYSQL_RES *result)
mysql_field_seek(result,0); mysql_field_seek(result,0);
(void) tee_fputs("<TABLE BORDER=1><TR>", PAGER); (void) tee_fputs("<TABLE BORDER=1><TR>", PAGER);
if (!skip_column_names) if (column_names)
{ {
while((field = mysql_fetch_field(result))) while((field = mysql_fetch_field(result)))
{ {
...@@ -1835,7 +1819,7 @@ print_tab_data(MYSQL_RES *result) ...@@ -1835,7 +1819,7 @@ print_tab_data(MYSQL_RES *result)
MYSQL_FIELD *field; MYSQL_FIELD *field;
ulong *lengths; ulong *lengths;
if (opt_silent < 2 && !skip_column_names) if (opt_silent < 2 && column_names)
{ {
int first=0; int first=0;
while ((field = mysql_fetch_field(result))) while ((field = mysql_fetch_field(result)))
...@@ -2187,7 +2171,7 @@ com_use(String *buffer __attribute__((unused)), char *line) ...@@ -2187,7 +2171,7 @@ com_use(String *buffer __attribute__((unused)), char *line)
if (!current_db || cmp_database(current_db,tmp)) if (!current_db || cmp_database(current_db,tmp))
{ {
if (one_database) if (one_database)
skip_updates=1; skip_updates= 1;
else else
{ {
/* /*
...@@ -2214,7 +2198,7 @@ com_use(String *buffer __attribute__((unused)), char *line) ...@@ -2214,7 +2198,7 @@ com_use(String *buffer __attribute__((unused)), char *line)
} }
} }
else else
skip_updates=0; skip_updates= 0;
put_info("Database changed",INFO_INFO); put_info("Database changed",INFO_INFO);
return 0; return 0;
} }
...@@ -2248,8 +2232,8 @@ sql_real_connect(char *host,char *database,char *user,char *password, ...@@ -2248,8 +2232,8 @@ sql_real_connect(char *host,char *database,char *user,char *password,
select_limit,max_join_size); select_limit,max_join_size);
mysql_options(&mysql, MYSQL_INIT_COMMAND, init_command); mysql_options(&mysql, MYSQL_INIT_COMMAND, init_command);
} }
if (!mysql_real_connect(&mysql,host,user,password, if (!mysql_real_connect(&mysql, host, user, password,
database,opt_mysql_port,opt_mysql_unix_port, database, opt_mysql_port, opt_mysql_unix_port,
connect_flag)) connect_flag))
{ {
if (!silent || if (!silent ||
...@@ -2406,7 +2390,7 @@ put_info(const char *str,INFO_TYPE info_type,uint error) ...@@ -2406,7 +2390,7 @@ put_info(const char *str,INFO_TYPE info_type,uint error)
fprintf(stderr,"ERROR"); fprintf(stderr,"ERROR");
if (error) if (error)
(void) fprintf(stderr," %d",error); (void) fprintf(stderr," %d",error);
if (status.query_start_line && ! skip_line_numbers) if (status.query_start_line && line_numbers)
{ {
(void) fprintf(stderr," at line %lu",status.query_start_line); (void) fprintf(stderr," at line %lu",status.query_start_line);
if (status.file_name) if (status.file_name)
......
...@@ -19,21 +19,24 @@ ...@@ -19,21 +19,24 @@
#include "client_priv.h" #include "client_priv.h"
#include <signal.h> #include <signal.h>
#include <my_getopt.h>
#ifdef THREAD #ifdef THREAD
#include <my_pthread.h> /* because of signal() */ #include <my_pthread.h> /* because of signal() */
#endif #endif
#define ADMIN_VERSION "8.23" #define ADMIN_VERSION "8.30"
#define MAX_MYSQL_VAR 64 #define MAX_MYSQL_VAR 64
#define SHUTDOWN_DEF_TIMEOUT 3600 /* Wait for shutdown */ #define SHUTDOWN_DEF_TIMEOUT 3600 /* Wait for shutdown */
#define MAX_TRUNC_LENGTH 3 #define MAX_TRUNC_LENGTH 3
char *host= NULL, *user= 0, *opt_password= 0;
char truncated_var_names[MAX_MYSQL_VAR][MAX_TRUNC_LENGTH]; char truncated_var_names[MAX_MYSQL_VAR][MAX_TRUNC_LENGTH];
char ex_var_names[MAX_MYSQL_VAR][FN_REFLEN]; char ex_var_names[MAX_MYSQL_VAR][FN_REFLEN];
ulonglong last_values[MAX_MYSQL_VAR]; ulonglong last_values[MAX_MYSQL_VAR];
static int interval=0; static int interval=0;
static my_bool option_force=0,interrupted=0,new_line=0, static my_bool option_force=0,interrupted=0,new_line=0,
opt_compress=0, opt_relative=0, opt_verbose=0, opt_vertical=0; opt_compress=0, opt_relative=0, opt_verbose=0, opt_vertical=0,
tty_password=0;
static uint tcp_port = 0, option_wait = 0, option_silent=0; static uint tcp_port = 0, option_wait = 0, option_silent=0;
static ulong opt_connect_timeout, opt_shutdown_timeout; static ulong opt_connect_timeout, opt_shutdown_timeout;
static my_string unix_port=0; static my_string unix_port=0;
...@@ -49,8 +52,7 @@ static uint ex_var_count, max_var_length, max_val_length; ...@@ -49,8 +52,7 @@ static uint ex_var_count, max_var_length, max_val_length;
static void print_version(void); static void print_version(void);
static void usage(void); static void usage(void);
static my_bool sql_connect(MYSQL *mysql,const char *host, const char *user, static my_bool sql_connect(MYSQL *mysql, uint wait);
const char *password,uint wait);
static int execute_commands(MYSQL *mysql,int argc, char **argv); static int execute_commands(MYSQL *mysql,int argc, char **argv);
static int drop_db(MYSQL *mysql,const char *db); static int drop_db(MYSQL *mysql,const char *db);
static sig_handler endprog(int signal_number); static sig_handler endprog(int signal_number);
...@@ -97,158 +99,176 @@ static const char *command_names[]= { ...@@ -97,158 +99,176 @@ static const char *command_names[]= {
static TYPELIB command_typelib= static TYPELIB command_typelib=
{ array_elements(command_names)-1,"commands", command_names}; { array_elements(command_names)-1,"commands", command_names};
static struct option long_options[] = { static struct my_option my_long_options[] =
{"compress", no_argument, 0, 'C'}, {
{"character-sets-dir", required_argument, 0, OPT_CHARSETS_DIR}, {"debug", '#', "Output debug log. Often this is 'd:t:o,filename'",
{"debug", optional_argument, 0, '#'}, 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"force", no_argument, 0, 'f'}, {"force", 'f',
{"help", no_argument, 0, '?'}, "Don't ask for confirmation on drop database; with multiple commands, continue even if an error occurs.",
{"host", required_argument, 0, 'h'}, (gptr*) &option_force, (gptr*) &option_force, 0, GET_BOOL, NO_ARG, 0, 0,
{"password", optional_argument, 0, 'p'}, 0, 0, 0, 0},
{"compress", 'C', "Use compression in server/client protocol",
(gptr*) &opt_compress, (gptr*) &opt_compress, 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},
{"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
{"host", 'h', "Connect to host", (gptr*) &host, (gptr*) &host, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"password", 'p',
"Password to use when connecting to server. If password is not given it's asked from the tty.",
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
#ifdef __WIN__ #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 #endif
{"port", required_argument, 0, 'P'}, {"port", 'P', "Port number to use for connection.", 0, 0, 0,
{"relative", no_argument, 0, 'r'}, GET_LONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"set-variable", required_argument, 0, 'O'}, {"relative", 'r',
{"silent", no_argument, 0, 's'}, "Show difference between current and previous values when used with -i. Currently works only with extended-status.",
{"socket", required_argument, 0, 'S'}, (gptr*) &opt_relative, (gptr*) &opt_relative, 0, GET_BOOL, NO_ARG, 0, 0, 0,
{"sleep", required_argument, 0, 'i'}, 0, 0, 0},
{"set-variable", 'O',
"Change the value of a variable. Please note that this option is depricated; you can set variables directly with --variable-name=value.",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"silent", 's', "Silently exit if one can't connect to server",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"socket", 'S', "Socket file to use for connection.",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"sleep", 'i', "Execute commands again and again with a sleep between.",
0, 0, 0, GET_LONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#include "sslopt-longopts.h" #include "sslopt-longopts.h"
#ifndef DONT_ALLOW_USER_CHANGE #ifndef DONT_ALLOW_USER_CHANGE
{"user", required_argument, 0, 'u'}, {"user", 'u', "User for login if not current user.", (gptr*) &user,
(gptr*) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#endif #endif
{"verbose", no_argument, 0, 'v'}, {"verbose", 'v', "Write more information.", (gptr*) &opt_verbose,
{"version", no_argument, 0, 'V'}, (gptr*) &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"vertical", no_argument, 0, 'E'}, {"version", 'V', "Output version information and exit", 0, 0, 0, GET_NO_ARG,
{"wait", optional_argument, 0, 'w'}, NO_ARG, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0} {"vertical", 'E',
"Print output vertically. Is similar to --relative, but prints output vertically.",
(gptr*) &opt_vertical, (gptr*) &opt_vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0,
0, 0, 0},
{"wait", 'w', "Wait and retry if connection is down", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
{"connect_timeout", OPT_CONNECT_TIMEOUT, "", (gptr*) &opt_connect_timeout,
(gptr*) &opt_connect_timeout, 0, GET_LONG, REQUIRED_ARG, 3600*12, 0,
3600*12, 0, 1, 0},
{"shutdown_timeout", OPT_SHUTDOWN_TIMEOUT, "", (gptr*) &opt_shutdown_timeout,
(gptr*) &opt_shutdown_timeout, 0, GET_LONG, REQUIRED_ARG,
SHUTDOWN_DEF_TIMEOUT, 0, 3600*12, 0, 1, 0},
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
}; };
static CHANGEABLE_VAR changeable_vars[] = {
{ "connect_timeout", (long*) &opt_connect_timeout, 0, 0, 3600*12, 0, 1},
{ "shutdown_timeout", (long*) &opt_shutdown_timeout, SHUTDOWN_DEF_TIMEOUT, 0,
3600*12, 0, 1},
{ 0, 0, 0, 0, 0, 0, 0}
};
static const char *load_default_groups[]= { "mysqladmin","client",0 }; static const char *load_default_groups[]= { "mysqladmin","client",0 };
int main(int argc,char *argv[]) static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{ {
int c, error = 0,option_index=0; int error = 0;
MYSQL mysql;
char *host = NULL,*opt_password=0,*user=0,**commands; switch(optid) {
my_bool tty_password=0; case 'h':
MY_INIT(argv[0]); host = argument;
mysql_init(&mysql); break;
load_defaults("my",load_default_groups,&argc,&argv); case 'q': /* Allow old 'q' option */
set_all_changeable_vars( changeable_vars ); case 'p':
if (argument)
while ((c=getopt_long(argc,argv, {
(char*) "h:i:p::u:#::P:sS:Ct:fq?vVw::WrEO:", char *start=argument;
long_options, &option_index)) != EOF) my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
{ opt_password=my_strdup(argument,MYF(MY_FAE));
switch(c) { while (*argument) *argument++= 'x'; /* Destroy argument */
case 'C': if (*start)
opt_compress=1; start[1]=0; /* Cut length of argument */
break; }
case 'h': else
host = optarg; tty_password=1;
break; break;
case 'q': /* Allow old 'q' option */
case 'f':
option_force++;
break;
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;
#ifndef DONT_ALLOW_USER_CHANGE #ifndef DONT_ALLOW_USER_CHANGE
case 'u': case 'u':
user= my_strdup(optarg,MYF(0)); user= my_strdup(argument,MYF(0));
break; break;
#endif #endif
case 'i': case 'i':
interval=atoi(optarg); interval=atoi(argument);
break; break;
case 'P': case 'P':
tcp_port= (unsigned int) atoi(optarg); tcp_port= (unsigned int) atoi(argument);
break; break;
case 'r': case 's':
opt_relative = 1; option_silent++;
break; break;
case 'E': case 'S':
opt_vertical = 1; unix_port= argument;
break; break;
case 'O': case 'W':
if (set_changeable_var(optarg, changeable_vars))
{
usage();
return(1);
}
break;
case 's':
option_silent++;
break;
case 'S':
unix_port= optarg;
break;
case 'W':
#ifdef __WIN__ #ifdef __WIN__
unix_port=MYSQL_NAMEDPIPE; unix_port=MYSQL_NAMEDPIPE;
#endif #endif
break; break;
case '#': case '#':
DBUG_PUSH(optarg ? optarg : "d:t:o,/tmp/mysqladmin.trace"); DBUG_PUSH(argument ? argument : "d:t:o,/tmp/mysqladmin.trace");
break; break;
case 'V': case 'V':
print_version(); print_version();
exit(0); exit(0);
break; break;
case 'v': case 'w':
opt_verbose=1; if (argument)
break; {
case 'w': if ((option_wait=atoi(argument)) <= 0)
if (optarg) option_wait=1;
{ }
if ((option_wait=atoi(optarg)) <= 0) else
option_wait=1; option_wait= ~0;
} break;
else
option_wait= ~0;
break;
#include "sslopt-case.h" #include "sslopt-case.h"
default: case '?':
fprintf(stderr,"Illegal option character '%c'\n",opterr); case 'I': /* Info */
/* Fall throught */ error++;
case '?': break;
case 'I': /* Info */ case OPT_CHARSETS_DIR:
error++;
break;
case OPT_CHARSETS_DIR:
#if MYSQL_VERSION_ID > 32300 #if MYSQL_VERSION_ID > 32300
charsets_dir = optarg; charsets_dir = argument;
#endif #endif
break; break;
} }
if (error)
{
usage();
exit(1);
}
return 0;
}
int main(int argc,char *argv[])
{
int error, ho_error;
MYSQL mysql;
char **commands;
MY_INIT(argv[0]);
mysql_init(&mysql);
load_defaults("my",load_default_groups,&argc,&argv);
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
{
printf("%s: handle_options() failed with error %d\n", my_progname,
ho_error);
exit(1);
} }
argc -= optind; if (argc == 0)
commands = argv + optind;
if (error || argc == 0)
{ {
usage(); usage();
exit(1); exit(1);
} }
commands = argv;
if (tty_password) if (tty_password)
opt_password = get_tty_password(NullS); opt_password = get_tty_password(NullS);
...@@ -267,7 +287,7 @@ int main(int argc,char *argv[]) ...@@ -267,7 +287,7 @@ int main(int argc,char *argv[])
mysql_ssl_set(&mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca, mysql_ssl_set(&mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
opt_ssl_capath, opt_ssl_cipher); opt_ssl_capath, opt_ssl_cipher);
#endif /* HAVE_OPENSSL */ #endif /* HAVE_OPENSSL */
if (sql_connect(&mysql,host,user,opt_password,option_wait)) if (sql_connect(&mysql, option_wait))
error = 1; error = 1;
else else
{ {
...@@ -284,7 +304,7 @@ int main(int argc,char *argv[]) ...@@ -284,7 +304,7 @@ int main(int argc,char *argv[])
if (option_wait && !interrupted) if (option_wait && !interrupted)
{ {
mysql_close(&mysql); mysql_close(&mysql);
if (!sql_connect(&mysql,host,user,opt_password,option_wait)) if (!sql_connect(&mysql, option_wait))
{ {
sleep(1); /* Don't retry too rapidly */ sleep(1); /* Don't retry too rapidly */
continue; /* Retry */ continue; /* Retry */
...@@ -320,15 +340,14 @@ static sig_handler endprog(int signal_number __attribute__((unused))) ...@@ -320,15 +340,14 @@ static sig_handler endprog(int signal_number __attribute__((unused)))
} }
static my_bool sql_connect(MYSQL *mysql,const char *host, const char *user, static my_bool sql_connect(MYSQL *mysql, uint wait)
const char *password,uint wait)
{ {
my_bool info=0; my_bool info=0;
for (;;) for (;;)
{ {
if (mysql_real_connect(mysql,host,user,password,NullS,tcp_port,unix_port, if (mysql_real_connect(mysql,host,user,opt_password,NullS,tcp_port,
0)) unix_port, 0))
{ {
if (info) if (info)
{ {
...@@ -343,7 +362,7 @@ static my_bool sql_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -343,7 +362,7 @@ static my_bool sql_connect(MYSQL *mysql,const char *host, const char *user,
if (!option_silent) if (!option_silent)
{ {
if (!host) if (!host)
host=LOCAL_HOST; host= (char*) LOCAL_HOST;
my_printf_error(0,"connect to server at '%s' failed\nerror: '%s'", my_printf_error(0,"connect to server at '%s' failed\nerror: '%s'",
MYF(ME_BELL), host, mysql_error(mysql)); MYF(ME_BELL), host, mysql_error(mysql));
if (mysql_errno(mysql) == CR_CONNECTION_ERROR) if (mysql_errno(mysql) == CR_CONNECTION_ERROR)
...@@ -788,52 +807,14 @@ static void print_version(void) ...@@ -788,52 +807,14 @@ static void print_version(void)
static void usage(void) static void usage(void)
{ {
uint i;
print_version(); print_version();
puts("Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB"); puts("Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB");
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"); 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");
puts("Administration program for the mysqld daemon."); puts("Administration program for the mysqld daemon.");
printf("Usage: %s [OPTIONS] command command....\n", my_progname); printf("Usage: %s [OPTIONS] command command....\n", my_progname);
printf("\n\ my_print_help(my_long_options);
-#, --debug=... Output debug log. Often this is 'd:t:o,filename`\n\ my_print_variables(my_long_options);
-f, --force Don't ask for confirmation on drop database; with\n\
multiple commands, continue even if an error occurs\n\
-?, --help Display this help and exit\n\
--character-sets-dir=...\n\
Set the character set directory\n\
-C, --compress Use compression in server/client protocol\n\
-h, --host=# Connect to host\n\
-p, --password[=...] Password to use when connecting to server\n\
If password is not given it's asked from 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\
-i, --sleep=sec Execute commands again and again with a sleep between\n\
-r, --relative Show difference between current and previous values\n\
when used with -i. Currently works only with\n\
extended-status\n\
-E, --vertical Print output vertically. Is similar to --relative,\n\
but prints output vertically.\n\
-s, --silent Silently exit if one can't connect to server\n\
-S, --socket=... Socket file to use for connection\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 Write more information\n\
-V, --version Output version information and exit\n\
-w, --wait[=retries] Wait and retry if connection is down\n");
print_defaults("my",load_default_groups); print_defaults("my",load_default_groups);
printf("\nPossible variables for option --set-variable (-O) are:\n");
for (i=0 ; changeable_vars[i].name ; i++)
printf("%-20s current value: %lu\n",
changeable_vars[i].name,
(ulong) *changeable_vars[i].varptr);
puts("\nWhere command is a one or more of: (Commands may be shortened)\n\ puts("\nWhere command is a one or more of: (Commands may be shortened)\n\
create databasename Create a new database\n\ create databasename Create a new database\n\
drop databasename Delete a database and all its tables\n\ drop databasename Delete a database and all its tables\n\
......
...@@ -16,9 +16,10 @@ ...@@ -16,9 +16,10 @@
/* By Jani Tolonen, 2001-04-20, MySQL Development Team */ /* By Jani Tolonen, 2001-04-20, MySQL Development Team */
#define CHECK_VERSION "1.02" #define CHECK_VERSION "2.0"
#include "client_priv.h" #include "client_priv.h"
#include <my_getopt.h>
#include <m_ctype.h> #include <m_ctype.h>
#include "mysql_version.h" #include "mysql_version.h"
#include "mysqld_error.h" #include "mysqld_error.h"
...@@ -33,7 +34,8 @@ static MYSQL mysql_connection, *sock = 0; ...@@ -33,7 +34,8 @@ static MYSQL mysql_connection, *sock = 0;
static my_bool opt_alldbs = 0, opt_check_only_changed = 0, opt_extended = 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_compress = 0, opt_databases = 0, opt_fast = 0,
opt_medium_check = 0, opt_quick = 0, opt_all_in_1 = 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 uint verbose = 0, opt_mysql_port=0;
static my_string opt_mysql_unix_port = 0; static my_string opt_mysql_unix_port = 0;
static char *opt_password = 0, *current_user = 0, *default_charset = 0, static char *opt_password = 0, *current_user = 0, *default_charset = 0,
...@@ -43,45 +45,96 @@ DYNAMIC_ARRAY tables4repair; ...@@ -43,45 +45,96 @@ DYNAMIC_ARRAY tables4repair;
enum operations {DO_CHECK, DO_REPAIR, DO_ANALYZE, DO_OPTIMIZE}; 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-databases", 'A',
{"all-in-1", no_argument, 0, '1'}, "Check all the databases. This will be same as --databases with all databases selected.",
{"auto-repair", no_argument, 0, OPT_AUTO_REPAIR}, (gptr*) &opt_alldbs, (gptr*) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
{"analyze", no_argument, 0, 'a'}, 0, 0},
{"character-sets-dir", required_argument, 0, OPT_CHARSETS_DIR}, {"analyze", 'a', "Analyze given tables.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
{"check", no_argument, 0, 'c'}, 0, 0, 0, 0},
{"check-only-changed", no_argument, 0, 'C'}, {"all-in-1", '1',
{"compress", no_argument, 0, OPT_COMPRESS}, "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.",
{"databases", no_argument, 0, 'B'}, (gptr*) &opt_all_in_1, (gptr*) &opt_all_in_1, 0, GET_BOOL, NO_ARG, 0, 0, 0,
{"debug", optional_argument, 0, '#'}, 0, 0, 0},
{"default-character-set", required_argument, 0, OPT_DEFAULT_CHARSET}, {"auto-repair", OPT_AUTO_REPAIR,
{"fast", no_argument, 0, 'F'}, "If a checked table is corrupted, automatically fix it. Repairing will be done after all tables have been checked, if corrupted ones were found.",
{"force", no_argument, 0, 'f'}, (gptr*) &opt_auto_repair, (gptr*) &opt_auto_repair, 0, GET_BOOL, NO_ARG, 0,
{"extended", no_argument, 0, 'e'}, 0, 0, 0, 0, 0},
{"help", no_argument, 0, '?'}, {"character-sets-dir", OPT_CHARSETS_DIR,
{"host", required_argument, 0, 'h'}, "Directory where character sets are", (gptr*) &charsets_dir,
{"medium-check", no_argument, 0, 'm'}, (gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"optimize", no_argument, 0, 'o'}, {"check", 'c', "Check table for errors", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
{"password", optional_argument, 0, 'p'}, 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__ #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 #endif
{"port", required_argument, 0, 'P'}, {"port", 'P', "Port number to use for connection.", 0, 0, 0, GET_LONG,
{"quick", no_argument, 0, 'q'}, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"repair", no_argument, 0, 'r'}, {"quick", 'q',
{"silent", no_argument, 0, 's'}, "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.",
{"socket", required_argument, 0, 'S'}, (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" #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 #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 #endif
{"verbose", no_argument, 0, 'v'}, {"verbose", 'v', "Print info about the various stages.", 0, 0, 0, GET_NO_ARG,
{"version", no_argument, 0, 'V'}, NO_ARG, 0, 0, 0, 0, 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 }; static const char *load_default_groups[] = { "mysqlcheck", "client", 0 };
...@@ -131,78 +184,99 @@ static void usage(void) ...@@ -131,78 +184,99 @@ static void usage(void)
printf("OR %s [OPTIONS] --databases DB1 [DB2 DB3...]\n", printf("OR %s [OPTIONS] --databases DB1 [DB2 DB3...]\n",
my_progname); my_progname);
printf("OR %s [OPTIONS] --all-databases\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); print_defaults("my", load_default_groups);
my_print_help(my_long_options);
my_print_variables(my_long_options);
} /* usage */ } /* 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) static int get_options(int *argc, char ***argv)
{ {
int c, option_index; int ho_error;
my_bool tty_password = 0;
if (*argc == 1) if (*argc == 1)
{ {
...@@ -211,119 +285,14 @@ static int get_options(int *argc, char ***argv) ...@@ -211,119 +285,14 @@ static int get_options(int *argc, char ***argv)
} }
load_defaults("my", load_default_groups, argc, 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) { printf("%s: handle_options() failed with error %d\n", my_progname,
case 'a': ho_error);
what_to_do = DO_ANALYZE; exit(1);
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"
}
} }
if (!what_to_do) if (!what_to_do)
{ {
int pnlen = strlen(my_progname); int pnlen = strlen(my_progname);
...@@ -344,8 +313,6 @@ static int get_options(int *argc, char ***argv) ...@@ -344,8 +313,6 @@ static int get_options(int *argc, char ***argv)
if (set_default_charset_by_name(default_charset, MYF(MY_WME))) if (set_default_charset_by_name(default_charset, MYF(MY_WME)))
exit(1); exit(1);
} }
(*argc) -= optind;
(*argv) += optind;
if (*argc > 0 && opt_alldbs) if (*argc > 0 && opt_alldbs)
{ {
printf("You should give only options, no arguments at all, with option\n"); printf("You should give only options, no arguments at all, with option\n");
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
** and adapted to mysqldump 05/11/01 by Jani Tolonen ** and adapted to mysqldump 05/11/01 by Jani Tolonen
*/ */
#define DUMP_VERSION "8.22" #define DUMP_VERSION "9.00"
#include <my_global.h> #include <my_global.h>
#include <my_sys.h> #include <my_sys.h>
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
#include "mysql.h" #include "mysql.h"
#include "mysql_version.h" #include "mysql_version.h"
#include "mysqld_error.h" #include "mysqld_error.h"
#include <getopt.h> #include <my_getopt.h>
/* Exit codes */ /* Exit codes */
...@@ -73,7 +73,8 @@ static my_bool verbose=0,tFlag=0,cFlag=0,dFlag=0,quick=0, extended_insert = 0, ...@@ -73,7 +73,8 @@ static my_bool verbose=0,tFlag=0,cFlag=0,dFlag=0,quick=0, extended_insert = 0,
ignore=0,opt_drop=0,opt_keywords=0,opt_lock=0,opt_compress=0, ignore=0,opt_drop=0,opt_keywords=0,opt_lock=0,opt_compress=0,
opt_delayed=0,create_options=0,opt_quoted=0,opt_databases=0, opt_delayed=0,create_options=0,opt_quoted=0,opt_databases=0,
opt_alldbs=0,opt_create_db=0,opt_first_slave=0, opt_alldbs=0,opt_create_db=0,opt_first_slave=0,
opt_autocommit=0,opt_master_data,opt_disable_keys=0,opt_xml=0; opt_autocommit=0,opt_master_data,opt_disable_keys=0,opt_xml=0,
tty_password=0;
static MYSQL mysql_connection,*sock=0; static MYSQL mysql_connection,*sock=0;
static char insert_pat[12 * 1024],*opt_password=0,*current_user=0, static char insert_pat[12 * 1024],*opt_password=0,*current_user=0,
*current_host=0,*path=0,*fields_terminated=0, *current_host=0,*path=0,*fields_terminated=0,
...@@ -87,69 +88,154 @@ static DYNAMIC_STRING extended_row; ...@@ -87,69 +88,154 @@ static DYNAMIC_STRING extended_row;
#include "sslopt-vars.h" #include "sslopt-vars.h"
FILE *md_result_file; FILE *md_result_file;
static struct option long_options[] = static struct my_option my_long_options[] =
{ {
{"all-databases", no_argument, 0, 'A'}, {"all-databases", 'A',
{"all", no_argument, 0, 'a'}, "Dump all the databases. This will be same as --databases with all databases selected.",
{"add-drop-table", no_argument, 0, OPT_DROP}, (gptr*) &opt_alldbs, (gptr*) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
{"add-locks", no_argument, 0, OPT_LOCKS}, 0, 0},
{"allow-keywords", no_argument, 0, OPT_KEYWORDS}, {"all", 'a', "Include all MySQL specific create options.", 0, 0, 0,
{"character-sets-dir",required_argument,0, OPT_CHARSETS_DIR}, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"complete-insert", no_argument, 0, 'c'}, {"add-drop-table", OPT_DROP, "Add a 'drop table' before each create.",
{"compress", no_argument, 0, 'C'}, (gptr*) &opt_drop, (gptr*) &opt_drop, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
{"databases", no_argument, 0, 'B'}, 0},
{"debug", optional_argument, 0, '#'}, {"add-locks", OPT_LOCKS, "Add locks around insert statements.",
{"default-character-set", required_argument, 0, OPT_DEFAULT_CHARSET}, (gptr*) &opt_lock, (gptr*) &opt_lock, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
{"delayed-insert", no_argument, 0, OPT_DELAYED}, 0},
{"disable-keys", no_argument, 0, 'K'}, {"allow-keywords", OPT_KEYWORDS,
{"extended-insert", no_argument, 0, 'e'}, "Allow creation of column names that are keywords.", (gptr*) &opt_keywords,
{"fields-terminated-by", required_argument, 0, (int) OPT_FTB}, (gptr*) &opt_keywords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"fields-enclosed-by", required_argument, 0, (int) OPT_ENC}, {"character-sets-dir", OPT_CHARSETS_DIR,
{"fields-optionally-enclosed-by", required_argument, 0, (int) OPT_O_ENC}, "Directory where character sets are", (gptr*) &charsets_dir,
{"fields-escaped-by", required_argument, 0, (int) OPT_ESC}, (gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"first-slave", no_argument, 0, 'x'}, {"complete-insert", 'c', "Use complete insert statements.", 0, 0, 0,
{"flush-logs", no_argument, 0, 'F'}, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"force", no_argument, 0, 'f'}, {"compress", 'C', "Use compression in server/client protocol.",
{"help", no_argument, 0, '?'}, (gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
{"host", required_argument, 0, 'h'}, 0, 0, 0},
{"lines-terminated-by", required_argument, 0, (int) OPT_LTB}, {"databases", 'B',
{"lock-tables", no_argument, 0, 'l'}, "To dump several databases. Note the difference in usage; In this case no tables are given. All name arguments are regarded as databasenames. 'USE db_name;' will be included in the output.",
{"master-data", no_argument, 0, OPT_MASTER_DATA}, (gptr*) &opt_databases, (gptr*) &opt_databases, 0, GET_BOOL, NO_ARG, 0, 0,
{"no-autocommit", no_argument, 0, OPT_AUTOCOMMIT}, 0, 0, 0, 0},
{"no-create-db", no_argument, 0, 'n'}, {"debug", '#', "Output debug log. Often this is 'd:t:o,filename'.",
{"no-create-info", no_argument, 0, 't'}, 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"no-data", no_argument, 0, 'd'}, {"default-character-set", OPT_DEFAULT_CHARSET,
{"opt", no_argument, 0, OPT_OPTIMIZE}, "Set the default character set.", (gptr*) &default_charset,
{"password", optional_argument, 0, 'p'}, (gptr*) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"delayed-insert", OPT_DELAYED, "Insert rows with INSERT DELAYED.",
(gptr*) &opt_delayed, (gptr*) &opt_delayed, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
0, 0},
{"disable-keys", 'K',
"'/*!40000 ALTER TABLE tb_name DISABLE KEYS */; and '/*!40000 ALTER TABLE tb_name ENABLE KEYS */; will be put in the output.", (gptr*) &opt_disable_keys,
(gptr*) &opt_disable_keys, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"extended-insert", 'e',
"Allows utilization of the new, much faster INSERT syntax.",
(gptr*) &extended_insert, (gptr*) &extended_insert, 0, GET_BOOL, NO_ARG,
0, 0, 0, 0, 0, 0},
{"fields-terminated-by", OPT_FTB,
"Fields in the textfile are terminated by ...", (gptr*) &fields_terminated,
(gptr*) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"fields-enclosed-by", OPT_ENC,
"Fields in the importfile are enclosed by ...", (gptr*) &enclosed,
(gptr*) &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
{"fields-optionally-enclosed-by", OPT_O_ENC,
"Fields in the i.file are opt. enclosed by ...", (gptr*) &opt_enclosed,
(gptr*) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0 ,0, 0},
{"fields-escaped-by", OPT_ESC, "Fields in the i.file are escaped by ...",
(gptr*) &escaped, (gptr*) &escaped, 0, GET_STR, NO_ARG, 0, 0, 0, 0, 0, 0},
{"first-slave", 'x', "Locks all tables across all databases.",
(gptr*) &opt_first_slave, (gptr*) &opt_first_slave, 0, GET_BOOL, NO_ARG,
0, 0, 0, 0, 0, 0},
{"flush-logs", 'F', "Flush logs file in server before starting dump.",
(gptr*) &flush_logs, (gptr*) &flush_logs, 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},
{"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},
{"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...",
(gptr*) &lines_terminated, (gptr*) &lines_terminated, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"lock-tables", 'l', "Lock all tables for read.", (gptr*) &lock_tables,
(gptr*) &lock_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"master-data", OPT_MASTER_DATA,
"This will cause the master position and filename to be appended to your output. This will automagically enable --first-slave.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"no-autocommit", OPT_AUTOCOMMIT,
"Wrap tables with autocommit/commit statements.",
(gptr*) &opt_autocommit, (gptr*) &opt_autocommit, 0, GET_BOOL, NO_ARG,
0, 0, 0, 0, 0, 0},
{"no-create-db", 'n',
"'CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;' will not be put in the output. The above line will be added otherwise, if --databases or --all-databases option was given.}",
(gptr*) &opt_create_db, (gptr*) &opt_create_db, 0, GET_BOOL, NO_ARG, 0, 0,
0, 0, 0, 0},
{"no-create-info", 't', "Don't write table creation info.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"no-data", 'd', "No row information.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
0, 0, 0, 0},
{"set-variable", 'O',
"Change the value of a variable. Please note that this option is depricated; you can set variables directly with --variable-name=value.",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"opt", OPT_OPTIMIZE,
"Same as --add-drop-table --add-locks --all --quick --extended-insert --lock-tables --disable-keys",
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__ #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 #endif
{"port", required_argument, 0, 'P'}, {"port", 'P', "Port number to use for connection.", 0, 0, 0, GET_LONG,
{"quick", no_argument, 0, 'q'}, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"quote-names", no_argument, 0, 'Q'}, {"quick", 'q', "Don't buffer query, dump directly to stdout.",
{"result-file", required_argument, 0, 'r'}, (gptr*) &quick, (gptr*) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"set-variable", required_argument, 0, 'O'}, {"quote-names",'Q', "Quote table and column names with a `",
{"socket", required_argument, 0, 'S'}, (gptr*) &opt_quoted, (gptr*) &opt_quoted, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
0, 0},
{"result-file", 'r',
"Direct output to a given file. This option should be used in MSDOS, because it prevents new line '\\n' from being converted to '\\n\\r' (newline + carriage return).",
(gptr*) &md_result_file, (gptr*) &md_result_file, 0, GET_STR, REQUIRED_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" #include "sslopt-longopts.h"
{"tab", required_argument, 0, 'T'}, {"tab",'T',
{"tables", no_argument, 0, OPT_TABLES}, "Creates tab separated textfile for each table to given path. (creates .sql and .txt files). NOTE: This only works if mysqldump is run on the same machine as the mysqld daemon.",
(gptr*) &path, (gptr*) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"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 #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 #endif
{"verbose", no_argument, 0, 'v'}, {"verbose", 'v', "Print info about the various stages.",
{"version", no_argument, 0, 'V'}, (gptr*) &verbose, (gptr*) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"where", required_argument, 0, 'w'}, {"version",'V', "Output version information and exit.", 0, 0, 0,
{"xml", no_argument, 0, 'X'}, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0} {"where", 'w', "Dump only selected records; QUOTES mandatory!",
(gptr*) &where, (gptr*) &where, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"xml", 'X', "Dump a database as well formed XML.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
{ "max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "",
(gptr*) &max_allowed_packet, (gptr*) &max_allowed_packet, 0,
GET_LONG, REQUIRED_ARG, 24*1024*1024, 4096, 512*1024L*1024L,
MALLOC_OVERHEAD, 1024, 0},
{ "net_buffer_length", OPT_NET_BUFFER_LENGTH, "",
(gptr*) &net_buffer_length, (gptr*) &net_buffer_length, 0,
GET_LONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 512*1024L*1024L,
MALLOC_OVERHEAD, 1024, 0},
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
}; };
static const char *load_default_groups[]= { "mysqldump","client",0 }; static const char *load_default_groups[]= { "mysqldump","client",0 };
CHANGEABLE_VAR md_changeable_vars[] = { CHANGEABLE_VAR md_changeable_vars[] = {
{ "max_allowed_packet", (long*) &max_allowed_packet,24*1024*1024,4096,
512*1024L*1024L,MALLOC_OVERHEAD,1024},
{ "net_buffer_length", (long*) &net_buffer_length,1024*1024L-1025,4096,
512*1024L*1024L,MALLOC_OVERHEAD,1024},
{ 0, 0, 0, 0, 0, 0, 0} { 0, 0, 0, 0, 0, 0, 0}
}; };
...@@ -184,101 +270,9 @@ static void usage(void) ...@@ -184,101 +270,9 @@ static void usage(void)
printf("OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n", printf("OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n",
my_progname); my_progname);
printf("OR %s [OPTIONS] --all-databases [OPTIONS]\n", my_progname); printf("OR %s [OPTIONS] --all-databases [OPTIONS]\n", my_progname);
printf("\n\
-A, --all-databases Dump all the databases. This will be same as\n\
--databases with all databases selected.\n\
-a, --all Include all MySQL specific create options.\n\
-#, --debug=... Output debug log. Often this is 'd:t:o,filename`.\n\
--character-sets-dir=...\n\
Directory where character sets are\n\
-?, --help Display this help message and exit.\n\
-B, --databases To dump several databases. Note the difference in\n\
usage; In this case no tables are given. All name\n\
arguments are regarded as databasenames.\n\
'USE db_name;' will be included in the output\n\
-c, --complete-insert Use complete insert statements.\n\
-C, --compress Use compression in server/client protocol.\n\
--default-character-set=...\n\
Set the default character set\n\
-e, --extended-insert Allows utilization of the new, much faster\n\
INSERT syntax.\n\
--add-drop-table Add a 'drop table' before each create.\n\
--add-locks Add locks around insert statements.\n\
--allow-keywords Allow creation of column names that are keywords.\n\
--delayed-insert Insert rows with INSERT DELAYED.\n\
--master-data This will cause the master position and filename to \n\
be appended to your output. This will automagically \n\
enable --first-slave.\n\
-F, --flush-logs Flush logs file in server before starting dump.\n\
-f, --force Continue even if we get an sql-error.\n\
-h, --host=... Connect to host.\n");
puts("\
-l, --lock-tables Lock all tables for read.\n\
--no-autocommit Wrap tables with autocommit/commit statements.\n\
-K, --disable-keys '/*!40000 ALTER TABLE tb_name DISABLE KEYS */;\n\
and '/*!40000 ALTER TABLE tb_name ENABLE KEYS */;\n\
will be put in the output.\n\
-n, --no-create-db 'CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;'\n\
will not be put in the output. The above line will\n\
be added otherwise, if --databases or\n\
--all-databases option was given.\n\
-t, --no-create-info Don't write table creation info.\n\
-d, --no-data No row information.\n\
-O, --set-variable var=option\n\
give a variable a value. --help lists variables\n\
--opt Same as --add-drop-table --add-locks --all --quick\n\
--extended-insert --lock-tables --disable-keys\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 Don't buffer query, dump directly to stdout.\n\
-Q, --quote-names Quote table and column names with `\n\
-r, --result-file=... Direct output to a given file. This option should be\n\
used in MSDOS, because it prevents new line '\\n'\n\
from being converted to '\\n\\r' (newline + carriage\n\
return).\n\
-S, --socket=... Socket file to use for connection.\n\
--tables Overrides option --databases (-B).\n");
#include "sslopt-usage.h"
printf("\
-T, --tab=... Creates tab separated textfile for each table to\n\
given path. (creates .sql and .txt files).\n\
NOTE: This only works if mysqldump is run on\n\
the same machine as the mysqld daemon.\n");
#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\
-w, --where= dump only selected records; QUOTES mandatory!\n\
-X, --xml dump a database as well formed XML\n\
-x, --first-slave Locks all tables across all databases.\n\
EXAMPLES: \"--where=user=\'jimf\'\" \"-wuserid>1\" \"-wuserid<1\"\n\
Use -T (--tab=...) with --fields-...\n\
--fields-terminated-by=...\n\
Fields in the textfile are terminated by ...\n\
--fields-enclosed-by=...\n\
Fields in the importfile are enclosed by ...\n\
--fields-optionally-enclosed-by=...\n\
Fields in the i.file are opt. enclosed by ...\n\
--fields-escaped-by=...\n\
Fields in the i.file are escaped by ...\n\
--lines-terminated-by=...\n\
Lines in the i.file are terminated by ...\n\
");
print_defaults("my",load_default_groups); print_defaults("my",load_default_groups);
my_print_help(my_long_options);
printf("\nPossible variables for option --set-variable (-O) are:\n"); my_print_variables(my_long_options);
for (i=0 ; md_changeable_vars[i].name ; i++)
printf("%-20s current value: %lu\n",
md_changeable_vars[i].name,
(ulong) *md_changeable_vars[i].varptr);
} /* usage */ } /* usage */
...@@ -300,179 +294,137 @@ static void write_header(FILE *sql_file, char *db_name) ...@@ -300,179 +294,137 @@ static void write_header(FILE *sql_file, char *db_name)
} /* write_header */ } /* write_header */
static int get_options(int *argc,char ***argv) static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
char *argument)
{ {
int c,option_index; switch(optid) {
my_bool tty_password=0; case OPT_MASTER_DATA:
opt_master_data=1;
md_result_file=stdout; opt_first_slave=1;
load_defaults("my",load_default_groups,argc,argv); break;
set_all_changeable_vars(md_changeable_vars); case 'a':
while ((c=getopt_long(*argc,*argv, create_options=1;
"#::p::h:u:O:P:r:S:T:EBaAcCdefFKlnqQtvVw:?IxX", break;
long_options, &option_index)) != EOF) case OPT_DEFAULT_CHARSET:
{ default_charset= argument;
switch(c) { break;
case OPT_MASTER_DATA: case OPT_CHARSETS_DIR:
opt_master_data=1; charsets_dir= argument;
opt_first_slave=1; break;
break; case 'h':
case OPT_AUTOCOMMIT: my_free(current_host,MYF(MY_ALLOW_ZERO_PTR));
opt_autocommit=1; current_host=my_strdup(argument,MYF(MY_WME));
break; break;
case 'a':
create_options=1;
break;
case 'e':
extended_insert=1;
break;
case 'A':
opt_alldbs=1;
break;
case OPT_DEFAULT_CHARSET:
default_charset= optarg;
break;
case OPT_CHARSETS_DIR:
charsets_dir= optarg;
break;
case 'f':
ignore_errors=1;
break;
case 'F':
flush_logs=1;
break;
case 'h':
my_free(current_host,MYF(MY_ALLOW_ZERO_PTR));
current_host=my_strdup(optarg,MYF(MY_WME));
break;
case 'K':
opt_disable_keys=1;
break;
case 'n':
opt_create_db = 1;
break;
#ifndef DONT_ALLOW_USER_CHANGE #ifndef DONT_ALLOW_USER_CHANGE
case 'u': case 'u':
current_user=optarg; current_user=argument;
break; break;
#endif #endif
case 'O': case 'p':
if (set_changeable_var(optarg, md_changeable_vars)) if (argument)
{ {
usage(); char *start=argument;
return(1); my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
} opt_password=my_strdup(argument,MYF(MY_FAE));
break; while (*argument) *argument++= 'x'; /* Destroy argument */
case 'p': if (*start)
if (optarg) start[1]=0; /* Cut length of argument */
{ }
char *start=optarg; else
my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR)); tty_password=1;
opt_password=my_strdup(optarg,MYF(MY_FAE)); break;
while (*optarg) *optarg++= 'x'; /* Destroy argument */ case 'P':
if (*start) opt_mysql_port= (unsigned int) atoi(argument);
start[1]=0; /* Cut length of argument */ break;
} case 'r':
else if (!(md_result_file = my_fopen(argument, O_WRONLY | O_BINARY,
tty_password=1; MYF(MY_WME))))
break; exit(1);
case 'P': break;
opt_mysql_port= (unsigned int) atoi(optarg); case 'S':
break; opt_mysql_unix_port= argument;
case 'r': break;
if (!(md_result_file = my_fopen(optarg, O_WRONLY | O_BINARY, case 'W':
MYF(MY_WME))))
exit(1);
break;
case 'S':
opt_mysql_unix_port= optarg;
break;
case 'W':
#ifdef __WIN__ #ifdef __WIN__
opt_mysql_unix_port=MYSQL_NAMEDPIPE; opt_mysql_unix_port=MYSQL_NAMEDPIPE;
#endif #endif
break; break;
case 'T': case 'T':
path= optarg; path= argument;
opt_disable_keys=0; opt_disable_keys=0;
break; break;
case 'B': case '#':
opt_databases = 1; DBUG_PUSH(argument ? argument : "d:t:o");
break; break;
case '#': case 'c': cFlag=1; break;
DBUG_PUSH(optarg ? optarg : "d:t:o"); case 'd': dFlag=1; break;
break; case 't': tFlag=1; break;
case 'c': cFlag=1; break; case 'V': print_version(); exit(0);
case 'C': case 'w':
opt_compress=1; where=argument;
break; break;
case 'd': dFlag=1; break; case 'X':
case 'l': lock_tables=1; break; opt_xml = 1;
case 'q': quick=1; break; opt_disable_keys=0;
case 'Q': opt_quoted=1; break; break;
case 't': tFlag=1; break; default:
case 'v': verbose=1; break; fprintf(stderr,"%s: Illegal option character '%c'\n",my_progname,opterr);
case 'V': print_version(); exit(0); /* Fall throught */
case 'w': case 'I':
where=optarg; case '?':
break; usage();
case 'X': exit(0);
opt_xml = 1; case (int) OPT_FTB:
opt_disable_keys=0; fields_terminated= argument;
break; break;
case 'x': case (int) OPT_LTB:
opt_first_slave=1; lines_terminated= argument;
break; break;
default: case (int) OPT_ENC:
fprintf(stderr,"%s: Illegal option character '%c'\n",my_progname,opterr); enclosed= argument;
/* Fall throught */ break;
case 'I': case (int) OPT_O_ENC:
case '?': opt_enclosed= argument;
usage(); break;
exit(0); case (int) OPT_ESC:
case (int) OPT_FTB: escaped= argument;
fields_terminated= optarg; break;
break; case (int) OPT_OPTIMIZE:
case (int) OPT_LTB: extended_insert=opt_drop=opt_lock=lock_tables=quick=create_options=
lines_terminated= optarg; opt_disable_keys=1;
break; break;
case (int) OPT_ENC: case (int) OPT_TABLES:
enclosed= optarg; opt_databases=0;
break; break;
case (int) OPT_O_ENC:
opt_enclosed= optarg;
break;
case (int) OPT_ESC:
escaped= optarg;
break;
case (int) OPT_DROP:
opt_drop=1;
break;
case (int) OPT_KEYWORDS:
opt_keywords=1;
break;
case (int) OPT_LOCKS:
opt_lock=1;
break;
case (int) OPT_OPTIMIZE:
extended_insert=opt_drop=opt_lock=lock_tables=quick=create_options=
opt_disable_keys=1;
break;
case (int) OPT_DELAYED:
opt_delayed=1;
break;
case (int) OPT_TABLES:
opt_databases=0;
break;
#include "sslopt-case.h" #include "sslopt-case.h"
}
} }
return 0;
}
static int get_options(int *argc, char ***argv)
{
int ho_error;
md_result_file= stdout;
load_defaults("my",load_default_groups,argc,argv);
set_all_changeable_vars(md_changeable_vars);
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
{
printf("%s: handle_options() failed with error %d\n", my_progname,
ho_error);
exit(1);
}
if (opt_delayed) if (opt_delayed)
opt_lock=0; /* Can't have lock with delayed */ opt_lock=0; /* Can't have lock with delayed */
if (!path && (enclosed || opt_enclosed || escaped || lines_terminated || if (!path && (enclosed || opt_enclosed || escaped || lines_terminated ||
fields_terminated)) fields_terminated))
{ {
fprintf(stderr, "%s: You must use option --tab with --fields-...\n", my_progname); fprintf(stderr,
"%s: You must use option --tab with --fields-...\n", my_progname);
return(1); return(1);
} }
...@@ -498,8 +450,6 @@ static int get_options(int *argc,char ***argv) ...@@ -498,8 +450,6 @@ static int get_options(int *argc,char ***argv)
if (set_default_charset_by_name(default_charset, MYF(MY_WME))) if (set_default_charset_by_name(default_charset, MYF(MY_WME)))
exit(1); exit(1);
} }
(*argc)-=optind;
(*argv)+=optind;
if ((*argc < 1 && !opt_alldbs) || (*argc > 0 && opt_alldbs)) if ((*argc < 1 && !opt_alldbs) || (*argc > 0 && opt_alldbs))
{ {
usage(); usage();
......
...@@ -25,10 +25,11 @@ ...@@ -25,10 +25,11 @@
** * * ** * *
** ************************* ** *************************
*/ */
#define IMPORT_VERSION "2.7" #define IMPORT_VERSION "3.0"
#include "client_priv.h" #include "client_priv.h"
#include "mysql_version.h" #include "mysql_version.h"
#include <my_getopt.h>
static void db_error_with_table(MYSQL *mysql, char *table); static void db_error_with_table(MYSQL *mysql, char *table);
static void db_error(MYSQL *mysql); static void db_error(MYSQL *mysql);
...@@ -37,53 +38,93 @@ static char *add_load_option(char *ptr,const char *object, ...@@ -37,53 +38,93 @@ static char *add_load_option(char *ptr,const char *object,
const char *statement); const char *statement);
static my_bool verbose=0,lock_tables=0,ignore_errors=0,opt_delete=0, static my_bool verbose=0,lock_tables=0,ignore_errors=0,opt_delete=0,
replace=0,silent=0,ignore=0,opt_compress=0,opt_local_file=0; replace=0,silent=0,ignore=0,opt_compress=0,opt_local_file=0,
opt_low_priority= 0, tty_password= 0;
static MYSQL mysql_connection; static MYSQL mysql_connection;
static char *opt_password=0, *current_user=0, static char *opt_password=0, *current_user=0,
*current_host=0, *current_db=0, *fields_terminated=0, *current_host=0, *current_db=0, *fields_terminated=0,
*lines_terminated=0, *enclosed=0, *opt_enclosed=0, *lines_terminated=0, *enclosed=0, *opt_enclosed=0,
*escaped=0, opt_low_priority=0, *opt_columns=0, *escaped=0, *opt_columns=0, *default_charset;
*default_charset;
static uint opt_mysql_port=0; static uint opt_mysql_port=0;
static my_string opt_mysql_unix_port=0; static my_string opt_mysql_unix_port=0;
#include "sslopt-vars.h" #include "sslopt-vars.h"
static struct option long_options[] = static struct my_option my_long_options[] =
{ {
{"character-sets-dir", required_argument, 0, OPT_CHARSETS_DIR}, {"character-sets-dir", OPT_CHARSETS_DIR,
{"default-character-set", required_argument, 0, OPT_DEFAULT_CHARSET}, "Directory where character sets are", (gptr*) &charsets_dir,
{"columns", required_argument, 0, 'c'}, (gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"compress", no_argument, 0, 'C'}, {"default-character-set", OPT_DEFAULT_CHARSET,
{"debug", optional_argument, 0, '#'}, "Set the default character set.", (gptr*) &default_charset,
{"delete", no_argument, 0, 'd'}, (gptr*) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"fields-terminated-by", required_argument, 0, (int) OPT_FTB}, {"columns", 'c',
{"fields-enclosed-by", required_argument, 0, (int) OPT_ENC}, "Use only these columns to import the data to. Give the column names in a comma separated list. This is same as giving columns to LOAD DATA INFILE.",
{"fields-optionally-enclosed-by", required_argument, 0, (int) OPT_O_ENC}, (gptr*) &opt_columns, (gptr*) &opt_columns, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
{"fields-escaped-by", required_argument, 0, (int) OPT_ESC}, 0, 0, 0},
{"force", no_argument, 0, 'f'}, {"compress", 'C', "Use compression in server/client protocol.",
{"help", no_argument, 0, '?'}, (gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
{"host", required_argument, 0, 'h'}, 0, 0, 0},
{"ignore", no_argument, 0, 'i'}, {"debug",'#', "Output debug log. Often this is 'd:t:o,filename'", 0, 0, 0,
{"lines-terminated-by", required_argument, 0, (int) OPT_LTB}, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"local", no_argument, 0, 'L'}, {"delete", 'd', "First delete all rows from table.", (gptr*) &opt_delete,
{"lock-tables", no_argument, 0, 'l'}, (gptr*) &opt_delete, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"low-priority", no_argument, 0, (int) OPT_LOW_PRIORITY}, {"fields-terminated-by", OPT_FTB,
{"password", optional_argument, 0, 'p'}, "Fields in the textfile are terminated by ...", (gptr*) &fields_terminated,
(gptr*) &fields_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"fields-enclosed-by", OPT_ENC,
"Fields in the importfile are enclosed by ...", (gptr*) &enclosed,
(gptr*) &enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"fields-optionally-enclosed-by", OPT_O_ENC,
"Fields in the i.file are opt. enclosed by ...", (gptr*) &opt_enclosed,
(gptr*) &opt_enclosed, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"fields-escaped-by", OPT_ESC, "Fields in the i.file are escaped by ...",
(gptr*) &escaped, (gptr*) &escaped, 0, GET_STR, REQUIRED_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},
{"help", '?', "Displays this help and exits.", 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},
{"ignore", 'i', "If duplicate unique key was found, keep old row.",
(gptr*) &ignore, (gptr*) &ignore, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...",
(gptr*) &lines_terminated, (gptr*) &lines_terminated, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"local", 'L', "Read all files through the client", (gptr*) &opt_local_file,
(gptr*) &opt_local_file, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"lock-tables", 'l', "Lock all tables for write.", (gptr*) &lock_tables,
(gptr*) &lock_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"low-priority", OPT_LOW_PRIORITY,
"Use LOW_PRIORITY when updating the table", (gptr*) &opt_low_priority,
(gptr*) &opt_low_priority, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"password", 'p',
"Password to use when connecting to server. If password is not given it's asked from the tty.",
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
#ifdef __WIN__ #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 #endif
{"port", required_argument, 0, 'P'}, {"port", 'P', "Port number to use for connection.", (gptr*) &opt_mysql_port,
{"replace", no_argument, 0, 'r'}, (gptr*) &opt_mysql_port, 0, GET_LONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"silent", no_argument, 0, 's'}, {"replace", 'r', "If duplicate unique key was found, replace old row.",
{"socket", required_argument, 0, 'S'}, (gptr*) &replace, (gptr*) &replace, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"silent", 's', "Be more silent.", (gptr*) &silent, (gptr*) &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" #include "sslopt-longopts.h"
#ifndef DONT_ALLOW_USER_CHANGE #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 #endif
{"verbose", no_argument, 0, 'v'}, {"verbose", 'v', "Print info about the various stages.", (gptr*) &verbose,
{"version", no_argument, 0, 'V'}, (gptr*) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 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}
}; };
...@@ -110,154 +151,97 @@ read the text file directly. In other cases the client will open the text\n\ ...@@ -110,154 +151,97 @@ read the text file directly. In other cases the client will open the text\n\
file. The SQL command 'LOAD DATA INFILE' is used to import the rows.\n"); file. The SQL command 'LOAD DATA INFILE' is used to import the rows.\n");
printf("\nUsage: %s [OPTIONS] database textfile...",my_progname); printf("\nUsage: %s [OPTIONS] database textfile...",my_progname);
printf("\n\
-#, --debug[=...] Output debug log. Often this is 'd:t:o,filename`\n\
-?, --help Displays this help and exits.\n\
--default-character-set=...\n\
Set the default character set.\n\
--character-sets-dir=...\n\
Directory where character sets are\n\
-c, --columns=... Use only these columns to import the data to.\n\
Give the column names in a comma separated list.\n\
This is same as giving columns to LOAD DATA INFILE.\n\
-C, --compress Use compression in server/client protocol\n\
-d, --delete First delete all rows from table.\n\
-f, --force Continue even if we get an sql-error.\n\
-h, --host=... Connect to host.\n\
-i, --ignore If duplicate unique key was found, keep old row.\n\
-l, --lock-tables Lock all tables for write.\n\
-L, --local Read all files through the client\n\
--low-priority Use LOW_PRIORITY when updating the table\n\
-p, --password[=...] Password to use when connecting to server.\n\
If password is not given it's asked from 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\
-r, --replace If duplicate unique key was found, replace old row.\n\
-s, --silent Be more silent.\n\
-S, --socket=... Socket file to use for connection.\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\
--fields-terminated-by=...\n\
Fields in the textfile are terminated by ...\n\
--fields-enclosed-by=...\n\
Fields in the importfile are enclosed by ...\n\
--fields-optionally-enclosed-by=...\n\
Fields in the i.file are opt. enclosed by ...\n\
--fields-escaped-by=...\n\
Fields in the i.file are escaped by ...\n\
--lines-terminated-by=...\n\
Lines in the i.file are terminated by ...\n\
");
print_defaults("my",load_default_groups); print_defaults("my",load_default_groups);
my_print_help(my_long_options);
my_print_variables(my_long_options);
} }
static int get_options(int *argc, char ***argv)
{
int c, option_index;
my_bool tty_password=0;
while ((c=getopt_long(*argc,*argv, static my_bool
(char*) "#::p::c:h:u:P:S:CdfilLrsvV?IW", get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
long_options, &option_index)) != EOF) char *argument)
{ {
switch(c) { switch(optid) {
case 'c': case 'c':
opt_columns= optarg; opt_columns= argument;
break; break;
case 'C': case OPT_DEFAULT_CHARSET:
opt_compress=1; default_charset= argument;
break; break;
case OPT_DEFAULT_CHARSET: case OPT_CHARSETS_DIR:
default_charset= optarg; charsets_dir= argument;
break; break;
case OPT_CHARSETS_DIR: case 'h':
charsets_dir= optarg; current_host= argument;
break; break;
case 'd':
opt_delete= 1;
break;
case 'f':
ignore_errors= 1;
break;
case 'h':
current_host= optarg;
break;
case 'i':
ignore= 1;
break;
#ifndef DONT_ALLOW_USER_CHANGE #ifndef DONT_ALLOW_USER_CHANGE
case 'u': case 'u':
current_user= optarg; current_user= argument;
break; break;
#endif #endif
case 'p': case 'p':
if (optarg) if (argument)
{ {
char *start=optarg; char *start=argument;
my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR)); my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
opt_password=my_strdup(optarg,MYF(MY_FAE)); opt_password=my_strdup(argument,MYF(MY_FAE));
while (*optarg) *optarg++= 'x'; /* Destroy argument */ while (*argument) *argument++= 'x'; /* Destroy argument */
if (*start) if (*start)
start[1]=0; /* Cut length of argument */ start[1]=0; /* Cut length of argument */
} }
else else
tty_password= 1; tty_password= 1;
break; break;
case 'P': case 'P':
opt_mysql_port= (unsigned int) atoi(optarg); opt_mysql_port= (unsigned int) atoi(argument);
break; break;
case 'r': case 'S':
replace= 1; opt_mysql_unix_port= argument;
break; break;
case 's':
silent= 1;
break;
case 'S':
opt_mysql_unix_port= optarg;
break;
#ifdef __WIN__ #ifdef __WIN__
case 'W': case 'W':
opt_mysql_unix_port=MYSQL_NAMEDPIPE; opt_mysql_unix_port=MYSQL_NAMEDPIPE;
opt_local_file=1; opt_local_file=1;
break; break;
#endif #endif
case '#': case '#':
DBUG_PUSH(optarg ? optarg : "d:t:o"); DBUG_PUSH(argument ? argument : "d:t:o");
break; break;
case 'l': lock_tables= 1; break; case 'V': print_version(); exit(0);
case 'L': opt_local_file=1; break; case 'I':
case 'v': verbose= 1; break; case '?':
case 'V': print_version(); exit(0); usage();
case 'I': exit(0);
case '?': case (int) OPT_FTB:
usage(); fields_terminated= argument;
exit(0); break;
case (int) OPT_FTB: case (int) OPT_LTB:
fields_terminated= optarg; lines_terminated= argument;
break; break;
case (int) OPT_LTB: case (int) OPT_ENC:
lines_terminated= optarg; enclosed= argument;
break; break;
case (int) OPT_ENC: case (int) OPT_O_ENC:
enclosed= optarg; opt_enclosed= argument;
break; break;
case (int) OPT_O_ENC: case (int) OPT_ESC:
opt_enclosed= optarg; escaped= argument;
break; break;
case (int) OPT_ESC:
escaped= optarg;
break;
#include "sslopt-case.h" #include "sslopt-case.h"
} }
return 0;
}
static int get_options(int *argc, char ***argv)
{
int ho_error;
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
{
printf("%s: handle_options() failed with error %d\n", my_progname,
ho_error);
exit(1);
} }
if (enclosed && opt_enclosed) if (enclosed && opt_enclosed)
{ {
...@@ -274,8 +258,6 @@ static int get_options(int *argc, char ***argv) ...@@ -274,8 +258,6 @@ static int get_options(int *argc, char ***argv)
if (set_default_charset_by_name(default_charset, MYF(MY_WME))) if (set_default_charset_by_name(default_charset, MYF(MY_WME)))
exit(1); exit(1);
} }
(*argc)-=optind;
(*argv)+=optind;
if (*argc < 2) if (*argc < 2)
{ {
usage(); usage();
......
...@@ -16,9 +16,10 @@ ...@@ -16,9 +16,10 @@
/* Show databases, tables or columns */ /* Show databases, tables or columns */
#define SHOW_VERSION "8.3" #define SHOW_VERSION "9.0"
#include <my_global.h> #include <my_global.h>
#include "client_priv.h"
#include <my_sys.h> #include <my_sys.h>
#include <m_string.h> #include <m_string.h>
#include "mysql.h" #include "mysql.h"
...@@ -26,10 +27,11 @@ ...@@ -26,10 +27,11 @@
#include "mysqld_error.h" #include "mysqld_error.h"
#include <signal.h> #include <signal.h>
#include <stdarg.h> #include <stdarg.h>
#include <getopt.h> #include <my_getopt.h>
#include "sslopt-vars.h"
static my_string host=0,opt_password=0,user=0; static my_string host=0,opt_password=0,user=0;
static my_bool opt_show_keys=0,opt_compress=0,opt_status=0; static my_bool opt_show_keys=0,opt_compress=0,opt_status=0, tty_password=0;
static uint opt_verbose=0; static uint opt_verbose=0;
static void get_options(int *argc,char ***argv); static void get_options(int *argc,char ***argv);
...@@ -48,7 +50,6 @@ static void print_res_row(MYSQL_RES *result,MYSQL_ROW cur); ...@@ -48,7 +50,6 @@ static void print_res_row(MYSQL_RES *result,MYSQL_ROW cur);
static const char *load_default_groups[]= { "mysqlshow","client",0 }; static const char *load_default_groups[]= { "mysqlshow","client",0 };
static my_string opt_mysql_unix_port=0; static my_string opt_mysql_unix_port=0;
#include "sslopt-vars.h"
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
...@@ -121,32 +122,51 @@ int main(int argc, char **argv) ...@@ -121,32 +122,51 @@ int main(int argc, char **argv)
return 0; /* No compiler warnings */ return 0; /* No compiler warnings */
} }
static struct my_option my_long_options[] =
static struct option long_options[] =
{ {
{"character-sets-dir", required_argument, 0, 'c'}, {"character-sets-dir", 'c', "Directory where character sets are",
{"compress", no_argument, 0, 'C'}, (gptr*) &charsets_dir, (gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0,
{"debug", optional_argument, 0, '#'}, 0, 0, 0, 0, 0},
{"help", no_argument, 0, '?'}, {"compress", 'C', "Use compression in server/client protocol",
{"host", required_argument, 0, 'h'}, (gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
{"status", no_argument, 0, 'i'}, 0, 0, 0},
{"keys", no_argument, 0, 'k'}, {"debug", '#', "Output debug log. Often this is 'd:t:o,filename'",
{"password", optional_argument, 0, 'p'}, 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"port", required_argument, 0, 'P'}, {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG,
0, 0, 0, 0, 0, 0},
{"host", 'h', "Connect to host.", (gptr*) &host, (gptr*) &host, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"status", 'i', "Shows a lot of extra information about each table.",
(gptr*) &opt_status, (gptr*) &opt_status, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
0, 0},
{"keys", 'k', "Show keys for table", (gptr*) &opt_show_keys,
(gptr*) &opt_show_keys, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"password", 'p',
"Password to use when connecting to server. If password is not given it's asked from the tty.",
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"port", 'P', "Port number to use for connection.", 0, 0, 0, GET_LONG,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#ifdef __WIN__ #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 #endif
{"socket", required_argument, 0, 'S'}, {"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" #include "sslopt-longopts.h"
#ifndef DONT_ALLOW_USER_CHANGE #ifndef DONT_ALLOW_USER_CHANGE
{"user", required_argument, 0, 'u'}, {"user", 'u', "User for login if not current user.", (gptr*) &user,
(gptr*) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#endif #endif
{"verbose", no_argument, 0, 'v'}, {"verbose", 'v',
{"version", no_argument, 0, 'V'}, "More verbose output; You can use this multiple times to get even more verbose output.",
{0, 0, 0, 0} 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 void print_version(void) static void print_version(void)
{ {
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,SHOW_VERSION, printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,SHOW_VERSION,
...@@ -160,33 +180,6 @@ static void usage(void) ...@@ -160,33 +180,6 @@ static void usage(void)
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"); 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");
puts("Shows the structure of a mysql database (databases,tables and columns)\n"); puts("Shows the structure of a mysql database (databases,tables and columns)\n");
printf("Usage: %s [OPTIONS] [database [table [column]]]\n",my_progname); printf("Usage: %s [OPTIONS] [database [table [column]]]\n",my_progname);
printf("\n\
-#, --debug=... output debug log. Often this is 'd:t:o,filename`\n\
-?, --help display this help and exit\n\
-c, --character-sets-dir=...\n\
Directory where character sets are\n\
-C, --compress Use compression in server/client protocol\n\
-h, --host=... connect to host\n\
-i, --status Shows a lot of extra information about each table\n\
-k, --keys show keys for table\n\
-p, --password[=...] password to use when connecting to server\n\
If password is not given it's asked from 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\
-S --socket=... Socket file to use for connection\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 more verbose output; You can use this multiple times\n\
to get even more verbose output.\n\
-V, --version output version information and exit\n");
puts("\n\ puts("\n\
If last argument contains a shell or SQL wildcard (*,?,% or _) then only\n\ If last argument contains a shell or SQL wildcard (*,?,% or _) then only\n\
what\'s matched by the wildcard is shown.\n\ what\'s matched by the wildcard is shown.\n\
...@@ -195,85 +188,82 @@ If no table is given then all matching tables in database are shown\n\ ...@@ -195,85 +188,82 @@ If no table is given then all matching tables in database are shown\n\
If no column is given then all matching columns and columntypes in table\n\ If no column is given then all matching columns and columntypes in table\n\
are shown"); are shown");
print_defaults("my",load_default_groups); print_defaults("my",load_default_groups);
my_print_help(my_long_options);
my_print_variables(my_long_options);
} }
static my_bool
static void get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
get_options(int *argc,char ***argv) char *argument)
{ {
int c,option_index; switch(optid) {
my_bool tty_password=0; case 'c':
charsets_dir= argument;
while ((c=getopt_long(*argc,*argv,"c:h:p::u:#::P:S:Ck?vVWi",long_options, break;
&option_index)) != EOF) case 'v':
{ opt_verbose++;
switch(c) { break;
case 'C': case 'h':
opt_compress=1; host = argument;
break; break;
case 'c': case 'p':
charsets_dir= optarg; if (argument)
break; {
case 'v': char *start=argument;
opt_verbose++; my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
break; opt_password=my_strdup(argument,MYF(MY_FAE));
case 'h': while (*argument) *argument++= 'x'; /* Destroy argument */
host = optarg; if (*start)
break; start[1]=0; /* Cut length of argument */
case 'i': }
opt_status=1; else
break; tty_password=1;
case 'k': break;
opt_show_keys=1;
break;
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;
#ifndef DONT_ALLOW_USER_CHANGE #ifndef DONT_ALLOW_USER_CHANGE
case 'u': case 'u':
user=optarg; user=argument;
break; break;
#endif #endif
case 'P': case 'P':
opt_mysql_port= (unsigned int) atoi(optarg); opt_mysql_port= (unsigned int) atoi(argument);
break; break;
case 'S': case 'S':
opt_mysql_unix_port= optarg; opt_mysql_unix_port= argument;
break; break;
case 'W': case 'W':
#ifdef __WIN__ #ifdef __WIN__
opt_mysql_unix_port=MYSQL_NAMEDPIPE; opt_mysql_unix_port=MYSQL_NAMEDPIPE;
#endif #endif
break; break;
#include "sslopt-case.h" #include "sslopt-case.h"
case '#': case '#':
DBUG_PUSH(optarg ? optarg : "d:t:o"); DBUG_PUSH(argument ? argument : "d:t:o");
break; break;
case 'V': case 'V':
print_version(); print_version();
exit(0); exit(0);
break; break;
default: case '?':
fprintf(stderr,"Illegal option character '%c'\n",opterr); case 'I': /* Info */
/* Fall throught */ usage();
case '?': exit(0);
case 'I': /* Info */ }
usage(); return 0;
exit(0); }
}
static void
get_options(int *argc,char ***argv)
{
int ho_error;
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
{
printf("%s: handle_options() failed with error %d\n", my_progname,
ho_error);
exit(1);
} }
(*argc)-=optind;
(*argv)+=optind;
if (tty_password) if (tty_password)
opt_password=get_tty_password(NullS); opt_password=get_tty_password(NullS);
return; return;
......
...@@ -14,28 +14,21 @@ ...@@ -14,28 +14,21 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
struct my_optarg C_MODE_START
{
char *arg; /* option argument */
int pos; /* next element in ARGV */
int verbose; /* 0 = inhibit warnings of unrecognized options */
int unrecognized; /* position of the unrecognized option */
};
enum get_opt_var_type { GET_NO_ARG, GET_BOOL, GET_LONG, GET_LL, GET_STR };
enum get_opt_var_type { GET_NO_ARG, GET_LONG, GET_LL, GET_STR };
enum get_opt_arg_type { NO_ARG, OPT_ARG, REQUIRED_ARG }; enum get_opt_arg_type { NO_ARG, OPT_ARG, REQUIRED_ARG };
struct my_option struct my_option
{ {
const char *name; /* Name of the option */ const char *name; /* Name of the option */
int id; /* unique id or short option */
const char *comment; /* option comment, for autom. --help */ const char *comment; /* option comment, for autom. --help */
gptr *value; /* The variable value */ gptr *value; /* The variable value */
gptr *u_max_value; /* The user def. max variable value */ gptr *u_max_value; /* The user def. max variable value */
const char **str_values; /* Pointer to possible values */ const char **str_values; /* Pointer to possible values */
enum get_opt_var_type var_type; enum get_opt_var_type var_type;
enum get_opt_arg_type arg_type; enum get_opt_arg_type arg_type;
int id; /* unique id or short option */
longlong def_value; /* Default value */ longlong def_value; /* Default value */
longlong min_value; /* Min allowed value */ longlong min_value; /* Min allowed value */
longlong max_value; /* Max allowed value */ longlong max_value; /* Max allowed value */
...@@ -44,6 +37,8 @@ struct my_option ...@@ -44,6 +37,8 @@ struct my_option
int app_type; /* To be used by an application */ int app_type; /* To be used by an application */
}; };
extern char *disabled_my_option;
extern int handle_options (int *argc, char ***argv, extern int handle_options (int *argc, char ***argv,
const struct my_option *longopts, const struct my_option *longopts,
my_bool (*get_one_option)(int, my_bool (*get_one_option)(int,
...@@ -51,3 +46,5 @@ extern int handle_options (int *argc, char ***argv, ...@@ -51,3 +46,5 @@ extern int handle_options (int *argc, char ***argv,
char *)); char *));
extern void my_print_help(const struct my_option *options); extern void my_print_help(const struct my_option *options);
extern void my_print_variables(const struct my_option *options); extern void my_print_variables(const struct my_option *options);
C_MODE_END
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
break; break;
case OPT_SSL_KEY: case OPT_SSL_KEY:
opt_use_ssl = 1; /* true */ opt_use_ssl = 1; /* true */
my_free(opt_ssl_key, MYF(MY_ALLOW_ZERO_PTR)); //QQ to be removed??? my_free(opt_ssl_key, MYF(MY_ALLOW_ZERO_PTR));
opt_ssl_key = my_strdup(optarg, MYF(0)); //QQ to be removed??? opt_ssl_key = my_strdup(optarg, MYF(0));
break; break;
case OPT_SSL_CERT: case OPT_SSL_CERT:
opt_use_ssl = 1; /* true */ opt_use_ssl = 1; /* true */
......
...@@ -16,17 +16,26 @@ ...@@ -16,17 +16,26 @@
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
#define OPT_SSL_SSL 200 {"ssl", OPT_SSL_SSL,
#define OPT_SSL_KEY 201 "Use SSL for connection (automatically set with other flags)",
#define OPT_SSL_CERT 202 (gptr*) &opt_use_ssl, (gptr*) &opt_use_ssl, 0, GET_BOOL, NO_ARG, 0, 0, 0,
#define OPT_SSL_CA 203 0, 0, 0},
#define OPT_SSL_CAPATH 204 {"ssl-key", OPT_SSL_KEY, "X509 key in PEM format (implies --ssl)",
#define OPT_SSL_CIPHER 205 (gptr*) &opt_ssl_key, (gptr*) &opt_ssl_key, 0, GET_STR, REQUIRED_ARG,
{"ssl", no_argument, 0, OPT_SSL_SSL}, 0, 0, 0, 0, 0, 0},
{"ssl-key", required_argument, 0, OPT_SSL_KEY}, {"ssl-cert", OPT_SSL_CERT, "X509 cert in PEM format (implies --ssl)",
{"ssl-cert", required_argument, 0, OPT_SSL_CERT}, (gptr*) &opt_ssl_cert, (gptr*) &opt_ssl_cert, 0, GET_STR, REQUIRED_ARG,
{"ssl-ca", required_argument, 0, OPT_SSL_CA}, 0, 0, 0, 0, 0, 0},
{"ssl-capath", required_argument, 0, OPT_SSL_CAPATH}, {"ssl-ca", OPT_SSL_CA,
{"ssl-cipher", required_argument, 0, OPT_SSL_CIPHER}, "CA file in PEM format (check OpenSSL docs, implies --ssl)",
(gptr*) &opt_ssl_ca, (gptr*) &opt_ssl_ca, 0, GET_STR, REQUIRED_ARG,
0, 0, 0, 0, 0, 0},
{"ssl-capath", OPT_SSL_CAPATH,
"CA directory (check OpenSSL docs, implies --ssl)",
(gptr*) &opt_ssl_capath, (gptr*) &opt_ssl_capath, 0, GET_STR, REQUIRED_ARG,
0, 0, 0, 0, 0, 0},
{"ssl-cipher", OPT_SSL_CAPATH, "SSL cipher to use (implies --ssl)",
(gptr*) &opt_ssl_cipher, (gptr*) &opt_ssl_cipher, 0, GET_STR, REQUIRED_ARG,
0, 0, 0, 0, 0, 0},
#endif /* HAVE_OPENSSL */ #endif /* HAVE_OPENSSL */
...@@ -152,132 +152,140 @@ enum options { ...@@ -152,132 +152,140 @@ enum options {
static struct my_option my_long_options[] = static struct my_option my_long_options[] =
{ {
{"analyze", {"analyze", 'a',
"Analyze distribution of keys. Will make some joins in MySQL faster. You can check the calculated distribution.", 0, 0, 0, GET_NO_ARG, NO_ARG, 'a', 0, 0, "Analyze distribution of keys. Will make some joins in MySQL faster. You can check the calculated distribution.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
0, 0, 0, 0}, 0, 0, 0, 0},
{"block-search", "No help available.", 0, 0, 0, GET_LONG, REQUIRED_ARG, 'b', {"block-search", 'b', "No help available.", 0, 0, 0, GET_LONG, REQUIRED_ARG,
0, 0, 0, 0, 0, 0}, 0, 0, 0, 0, 0, 0},
{"backup", "Make a backup of the .MYD file as 'filename-time.BAK'", 0, 0, 0, {"backup", 'B', "Make a backup of the .MYD file as 'filename-time.BAK'", 0,
GET_NO_ARG, NO_ARG, 'B', 0, 0, 0, 0, 0, 0}, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"character-sets-dir", "Directory where character sets are.", {"character-sets-dir", OPT_CHARSETS_DIR,
(gptr*) &set_charset_name, 0, 0, GET_STR, REQUIRED_ARG, OPT_CHARSETS_DIR, 0, "Directory where character sets are.", (gptr*) &set_charset_name, 0, 0,
0, 0, 0, 0, 0}, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"check", "Check table for errors.", 0, 0, 0, GET_NO_ARG, NO_ARG, 'c', 0, 0, {"check", 'c', "Check table for errors.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
0, 0, 0, 0}, 0, 0, 0, 0},
{"check-only-changed", {"check-only-changed", 'C',
"Check only tables that has changed since last check.", 0, 0, 0, GET_NO_ARG, "Check only tables that has changed since last check.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 'C', 0, 0, 0, 0, 0, 0}, NO_ARG, 0, 0, 0, 0, 0, 0},
{"correct-checksum", "Correct checksum information for table.", 0, 0, 0, {"correct-checksum", OPT_CORRECT_CHECKSUM,
GET_NO_ARG, NO_ARG, OPT_CORRECT_CHECKSUM, 0, 0, 0, 0, 0, 0}, "Correct checksum information for table.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
0, 0, 0, 0, 0},
#ifndef DBUG_OFF #ifndef DBUG_OFF
{"debug", "Output debug log. Often this is 'd:t:o,filename'.", 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}, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
#endif #endif
{"description", "Prints some information about table.", 0, 0, 0, GET_NO_ARG, {"description", 'd', "Prints some information about table.", 0, 0, 0,
NO_ARG, 'd', 0, 0, 0, 0, 0, 0}, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"data-file-length", {"data-file-length", 'D',
"Max length of data file (when recreating data-file when it's full).", "Max length of data file (when recreating data-file when it's full).",
(gptr*) &check_param.max_data_file_length, (gptr*) &check_param.max_data_file_length,
(gptr*) &check_param.max_data_file_length, 0, GET_LONG, REQUIRED_ARG, 'D', (gptr*) &check_param.max_data_file_length, 0, GET_LONG, REQUIRED_ARG,
0, 0, 0, 0, 0, 0}, 0, 0, 0, 0, 0, 0},
{"extend-check", {"extend-check", 'e',
"Try to recover every possible row from the data file. Normally this will also find a lot of garbage rows; Don't use this option if you are not totally desperate.", 0, 0, 0, GET_NO_ARG, NO_ARG, 'e', 0, 0, 0, 0, 0, 0}, "Try to recover every possible row from the data file. Normally this will also find a lot of garbage rows; Don't use this option if you are not totally desperate.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"fast", "Check only tables that hasn't been closed properly.", 0, 0, 0, {"fast", 'F', "Check only tables that hasn't been closed properly.", 0, 0, 0,
GET_NO_ARG, NO_ARG, 'F', 0, 0, 0, 0, 0, 0}, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"force", {"force", 'f',
"Restart with -r if there are any errors in the table. States will be updated as with --update-state.", 0, 0, 0, GET_NO_ARG, NO_ARG, 'f', 0, 0, 0, 0, 0, "Restart with -r if there are any errors in the table. States will be updated as with --update-state.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0,
0}, 0},
{"help", "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, '?', 0, {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
0, 0, 0, 0, 0}, 0, 0, 0, 0, 0},
{"information", "Print statistics information about table that is checked.", {"information", 'i',
0, 0, 0, GET_NO_ARG, NO_ARG, 'i', 0, 0, 0, 0, 0, 0}, "Print statistics information about table that is checked.", 0, 0, 0,
{"keys-used", "Tell MyISAM to update only some specific keys. # is a bit mask of which keys to use. This can be used to get faster inserts!", GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"keys-used", 'k',
"Tell MyISAM to update only some specific keys. # is a bit mask of which keys to use. This can be used to get faster inserts!",
(gptr*) &check_param.keys_in_use, (gptr*) &check_param.keys_in_use, 0, (gptr*) &check_param.keys_in_use, (gptr*) &check_param.keys_in_use, 0,
GET_LONG, REQUIRED_ARG, 'k', 0, 0, 0, 0, 0, 0}, GET_LONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"medium-check", {"medium-check", 'm',
"Faster than extended-check, but only finds 99.99% of all errors. Should be good enough for most cases.", 0, 0, 0, GET_NO_ARG, NO_ARG, 'm', 0, 0, 0, 0, 0, "Faster than extended-check, but only finds 99.99% of all errors. Should be good enough for most cases.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0,
0}, 0},
{"quick", "Faster repair by not modifying the data file.", 0, 0, 0, {"quick", 'q', "Faster repair by not modifying the data file.", 0, 0, 0,
GET_NO_ARG, NO_ARG, 'q', 0, 0, 0, 0, 0, 0}, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"read-only", "Don't mark table as checked.", 0, 0, 0, GET_NO_ARG, NO_ARG, {"read-only", 'T', "Don't mark table as checked.", 0, 0, 0, GET_NO_ARG,
'T', 0, 0, 0, 0, 0, 0}, NO_ARG, 0, 0, 0, 0, 0, 0},
{"recover", {"recover", 'r',
"Can fix almost anything except unique keys that aren't unique.", 0, 0, 0, "Can fix almost anything except unique keys that aren't unique.", 0, 0, 0,
GET_NO_ARG, NO_ARG, 'r', 0, 0, 0, 0, 0, 0}, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"safe-recover", {"safe-recover", 'o',
"Uses old recovery method; Slower than '-r' but can handle a couple of cases where '-r' reports that it can't fix the data file.", 0, 0, 0, GET_NO_ARG, "Uses old recovery method; Slower than '-r' but can handle a couple of cases where '-r' reports that it can't fix the data file.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 'o', 0, 0, 0, 0, 0, 0}, NO_ARG, 0, 0, 0, 0, 0, 0},
{"start-check-pos", "No help available.", 0, 0, 0, GET_LONG, REQUIRED_ARG, {"start-check-pos", OPT_START_CHECK_POS, "No help available.", 0, 0, 0,
OPT_START_CHECK_POS, 0, 0, 0, 0, 0, 0}, GET_LONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"set-auto-increment", {"set-auto-increment", 'A',
"Force auto_increment to start at this or higher value. If no value is given, then sets the next auto_increment value to the highest used value for the auto key + 1.", (gptr*) &check_param.auto_increment_value, "Force auto_increment to start at this or higher value. If no value is given, then sets the next auto_increment value to the highest used value for the auto key + 1.", (gptr*) &check_param.auto_increment_value,
(gptr*) &check_param.auto_increment_value, 0, GET_LONG, OPT_ARG, 'A', 0, 0, (gptr*) &check_param.auto_increment_value, 0, GET_LONG, OPT_ARG, 0, 0, 0,
0, 0, 0, 0}, 0, 0, 0},
{"set-character-set", "Change the character set used by the index", 0, 0, 0, {"set-character-set", OPT_SET_CHARSET,
GET_STR, REQUIRED_ARG, OPT_SET_CHARSET, 0, 0, 0, 0, 0, 0}, "Change the character set used by the index", 0, 0, 0, GET_STR,
{"set-variable", "Change the value of a variable. Please note that this option is depricated; you can set variables directly with --variable-name=value.", REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
0, 0, 0, GET_STR, REQUIRED_ARG, 'O', 0, 0, 0, 0, 0, 0}, {"set-variable", 'O',
{"silent", "Change the value of a variable. Please note that this option is depricated; you can set variables directly with --variable-name=value.",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"silent", 's',
"Only print errors. One can use two -s to make myisamchk very silent.", 0, "Only print errors. One can use two -s to make myisamchk very silent.", 0,
0, 0, GET_NO_ARG, NO_ARG, 's', 0, 0, 0, 0, 0, 0}, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"sort-index", {"sort-index", 'S',
"Sort index blocks. This speeds up 'read-next' in applications.", 0, 0, 0, "Sort index blocks. This speeds up 'read-next' in applications.", 0, 0, 0,
GET_NO_ARG, NO_ARG, 'S', 0, 0, 0, 0, 0, 0}, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"sort-records", {"sort-records", 'R',
"Sort records according to an index. This makes your data much more localized and may speed up things. (It may be VERY slow to do a sort the first time!)", "Sort records according to an index. This makes your data much more localized and may speed up things. (It may be VERY slow to do a sort the first time!)",
(gptr*) &check_param.opt_sort_key, (gptr*) &check_param.opt_sort_key, 0, (gptr*) &check_param.opt_sort_key, (gptr*) &check_param.opt_sort_key, 0,
GET_LONG, REQUIRED_ARG, 'R', 0, 0, 0, 0, 0, 0}, GET_LONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"sort-recover", {"sort-recover", 'n',
"Force recovering with sorting even if the temporary file was very big.", "Force recovering with sorting even if the temporary file was very big.",
0, 0, 0, GET_NO_ARG, NO_ARG, 'n', 0, 0, 0, 0, 0, 0}, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"tmpdir", "Path for temporary files.", (gptr*) &check_param.tmpdir, 0, 0, {"tmpdir", 't', "Path for temporary files.",
GET_STR, REQUIRED_ARG, 't', 0, 0, 0, 0, 0, 0}, (gptr*) &check_param.tmpdir, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"update-state", "Mark tables as crashed if any errors were found.", 0, 0, {"update-state", 'U', "Mark tables as crashed if any errors were found.", 0,
0, GET_NO_ARG, NO_ARG, 'U', 0, 0, 0, 0, 0, 0}, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"unpack", "Unpack file packed with myisampack.", 0, 0, 0, GET_NO_ARG, {"unpack", 'u', "Unpack file packed with myisampack.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 'u', 0, 0, 0, 0, 0, 0}, NO_ARG, 0, 0, 0, 0, 0, 0},
{"verbose", {"verbose", 'v',
"Print more information. This can be used with --describe and --check. Use many -v for more verbosity!", 0, 0, 0, GET_NO_ARG, NO_ARG, 'v', 0, 0, 0, 0, 0, "Print more information. This can be used with --describe and --check. Use many -v for more verbosity!", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0,
0}, 0},
{"version", "Print version and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 'V', 0, {"version", 'V', "Print version and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
0, 0, 0, 0, 0}, 0, 0, 0, 0, 0},
{"wait", "Wait if table is locked.", 0, 0, 0, GET_NO_ARG, NO_ARG, 'w', 0, 0, {"wait", 'w', "Wait if table is locked.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
0, 0, 0, 0}, 0, 0, 0, 0},
{ "key_buffer_size", "", (gptr*) &check_param.use_buffers, { "key_buffer_size", OPT_KEY_BUFFER_SIZE, "",
(gptr*) &check_param.use_buffers, 0, GET_LONG, REQUIRED_ARG, (gptr*) &check_param.use_buffers, (gptr*) &check_param.use_buffers, 0,
OPT_KEY_BUFFER_SIZE, (long) USE_BUFFER_INIT, (long) MALLOC_OVERHEAD, GET_LONG, REQUIRED_ARG, (long) USE_BUFFER_INIT, (long) MALLOC_OVERHEAD,
(long) ~0L, (long) MALLOC_OVERHEAD, (long) IO_SIZE, 0}, (long) ~0L, (long) MALLOC_OVERHEAD, (long) IO_SIZE, 0},
{ "myisam_block_size", "", (gptr*) &opt_myisam_block_size, { "myisam_block_size", OPT_MYISAM_BLOCK_SIZE, "",
(gptr*) &opt_myisam_block_size, 0, GET_LONG, REQUIRED_ARG, (gptr*) &opt_myisam_block_size, (gptr*) &opt_myisam_block_size, 0,
OPT_MYISAM_BLOCK_SIZE, MI_KEY_BLOCK_LENGTH, MI_MIN_KEY_BLOCK_LENGTH, GET_LONG, REQUIRED_ARG, MI_KEY_BLOCK_LENGTH, MI_MIN_KEY_BLOCK_LENGTH,
MI_MAX_KEY_BLOCK_LENGTH, 0, MI_MIN_KEY_BLOCK_LENGTH, 0}, MI_MAX_KEY_BLOCK_LENGTH, 0, MI_MIN_KEY_BLOCK_LENGTH, 0},
{ "read_buffer_size", "", (gptr*) &check_param.read_buffer_length, { "read_buffer_size", OPT_READ_BUFFER_SIZE, "",
(gptr*) &check_param.read_buffer_length,
(gptr*) &check_param.read_buffer_length, 0, GET_LONG, REQUIRED_ARG, (gptr*) &check_param.read_buffer_length, 0, GET_LONG, REQUIRED_ARG,
OPT_READ_BUFFER_SIZE, (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD, (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
(long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0}, (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
{ "write_buffer_size", "", (gptr*) &check_param.write_buffer_length, { "write_buffer_size", OPT_WRITE_BUFFER_SIZE, "",
(gptr*) &check_param.write_buffer_length,
(gptr*) &check_param.write_buffer_length, 0, GET_LONG, REQUIRED_ARG, (gptr*) &check_param.write_buffer_length, 0, GET_LONG, REQUIRED_ARG,
OPT_WRITE_BUFFER_SIZE, (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD, (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
(long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0}, (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
{ "sort_buffer_size", "", (gptr*) &check_param.sort_buffer_length, { "sort_buffer_size", OPT_SORT_BUFFER_SIZE, "",
(gptr*) &check_param.sort_buffer_length,
(gptr*) &check_param.sort_buffer_length, 0, GET_LONG, REQUIRED_ARG, (gptr*) &check_param.sort_buffer_length, 0, GET_LONG, REQUIRED_ARG,
OPT_SORT_BUFFER_SIZE, (long) SORT_BUFFER_INIT, (long) SORT_BUFFER_INIT, (long) (MIN_SORT_BUFFER + MALLOC_OVERHEAD),
(long) (MIN_SORT_BUFFER + MALLOC_OVERHEAD), (long) ~0L, (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
(long) MALLOC_OVERHEAD, (long) 1L, 0}, { "sort_key_blocks", OPT_SORT_KEY_BLOCKS, "",
{ "sort_key_blocks", "", (gptr*) &check_param.sort_key_blocks, (gptr*) &check_param.sort_key_blocks,
(gptr*) &check_param.sort_key_blocks, 0, GET_LONG, REQUIRED_ARG, (gptr*) &check_param.sort_key_blocks, 0, GET_LONG, REQUIRED_ARG,
OPT_SORT_KEY_BLOCKS, BUFFERS_WHEN_SORTING, 4L, 100L, 0L, 1L, 0}, BUFFERS_WHEN_SORTING, 4L, 100L, 0L, 1L, 0},
{ "decode_bits", "", (gptr*) &decode_bits, (gptr*) &decode_bits, 0, { "decode_bits", OPT_DECODE_BITS, "", (gptr*) &decode_bits,
GET_LONG, REQUIRED_ARG, OPT_DECODE_BITS, 9L, 4L, 17L, 0L, 1L, 0}, (gptr*) &decode_bits, 0, GET_LONG, REQUIRED_ARG, 9L, 4L, 17L, 0L, 1L, 0},
{ "ft_min_word_len", "", (gptr*) &ft_min_word_len, (gptr*) &ft_min_word_len, { "ft_min_word_len", OPT_FT_MIN_WORD_LEN, "", (gptr*) &ft_min_word_len,
0, GET_LONG, REQUIRED_ARG, OPT_FT_MIN_WORD_LEN, 4, 1, HA_FT_MAXLEN, 0, 1, (gptr*) &ft_min_word_len, 0, GET_LONG, REQUIRED_ARG, 4, 1, HA_FT_MAXLEN,
0}, 0, 1, 0},
{ "ft_max_word_len", "", (gptr*) &ft_max_word_len, (gptr*) &ft_max_word_len, { "ft_max_word_len", OPT_FT_MAX_WORD_LEN, "", (gptr*) &ft_max_word_len,
0, GET_LONG, REQUIRED_ARG, OPT_FT_MAX_WORD_LEN, HA_FT_MAXLEN, 10, (gptr*) &ft_max_word_len, 0, GET_LONG, REQUIRED_ARG, HA_FT_MAXLEN, 10,
HA_FT_MAXLEN, 0, 1, 0}, HA_FT_MAXLEN, 0, 1, 0},
{ "ft_max_word_len_for_sort", "", (gptr*) &ft_max_word_len_for_sort, { "ft_max_word_len_for_sort", OPT_FT_MAX_WORD_LEN_FOR_SORT, "",
(gptr*) &ft_max_word_len_for_sort, 0, GET_LONG, REQUIRED_ARG, (gptr*) &ft_max_word_len_for_sort, (gptr*) &ft_max_word_len_for_sort, 0,
OPT_FT_MAX_WORD_LEN_FOR_SORT, 20, 4, HA_FT_MAXLEN, 0, 1, 0}, GET_LONG, REQUIRED_ARG, 20, 4, HA_FT_MAXLEN, 0, 1, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
}; };
...@@ -504,7 +512,7 @@ get_one_option(int optid, ...@@ -504,7 +512,7 @@ get_one_option(int optid,
check_param.opt_rep_quick++; check_param.opt_rep_quick++;
break; break;
case 'u': case 'u':
if (argument && *argument == '0') if (argument == disabled_my_option)
{ {
check_param.testflag&= ~T_UNPACK; check_param.testflag&= ~T_UNPACK;
check_param.testflag&= ~T_REP_BY_SORT; check_param.testflag&= ~T_REP_BY_SORT;
......
...@@ -35,6 +35,7 @@ static void init_variables(const struct my_option *options); ...@@ -35,6 +35,7 @@ static void init_variables(const struct my_option *options);
static const char *special_opt_prefix[]= static const char *special_opt_prefix[]=
{"skip", "disable", "enable", "maximum", 0}; {"skip", "disable", "enable", "maximum", 0};
char *disabled_my_option= (char*) "0";
/* Return error values from handle_options */ /* Return error values from handle_options */
...@@ -66,7 +67,7 @@ int handle_options(int *argc, char ***argv, ...@@ -66,7 +67,7 @@ int handle_options(int *argc, char ***argv,
char *)) char *))
{ {
uint opt_found, argvpos= 0, length, spec_len, i; uint opt_found, argvpos= 0, length, spec_len, i;
int err; int err= 0;
my_bool end_of_options= 0, must_be_var, set_maximum_value, special_used; my_bool end_of_options= 0, must_be_var, set_maximum_value, special_used;
char *progname= *(*argv), **pos, *optend, *prev_found; char *progname= *(*argv), **pos, *optend, *prev_found;
const struct my_option *optp; const struct my_option *optp;
...@@ -177,7 +178,7 @@ int handle_options(int *argc, char ***argv, ...@@ -177,7 +178,7 @@ int handle_options(int *argc, char ***argv,
We were called with a special prefix, we can reuse opt_found We were called with a special prefix, we can reuse opt_found
*/ */
special_used= 1; special_used= 1;
cur_arg += (spec_len + 1); cur_arg+= (spec_len + 1);
if ((opt_found= findopt(cur_arg, length - (spec_len + 1), if ((opt_found= findopt(cur_arg, length - (spec_len + 1),
&optp, &prev_found))) &optp, &prev_found)))
{ {
...@@ -190,7 +191,7 @@ int handle_options(int *argc, char ***argv, ...@@ -190,7 +191,7 @@ int handle_options(int *argc, char ***argv,
return ERR_AMBIGUOUS_OPTION; return ERR_AMBIGUOUS_OPTION;
} }
if (i < DISABLE_OPTION_COUNT) if (i < DISABLE_OPTION_COUNT)
optend= (char*) "0"; optend= disabled_my_option;
else if (!compare_strings(special_opt_prefix[i],"enable",6)) else if (!compare_strings(special_opt_prefix[i],"enable",6))
optend= (char*) "1"; optend= (char*) "1";
else if (!compare_strings(special_opt_prefix[i],"maximum",7)) else if (!compare_strings(special_opt_prefix[i],"maximum",7))
...@@ -236,15 +237,44 @@ int handle_options(int *argc, char ***argv, ...@@ -236,15 +237,44 @@ int handle_options(int *argc, char ***argv,
} }
if (must_be_var && !optp->value) if (must_be_var && !optp->value)
{ {
fprintf(stderr, "%s: the argument '%s' is not an variable\n", fprintf(stderr, "%s: argument '%s' is not a variable\n",
progname, *pos); progname, *pos);
return ERR_MUST_BE_VARIABLE; return ERR_MUST_BE_VARIABLE;
} }
if (optp->arg_type == NO_ARG && optend && !special_used) if (optp->arg_type == NO_ARG)
{ {
fprintf(stderr, "%s: option '--%s' cannot take an argument\n", if (optend && !special_used)
progname, optp->name); {
return ERR_NO_ARGUMENT_ALLOWED; fprintf(stderr, "%s: option '--%s' cannot take an argument\n",
progname, optp->name);
return ERR_NO_ARGUMENT_ALLOWED;
}
if (optp->var_type == GET_BOOL)
{
/*
Set bool to 1 if no argument or if the user has used
--enable-'option-name'.
*optend was set to '0' if one used --disable-option
*/
*((my_bool*) optp->value)= (my_bool) (!optend || *optend == '1');
(*argc)--;
continue;
}
argument= optend;
}
else if (optp->arg_type == OPT_ARG && optp->var_type == GET_BOOL)
{
if (optend == disabled_my_option)
*((my_bool*) optp->value)= (my_bool) 0;
else
{
if (!optend) /* No argument -> enable option */
*((my_bool*) optp->value)= (my_bool) 1;
else /* If argument differs from 0, enable option, else disable */
*((my_bool*) optp->value)= (my_bool) atoi(optend) != 0;
}
(*argc)--;
continue;
} }
else if (optp->arg_type == REQUIRED_ARG && !optend) else if (optp->arg_type == REQUIRED_ARG && !optend)
{ {
...@@ -312,6 +342,7 @@ int handle_options(int *argc, char ***argv, ...@@ -312,6 +342,7 @@ int handle_options(int *argc, char ***argv,
{ {
gptr *result_pos= (set_maximum_value) ? gptr *result_pos= (set_maximum_value) ?
optp->u_max_value : optp->value; optp->u_max_value : optp->value;
if (!result_pos) if (!result_pos)
{ {
fprintf(stderr, fprintf(stderr,
...@@ -321,14 +352,13 @@ int handle_options(int *argc, char ***argv, ...@@ -321,14 +352,13 @@ int handle_options(int *argc, char ***argv,
if (optp->var_type == GET_LONG) if (optp->var_type == GET_LONG)
*((long*) result_pos)= (long) getopt_ll(argument, optp, &err); *((long*) result_pos)= (long) getopt_ll(argument, optp, &err);
else if (optp->var_type == GET_LL) else if (optp->var_type == GET_LL)
*((longlong*) result_pos)= getopt_ll(argument, optp, &err); *((longlong*) result_pos)= getopt_ll(argument, optp, &err);
else if (optp->var_type == GET_STR) else if (optp->var_type == GET_STR)
*((char**) result_pos)= argument; *((char**) result_pos)= argument;
if (err) if (err)
return ERR_UNKNOWN_SUFFIX; return ERR_UNKNOWN_SUFFIX;
} }
else get_one_option(optp->id, optp, argument);
get_one_option(optp->id, optp, argument);
(*argc)--; /* option handled (shortorlong), decrease argument count */ (*argc)--; /* option handled (shortorlong), decrease argument count */
} }
...@@ -489,17 +519,19 @@ void my_print_help(const struct my_option *options) ...@@ -489,17 +519,19 @@ void my_print_help(const struct my_option *options)
col+= 2 + strlen(optp->name); col+= 2 + strlen(optp->name);
if (optp->var_type == GET_STR) if (optp->var_type == GET_STR)
{ {
printf("=name "); printf("%s=name%s ", optp->arg_type == OPT_ARG ? "[" : "",
optp->arg_type == OPT_ARG ? "]" : "");
col+= 6; col+= 6;
} }
else if (optp->var_type == GET_NO_ARG) else if (optp->var_type == GET_NO_ARG || optp->var_type == GET_BOOL)
{ {
putchar(' '); putchar(' ');
col++; col++;
} }
else else
{ {
printf("=# "); printf("%s=#%s ", optp->arg_type == OPT_ARG ? "[" : "",
optp->arg_type == OPT_ARG ? "]" : "");
col+= 3; col+= 3;
} }
if (col > name_space) if (col > name_space)
...@@ -546,7 +578,7 @@ void my_print_variables(const struct my_option *options) ...@@ -546,7 +578,7 @@ void my_print_variables(const struct my_option *options)
printf("--------------------------------- -------------\n"); printf("--------------------------------- -------------\n");
for (optp= options; optp->id; optp++) for (optp= options; optp->id; optp++)
{ {
if (optp->value) if (optp->value && optp->var_type != GET_BOOL)
{ {
printf("%s", optp->name); printf("%s", optp->name);
length= strlen(optp->name); length= strlen(optp->name);
...@@ -554,10 +586,10 @@ void my_print_variables(const struct my_option *options) ...@@ -554,10 +586,10 @@ void my_print_variables(const struct my_option *options)
putchar(' '); putchar(' ');
if (optp->var_type == GET_STR) if (optp->var_type == GET_STR)
{ {
if (!optp->def_value && !*((char**) optp->value)) if (*((char**) optp->value))
printf("(No default value)\n");
else
printf("%s\n", *((char**) optp->value)); printf("%s\n", *((char**) optp->value));
else
printf("(No default value)\n");
} }
else if (optp->var_type == GET_LONG) else if (optp->var_type == GET_LONG)
{ {
...@@ -566,7 +598,7 @@ void my_print_variables(const struct my_option *options) ...@@ -566,7 +598,7 @@ void my_print_variables(const struct my_option *options)
else else
printf("%lu\n", *((long*) optp->value)); printf("%lu\n", *((long*) optp->value));
} }
else else
{ {
if (!optp->def_value && !*((longlong*) optp->value)) if (!optp->def_value && !*((longlong*) optp->value))
printf("(No default value)\n"); printf("(No default value)\n");
......
...@@ -2832,7 +2832,9 @@ static struct option long_options[] = { ...@@ -2832,7 +2832,9 @@ static struct option long_options[] = {
{"socket", required_argument, 0, (int) OPT_SOCKET}, {"socket", required_argument, 0, (int) OPT_SOCKET},
{"sql-bin-update-same", no_argument, 0, (int) OPT_SQL_BIN_UPDATE_SAME}, {"sql-bin-update-same", no_argument, 0, (int) OPT_SQL_BIN_UPDATE_SAME},
{"sql-mode", required_argument, 0, (int) OPT_SQL_MODE}, {"sql-mode", required_argument, 0, (int) OPT_SQL_MODE},
#ifdef TO_BE_DONE
#include "sslopt-longopts.h" #include "sslopt-longopts.h"
#endif
#ifdef __WIN__ #ifdef __WIN__
{"standalone", no_argument, 0, (int) OPT_STANDALONE}, {"standalone", no_argument, 0, (int) OPT_STANDALONE},
#endif #endif
...@@ -3992,8 +3994,10 @@ static void get_options(int argc,char **argv) ...@@ -3992,8 +3994,10 @@ static void get_options(int argc,char **argv)
strmov(mysql_charsets_dir, optarg); strmov(mysql_charsets_dir, optarg);
charsets_dir = mysql_charsets_dir; charsets_dir = mysql_charsets_dir;
break; break;
#ifdef TO_BE_DONE
#include "sslopt-case.h" #include "sslopt-case.h"
case OPT_DES_KEY_FILE: case OPT_DES_KEY_FILE:
#endif
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
des_key_file=optarg; des_key_file=optarg;
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment