diff options
author | monty@hundin.mysql.fi <> | 2002-06-03 12:59:31 +0300 |
---|---|---|
committer | monty@hundin.mysql.fi <> | 2002-06-03 12:59:31 +0300 |
commit | f0b28da6f91cf87804015b5dde4820be040c2de7 (patch) | |
tree | be04186411dc657ef6bbcbe01267d30f2675c914 /client | |
parent | 3ede8f6289b53345f44aecffd70c7e291f88186b (diff) | |
parent | 544f95c45112993df1d31d3eda859dd5e4efff89 (diff) | |
download | mariadb-git-f0b28da6f91cf87804015b5dde4820be040c2de7.tar.gz |
merge with 4.0
Diffstat (limited to 'client')
-rw-r--r-- | client/client_priv.h | 2 | ||||
-rw-r--r-- | client/mysql.cc | 391 | ||||
-rw-r--r-- | client/mysqladmin.c | 46 | ||||
-rw-r--r-- | client/mysqlbinlog.cc | 225 | ||||
-rw-r--r-- | client/mysqlcheck.c | 46 | ||||
-rw-r--r-- | client/mysqldump.c | 109 | ||||
-rw-r--r-- | client/mysqlimport.c | 59 | ||||
-rw-r--r-- | client/mysqlmanager-pwgen.c | 71 | ||||
-rw-r--r-- | client/mysqlmanagerc.c | 122 | ||||
-rw-r--r-- | client/mysqlshow.c | 31 | ||||
-rw-r--r-- | client/mysqltest.c | 373 | ||||
-rw-r--r-- | client/thread_test.c | 168 |
12 files changed, 700 insertions, 943 deletions
diff --git a/client/client_priv.h b/client/client_priv.h index f321b47aec0..ae5556cac35 100644 --- a/client/client_priv.h +++ b/client/client_priv.h @@ -22,7 +22,7 @@ #include <mysql_embed.h> #include <mysql.h> #include <errmsg.h> -#include <getopt.h> +#include <my_getopt.h> /* We have to define 'enum options' identical in all files to keep OS2 happy */ diff --git a/client/mysql.cc b/client/mysql.cc index c4dbf1688ef..1f710580991 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (C) 2000-2002 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,7 +32,6 @@ #include "client_priv.h" #include <m_ctype.h> #include <stdarg.h> -#include <my_getopt.h> #include <my_dir.h> #ifndef __GNU_LIBRARY__ #define __GNU_LIBRARY__ // Skip warnings in getopt.h @@ -41,7 +40,7 @@ #include <signal.h> #include <violite.h> -const char *VER= "12.1"; +const char *VER= "12.10"; /* Don't try to make a nice table if the data is too big */ #define MAX_COLUMN_LENGTH 1024 @@ -120,7 +119,7 @@ typedef enum enum_info_type INFO_TYPE; static MYSQL mysql; /* The connection */ 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, - no_rehash=0,skip_updates=0,safe_updates=0,one_database=0, + rehash=1,skip_updates=0,safe_updates=0,one_database=0, opt_compress=0, using_opt_local_infile=0, vertical=0, line_numbers=1, column_names=1,opt_html=0, opt_xml=0,opt_nopager=1, opt_outfile=0, named_cmds= 0, @@ -355,18 +354,6 @@ int main(int argc,char *argv[]) mysql_thread_id(&mysql),mysql_get_server_info(&mysql)); put_info((char*) glob_buffer.ptr(),INFO_INFO); -#ifdef HAVE_OPENSSL - if (mysql.net.vio->ssl_ && SSL_get_cipher(mysql.net.vio->ssl_)) - { - sprintf((char*) glob_buffer.ptr(), - "SSL cipher in use is %s\n", SSL_get_cipher(mysql.net.vio->ssl_)); - put_info((char*) glob_buffer.ptr(),INFO_INFO); - } - else - put_info("SSL is not in use\n",INFO_INFO); -#endif /* HAVE_OPENSSL */ - - #ifdef HAVE_READLINE initialize_readline(my_progname); if (!status.batch && !quick && !opt_html && !opt_xml) @@ -452,16 +439,18 @@ static struct my_option my_long_options[] = 0, 0, 0, 0, 0}, {"auto-rehash", OPT_AUTO_REHASH, "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}, + (gptr*) &rehash, (gptr*) &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.", + "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 deprecated; 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}, + {"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}, {"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}, @@ -469,8 +458,8 @@ static struct my_option my_long_options[] = {"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_STR, REQUIRED_ARG, 0, 0, - 0, 0, 0, 0}, + {"database", 'D', "Database to use.", (gptr*) ¤t_db, + (gptr*) ¤t_db, 0, GET_STR_ALLOC, REQUIRED_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.", @@ -479,20 +468,21 @@ static struct my_option my_long_options[] = {"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.", + {"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 deprecated; 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.", + "Enable named commands. Named commands mean this program's internal commands; see mysql> help . When enabled, the named commands can be used from any line of the query, otherwise only from the first line, before an enter. 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}, {"local-infile", OPT_LOCAL_INFILE, "Enable/disable LOAD DATA LOCAL INFILE.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, - {"no-beep", 'b', "Turn off beep on error.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, - 0, 0, 0, 0, 0}, - {"host", 'h', "Connect to host.", (gptr*) ¤t_host, - (gptr*) ¤t_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"no-beep", 'b', "Turn off beep on error.", (gptr*) &opt_nobeep, + (gptr*) &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"host", 'h', "Connect to host.", (gptr*) ¤t_host, + (gptr*) ¤t_host, 0, GET_STR_ALLOC, 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, @@ -500,25 +490,25 @@ static struct my_option my_long_options[] = {"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, + {"skip-line-numbers", 'L', "Don't write line number for errors. WARNING: -L is deprecated, 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.", + "Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, #endif - {"no-tee", OPT_NOTEE, "Disable outfile. See interactive help (\\h) also. WARNING: option depricated; use --disable-tee instead", 0, 0, 0, GET_NO_ARG, + {"no-tee", OPT_NOTEE, "Disable outfile. See interactive help (\\h) also. WARNING: option deprecated; use --disable-tee instead", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"unbuffered", 'n', "Flush buffer after each query.", (gptr*) &unbuffered, (gptr*) &unbuffered, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"column-names", OPT_COLUMN_NAMES, "Write column names in results.", (gptr*) &column_names, (gptr*) &column_names, 0, GET_BOOL, - NO_ARG, 0, 0, 0, 0, 0, 0}, + NO_ARG, 1, 0, 0, 0, 0, 0}, {"skip-column-names", 'N', - "Don't write column names in results. WARNING: -N is depricated, use long version of this options instead.", + "Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead.", 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.", + "Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"one-database", 'o', "Only update the default database. This is useful for skipping updates to other database in the update log.", @@ -535,10 +525,12 @@ static struct my_option my_long_options[] = {"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, #endif - {"port", 'P', "Port number to use for connection.", 0, 0, 0, - GET_LONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"prompt", OPT_PROMPT, "Set the mysql prompt to this value.", 0, 0, 0, - GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"port", 'P', "Port number to use for connection.", (gptr*) &opt_mysql_port, + (gptr*) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0, + 0}, + {"prompt", OPT_PROMPT, "Set the mysql prompt to this value.", + (gptr*) ¤t_prompt, (gptr*) ¤t_prompt, 0, GET_STR_ALLOC, + REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"quick", 'q', "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. ", (gptr*) &quick, (gptr*) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -548,7 +540,8 @@ static struct my_option my_long_options[] = {"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}, + (gptr*) &opt_mysql_unix_port, (gptr*) &opt_mysql_unix_port, 0, GET_STR_ALLOC, + REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #include "sslopt-longopts.h" {"table", 't', "Output in table format.", (gptr*) &output_tables, (gptr*) &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -559,7 +552,7 @@ static struct my_option my_long_options[] = 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #ifndef DONT_ALLOW_USER_CHANGE {"user", 'u', "User for login if not current user.", (gptr*) ¤t_user, - (gptr*) ¤t_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + (gptr*) ¤t_user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #endif {"safe-updates", 'U', "Only allow UPDATE and DELETE that uses keys.", (gptr*) &safe_updates, (gptr*) &safe_updates, 0, GET_BOOL, OPT_ARG, 0, 0, @@ -573,19 +566,19 @@ static struct my_option my_long_options[] = {"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, 0, 0, 3600*12, 0, + (gptr*) &opt_connect_timeout, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 3600*12, 0, 0, 1}, {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "", - (gptr*) &max_allowed_packet, (gptr*) &max_allowed_packet, 0, GET_LONG, + (gptr*) &max_allowed_packet, (gptr*) &max_allowed_packet, 0, GET_ULONG, REQUIRED_ARG, 16 *1024L*1024L, 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, + (gptr*) &net_buffer_length, (gptr*) &net_buffer_length, 0, GET_ULONG, 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}, + (gptr*) &select_limit, 0, GET_ULONG, 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, + (gptr*) &max_join_size, 0, GET_ULONG, 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} }; @@ -612,146 +605,115 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), char *argument) { switch(optid) { - case OPT_DEFAULT_CHARSET: - default_charset= argument; - break; - case OPT_CHARSETS_DIR: - strmov(mysql_charsets_dir, argument); - charsets_dir = mysql_charsets_dir; - break; - case OPT_LOCAL_INFILE: - using_opt_local_infile=1; - opt_local_infile= test(!optarg || atoi(optarg)>0); - break; - case OPT_TEE: - if (argument == disabled_my_option) - { - if (opt_outfile) - end_tee(); - opt_outfile= 0; - } - else - if (!opt_outfile) - { - strmov(outfile, argument); - opt_outfile= 1; - init_tee(); - } - break; - case OPT_NOTEE: - printf("WARNING: option depricated; use --disable-tee instead.\n"); + case OPT_CHARSETS_DIR: + strmov(mysql_charsets_dir, argument); + charsets_dir = mysql_charsets_dir; + break; + case OPT_LOCAL_INFILE: + using_opt_local_infile=1; + opt_local_infile= test(!argument || atoi(argument)>0); + break; + case OPT_TEE: + if (argument == disabled_my_option) + { if (opt_outfile) end_tee(); - opt_outfile= 0; - break; - case OPT_PAGER: - opt_nopager= 0; - if (argument) - strmov(pager, argument); - else - strmov(pager, default_pager); - strmov(default_pager, pager); - break; - case OPT_NOPAGER: - printf("WARNING: option depricated; use --disable-pager instead.\n"); - opt_nopager= 1; - break; - case OPT_PROMPT: - my_free(current_prompt,MYF(MY_ALLOW_ZERO_PTR)); - current_prompt=my_strdup(optarg,MYF(MY_FAE)); - break; - case 'b': - opt_nobeep = 1; - break; - case 'D': - my_free(current_db, MYF(MY_ALLOW_ZERO_PTR)); - current_db= my_strdup(argument, MYF(MY_WME)); - break; - case 'e': - status.batch= 1; - status.add_to_history= 0; - batch_readline_end(status.line_buff); // If multiple -e - if (!(status.line_buff= batch_readline_command(argument))) - return 1; - ignore_errors= 0; - break; - case 'h': - my_free(current_host, MYF(MY_ALLOW_ZERO_PTR)); - current_host= my_strdup(argument, MYF(MY_WME)); - break; -#ifndef DONT_ALLOW_USER_CHANGE - case 'u': - my_free(current_user, MYF(MY_ALLOW_ZERO_PTR)); - current_user= my_strdup(argument, MYF(MY_WME)); - break; -#endif - case 'o': - if (argument == disabled_my_option) - one_database= 0; - else - one_database= skip_updates= 1; - break; - case 'p': - if (argument == disabled_my_option) - opt_password= ""; - else - { - 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 ; - } - else - tty_password= 1; - } - break; - case '#': - DBUG_PUSH(argument ? argument : default_dbug_option); - info_flag= 1; - break; - case 's': - if (argument == disabled_my_option) - opt_silent= 0; - else - opt_silent++; - break; - case 'v': - if (argument == disabled_my_option) - verbose= 0; - else - verbose++; - break; - case 'B': - if (!status.batch) + } + else + if (!opt_outfile) { - status.batch= 1; - status.add_to_history= 0; - opt_silent++; // more silent + strmov(outfile, argument); + init_tee(); } - break; - case 'P': - opt_mysql_port= (unsigned int) atoi(argument); - break; - case 'S': - my_free(opt_mysql_unix_port, MYF(MY_ALLOW_ZERO_PTR)); - opt_mysql_unix_port= my_strdup(argument, MYF(0)); - break; - case 'W': + break; + case OPT_NOTEE: + printf("WARNING: option deprecated; use --disable-tee instead.\n"); + if (opt_outfile) + end_tee(); + break; + case OPT_PAGER: + opt_nopager= 0; + if (argument) + strmov(pager, argument); + else + strmov(pager, default_pager); + strmov(default_pager, pager); + break; + case OPT_NOPAGER: + printf("WARNING: option deprecated; use --disable-pager instead.\n"); + opt_nopager= 1; + break; + case 'A': + rehash= 0; + break; + case 'N': + column_names= 0; + break; + case 'e': + status.batch= 1; + status.add_to_history= 0; + batch_readline_end(status.line_buff); // If multiple -e + if (!(status.line_buff= batch_readline_command(argument))) + return 1; + ignore_errors= 0; + break; + case 'o': + if (argument == disabled_my_option) + one_database= 0; + else + one_database= skip_updates= 1; + break; + case 'p': + if (argument == disabled_my_option) + argument= (char*) ""; // Don't require password + 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 ; + } + else + tty_password= 1; + break; + case '#': + DBUG_PUSH(argument ? argument : default_dbug_option); + info_flag= 1; + break; + case 's': + if (argument == disabled_my_option) + opt_silent= 0; + else + opt_silent++; + break; + case 'v': + if (argument == disabled_my_option) + verbose= 0; + else + verbose++; + break; + case 'B': + if (!status.batch) + { + status.batch= 1; + status.add_to_history= 0; + opt_silent++; // more silent + } + break; + case 'W': #ifdef __WIN__ - opt_mysql_unix_port= my_strdup(MYSQL_NAMEDPIPE, MYF(0)); + opt_mysql_unix_port= my_strdup(MYSQL_NAMEDPIPE, MYF(0)); #endif - break; - case 'V': - usage(1); - exit(0); - case 'I': - case '?': - usage(0); - exit(0); + break; + case 'V': + usage(1); + exit(0); + case 'I': + case '?': + usage(0); + exit(0); #include "sslopt-case.h" } return 0; @@ -778,11 +740,7 @@ static int get_options(int argc, char **argv) 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); - } + exit(ho_error); if (status.batch) /* disable pager and outfile in this case */ { @@ -1180,7 +1138,7 @@ static char *new_command_generator(char *text,int state) /* Build up the completion hash */ -static void build_completion_hash(bool skip_rehash,bool write_info) +static void build_completion_hash(bool rehash, bool write_info) { COMMANDS *cmd=commands; MYSQL_RES *databases=0,*tables=0; @@ -1206,7 +1164,7 @@ static void build_completion_hash(bool skip_rehash,bool write_info) add_word(&ht,(char*) cmd->name); cmd++; } - if (skip_rehash) + if (!rehash) DBUG_VOID_RETURN; /* Free old used memory */ @@ -1345,7 +1303,7 @@ static int reconnect(void) { put_info("No connection. Trying to reconnect...",INFO_INFO); (void) com_connect((String *) 0, 0); - if(!no_rehash) com_rehash(NULL, NULL); + if(rehash) com_rehash(NULL, NULL); } if (!connected) return put_info("Can't connect to the server\n",INFO_ERROR); @@ -1556,17 +1514,22 @@ static void end_pager() static void init_tee() { + if (opt_outfile) + end_tee(); if (!(OUTFILE= my_fopen(outfile, O_APPEND | O_WRONLY, MYF(MY_WME)))) { - opt_outfile=0; + opt_outfile= 0; init_pager(); return; } + opt_outfile= 1; + tee_fprintf(stdout, "Logging to file '%s'\n", outfile); } static void end_tee() { my_fclose(OUTFILE, MYF(0)); + opt_outfile= 0; return; } @@ -1641,18 +1604,19 @@ print_table_data(MYSQL_RES *result) tee_puts(separator.c_ptr(), PAGER); } - while ((cur = mysql_fetch_row(result))) + while ((cur= mysql_fetch_row(result))) { (void) tee_fputs("|", PAGER); - mysql_field_seek(result,0); - for (uint off=0 ; off < mysql_num_fields(result); off++) + mysql_field_seek(result, 0); + for (uint off= 0; off < mysql_num_fields(result); off++) { - const char *str=cur[off] ? cur[off] : "NULL"; - field = mysql_fetch_field(result); - uint length=field->max_length; + const char *str= cur[off] ? cur[off] : "NULL"; + field= mysql_fetch_field(result); + uint length= field->max_length; if (length > MAX_COLUMN_LENGTH) { - tee_fputs(str,PAGER); tee_fputs(" |",PAGER); + tee_fputs(str, PAGER); + tee_fputs(" |", PAGER); } else tee_fprintf(PAGER, num_flag[off] ? "%*s |" : " %-*s|", @@ -1853,7 +1817,7 @@ print_tab_data(MYSQL_RES *result) for (uint off=1 ; off < mysql_num_fields(result); off++) { (void) tee_fputs("\t", PAGER); - safe_put_field(cur[off],lengths[off]); + safe_put_field(cur[off], lengths[off]); } (void) tee_fputs("\n", PAGER); } @@ -1872,8 +1836,8 @@ com_tee(String *buffer, char *line __attribute__((unused))) { if (!strlen(outfile)) { - printf("No previous outfile available, you must give the filename!\n"); - opt_outfile=0; + printf("No previous outfile available, you must give a filename!\n"); + opt_outfile= 0; return 0; } } @@ -1881,11 +1845,11 @@ com_tee(String *buffer, char *line __attribute__((unused))) { while (my_isspace(system_charset_info,*param)) param++; - end=strmake(file_name, param, sizeof(file_name)-1); + end= strmake(file_name, param, sizeof(file_name) - 1); while (end > file_name && (my_isspace(system_charset_info,end[-1]) || my_iscntrl(system_charset_info,end[-1]))) end--; - end[0]=0; + end[0]= 0; strmov(outfile, file_name); } if (!strlen(outfile)) @@ -1893,12 +1857,7 @@ com_tee(String *buffer, char *line __attribute__((unused))) printf("No outfile specified!\n"); return 0; } - if (!opt_outfile) - { - init_tee(); - opt_outfile=1; - } - tee_fprintf(stdout, "Logging to file '%s'\n", outfile); + init_tee(); return 0; } @@ -1908,7 +1867,6 @@ com_notee(String *buffer __attribute__((unused)), { if (opt_outfile) end_tee(); - opt_outfile=0; tee_fprintf(stdout, "Outfile disabled.\n"); return 0; } @@ -2031,7 +1989,7 @@ com_rehash(String *buffer __attribute__((unused)), char *line __attribute__((unused))) { #ifdef HAVE_READLINE - build_completion_hash(0,0); + build_completion_hash(1, 0); #endif return 0; } @@ -2075,7 +2033,7 @@ static int com_connect(String *buffer, char *line) { char *tmp,buff[256]; - bool save_rehash=no_rehash; + bool save_rehash= rehash; int error; if (buffer) @@ -2097,13 +2055,13 @@ com_connect(String *buffer, char *line) } } else - no_rehash=1; // Quick re-connect + rehash= 0; // Quick re-connect buffer->length(0); // command used } else - no_rehash=1; + rehash= 0; error=sql_connect(current_host,current_db,current_user,opt_password,0); - no_rehash=save_rehash; + rehash= save_rehash; if (connected) { @@ -2212,7 +2170,7 @@ com_use(String *buffer __attribute__((unused)), char *line) my_free(current_db,MYF(MY_ALLOW_ZERO_PTR)); current_db=my_strdup(tmp,MYF(MY_WME)); #ifdef HAVE_READLINE - build_completion_hash(no_rehash,1); + build_completion_hash(rehash, 1); #endif } } @@ -2270,7 +2228,7 @@ sql_real_connect(char *host,char *database,char *user,char *password, connected=1; mysql.reconnect=info_flag ? 1 : 0; // We want to know if this happens #ifdef HAVE_READLINE - build_completion_hash(no_rehash,1); + build_completion_hash(rehash, 1); #endif return 0; } @@ -2331,6 +2289,13 @@ com_status(String *buffer __attribute__((unused)), tee_fprintf(stdout, "Current user:\t\t%s\n",cur[1]); (void) mysql_fetch_row(result); // Read eof } +#ifdef HAVE_OPENSSL + if (mysql.net.vio->ssl_ && SSL_get_cipher(mysql.net.vio->ssl_)) + tee_fprintf(stdout, "SSL:\t\t\tCipher in use is %s\n", + SSL_get_cipher(mysql.net.vio->ssl_)); + else +#endif /* HAVE_OPENSSL */ + tee_puts("SSL:\t\t\tNot in use", stdout); } else { diff --git a/client/mysqladmin.c b/client/mysqladmin.c index 7f6d1d1a85d..fd2a17eee31 100644 --- a/client/mysqladmin.c +++ b/client/mysqladmin.c @@ -19,12 +19,11 @@ #include "client_priv.h" #include <signal.h> -#include <my_getopt.h> #ifdef THREAD #include <my_pthread.h> /* because of signal() */ #endif -#define ADMIN_VERSION "8.30" +#define ADMIN_VERSION "8.35" #define MAX_MYSQL_VAR 64 #define SHUTDOWN_DEF_TIMEOUT 3600 /* Wait for shutdown */ #define MAX_TRUNC_LENGTH 3 @@ -124,25 +123,27 @@ static struct my_option my_long_options[] = {"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, #endif - {"port", 'P', "Port number to use for connection.", 0, 0, 0, - GET_LONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"port", 'P', "Port number to use for connection.", (gptr*) &tcp_port, + (gptr*) &tcp_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"relative", 'r', "Show difference between current and previous values when used with -i. Currently works only with extended-status.", (gptr*) &opt_relative, (gptr*) &opt_relative, 0, GET_BOOL, 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.", + "Change the value of a variable. Please note that this option is deprecated; 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}, + (gptr*) &unix_port, (gptr*) &unix_port, 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}, + (gptr*) &interval, (gptr*) &interval, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, + 0, 0}, #include "sslopt-longopts.h" #ifndef DONT_ALLOW_USER_CHANGE {"user", 'u', "User for login if not current user.", (gptr*) &user, - (gptr*) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + (gptr*) &user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #endif {"verbose", 'v', "Write more information.", (gptr*) &opt_verbose, (gptr*) &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -155,10 +156,10 @@ static struct my_option my_long_options[] = {"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, + (gptr*) &opt_connect_timeout, 0, GET_ULONG, 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, + (gptr*) &opt_shutdown_timeout, 0, GET_ULONG, 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} }; @@ -173,10 +174,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), int error = 0; switch(optid) { - case 'h': - host = argument; - break; - case 'q': /* Allow old 'q' option */ case 'p': if (argument) { @@ -190,23 +187,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), else tty_password=1; break; -#ifndef DONT_ALLOW_USER_CHANGE - case 'u': - user= my_strdup(argument,MYF(0)); - break; -#endif - case 'i': - interval=atoi(argument); - break; - case 'P': - tcp_port= (unsigned int) atoi(argument); - break; case 's': option_silent++; break; - case 'S': - unix_port= argument; - break; case 'W': #ifdef __WIN__ unix_port=MYSQL_NAMEDPIPE; @@ -264,11 +247,8 @@ int main(int argc,char *argv[]) free_defaults() */ 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); - } + exit(ho_error); + if (argc == 0) { usage(); diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 3d30283d13a..3020e105954 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -38,26 +38,10 @@ static FILE *result_file; static const char* default_dbug_option = "d:t:o,/tmp/mysqlbinlog.trace"; #endif -static struct option long_options[] = -{ -#ifndef DBUG_OFF - {"debug", optional_argument, 0, '#'}, -#endif - {"help", no_argument, 0, '?'}, - {"host", required_argument, 0, 'h'}, - {"offset", required_argument, 0, 'o'}, - {"password", required_argument, 0, 'p'}, - {"port", required_argument, 0, 'P'}, - {"position", required_argument, 0, 'j'}, - {"result-file", required_argument, 0, 'r'}, - {"short-form", no_argument, 0, 's'}, - {"table", required_argument, 0, 't'}, - {"user", required_argument, 0, 'u'}, - {"version", no_argument, 0, 'V'}, -}; - void sql_print_error(const char *format,...); +static bool one_database = 0; +static const char* database; static bool short_form = 0; static ulonglong offset = 0; static const char* host = "localhost"; @@ -78,6 +62,44 @@ static void dump_remote_table(NET* net, const char* db, const char* table); static void die(const char* fmt, ...); static MYSQL* safe_connect(); +static struct my_option my_long_options[] = +{ +#ifndef DBUG_OFF + {"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', "List entries for just this database (local log only)", + (gptr*) &database, (gptr*) &database, 0, GET_STR_ALLOC, 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', "Get the binlog from server", (gptr*) &host, (gptr*) &host, + 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"offset", 'o', "Skip the first N entries", (gptr*) &offset, (gptr*) &offset, + 0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"password", 'p', "Password to connect to remote server", + 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"port", 'P', "Use port to connect to the remote server", + (gptr*) &port, (gptr*) &port, 0, GET_INT, REQUIRED_ARG, MYSQL_PORT, 0, 0, + 0, 0, 0}, + {"position", 'j', "Start reading the binlog at position N", + (gptr*) &position, (gptr*) &position, 0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, + 0, 0}, + {"result-file", 'r', "Direct output to a given file", 0, 0, 0, GET_STR, + REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"short-form", 's', "Just show the queries, no extra info", + (gptr*) &short_form, (gptr*) &short_form, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, + 0, 0}, + {"table", 't', "Get raw table dump using COM_TABLE_DUMB", (gptr*) &table, + (gptr*) &table, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"user", 'u', "Connect to the remote server as username", + (gptr*) &user, (gptr*) &user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, + 0, 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, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} +}; + void sql_print_error(const char *format,...) { @@ -102,38 +124,23 @@ static void die(const char* fmt, ...) static void print_version() { - printf("%s Ver 1.7 for %s at %s\n",my_progname,SYSTEM_TYPE, MACHINE_TYPE); + printf("%s Ver 2.3 for %s at %s\n", my_progname, SYSTEM_TYPE, MACHINE_TYPE); } static void usage() { print_version(); - puts("By Sasha, for your professional use\n\ -This software comes with NO WARRANTY: see the file PUBLIC for details\n"); + puts("By Monty and Sasha, for your professional use\n\ +This software comes with NO WARRANTY: This is free software,\n\ +and you are welcome to modify and redistribute it under the GPL license\n"); printf("\ Dumps a MySQL binary log in a format usable for viewing or for pipeing to\n\ the mysql command line client\n\n"); - printf("Usage: %s [options] log-files\n",my_progname); - puts("Options:"); -#ifndef DBUG_OFF - printf("-#, --debug[=...] Output debug log. (%s)\n", - default_dbug_option); -#endif - printf("\ --?, --help Display this help and exit\n\ --s, --short-form Just show the queries, no extra info\n\ --o, --offset=N Skip the first N entries\n\ --h, --host=server Get the binlog from server\n\ --P, --port=port Use port to connect to the remote server\n\ --u, --user=username Connect to the remote server as username\n\ --p, --password=password Password to connect to remote server\n\ --r, --result-file=file Direct output to a given file\n\ --j, --position=N Start reading the binlog at position N\n\ --t, --table=name Get raw table dump using COM_TABLE_DUMB\n\ --V, --version Print version and exit.\n\ -"); + printf("Usage: %s [options] log-files\n", my_progname); + my_print_help(my_long_options); + my_print_variables(my_long_options); } static void dump_remote_file(NET* net, const char* fname) @@ -166,76 +173,57 @@ static void dump_remote_file(NET* net, const char* fname) fflush(result_file); } -static int parse_args(int *argc, char*** argv) -{ - int c, opt_index = 0; - result_file = stdout; - while((c = getopt_long(*argc, *argv, "so:#::h:j:u:p:P:r:t:?V", long_options, - &opt_index)) != EOF) +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument) +{ + switch(optid) { - switch(c) - { #ifndef DBUG_OFF - case '#': - DBUG_PUSH(optarg ? optarg : default_dbug_option); - break; + case '#': + DBUG_PUSH(argument ? argument : default_dbug_option); + break; #endif - case 's': - short_form = 1; - break; - - case 'o': - offset = strtoull(optarg,(char**) 0, 10); - break; - - case 'j': - position = strtoull(optarg,(char**) 0, 10); - break; - - case 'h': - use_remote = 1; - host = my_strdup(optarg, MYF(0)); - break; - - case 'P': - use_remote = 1; - port = atoi(optarg); - break; - - case 'p': - use_remote = 1; - pass = my_strdup(optarg, MYF(0)); - break; - - case 'r': - if (!(result_file = my_fopen(optarg, O_WRONLY | O_BINARY, MYF(MY_WME)))) - exit(1); - break; - - case 'u': - use_remote = 1; - user = my_strdup(optarg, MYF(0)); - break; - - case 't': - table = my_strdup(optarg, MYF(0)); - break; - - case 'V': - print_version(); - exit(0); + case 'd': + one_database = 1; + break; + case 'h': + use_remote = 1; + break; + case 'P': + use_remote = 1; + break; + case 'p': + use_remote = 1; + pass = my_strdup(argument, MYF(0)); + break; + case 'r': + if (!(result_file = my_fopen(argument, O_WRONLY | O_BINARY, MYF(MY_WME)))) + exit(1); + break; + case 'u': + use_remote = 1; + break; + case 'V': + print_version(); + exit(0); + case '?': + default: + usage(); + exit(0); + } + return 0; +} - case '?': - default: - usage(); - exit(0); - } - } +static int parse_args(int *argc, char*** argv) +{ + int ho_error; - (*argc)-=optind; - (*argv)+=optind; + result_file = stdout; + if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option))) + exit(ho_error); return 0; } @@ -471,6 +459,37 @@ Could not read entry at offset %s : Error in log format or read error", } if (rec_count >= offset) { + // see if we should skip this event (only care about queries for now) + if (one_database) + { + if (ev->get_type_code() == QUERY_EVENT) + { + //const char * log_dbname = ev->get_db(); + const char * log_dbname = ((Query_log_event*)ev)->db; + //printf("entry: %llu, database: %s\n", rec_count, log_dbname); + + if ((log_dbname != NULL) && (strcmp(log_dbname, database))) + { + //printf("skipping, %s is not %s\n", log_dbname, database); + rec_count++; + delete ev; + continue; // next + } +#ifndef DBUG_OFF + else + { + printf("no skip\n"); + } +#endif + } +#ifndef DBUG_OFF + else + { + const char * query_type = ev->get_type_str(); + printf("not query -- %s\n", query_type); + } +#endif + } if (!short_form) fprintf(result_file, "# at %s\n",llstr(old_off,llbuff)); diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c index 86507bc0b31..78cd277f9be 100644 --- a/client/mysqlcheck.c +++ b/client/mysqlcheck.c @@ -16,10 +16,9 @@ /* By Jani Tolonen, 2001-04-20, MySQL Development Team */ -#define CHECK_VERSION "2.0" +#define CHECK_VERSION "2.4" #include "client_priv.h" -#include <my_getopt.h> #include <m_ctype.h> #include "mysql_version.h" #include "mysqld_error.h" @@ -94,7 +93,7 @@ static struct my_option my_long_options[] = {"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*) ¤t_host, - (gptr*) ¤t_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + (gptr*) ¤t_host, 0, GET_STR_ALLOC, 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}, @@ -107,8 +106,9 @@ static struct my_option my_long_options[] = {"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, #endif - {"port", 'P', "Port number to use for connection.", 0, 0, 0, GET_LONG, - REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"port", 'P', "Port number to use for connection.", (gptr*) &opt_mysql_port, + (gptr*) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0, + 0}, {"quick", 'q', "If you are using this option with CHECK TABLE, it prevents the check from scanning the rows to check for wrong links. This is the fastest check. If you are using this option with REPAIR TABLE, it will try to repair only the index tree. This is the fastest repair method for a table.", (gptr*) &opt_quick, (gptr*) &opt_quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, @@ -165,9 +165,8 @@ static void usage(void) { print_version(); puts("By Jani Tolonen, 2001-04-20, MySQL Development Team\n"); - puts("This software comes with ABSOLUTELY NO WARRANTY. This is free"); - puts("software and you are welcome to modify and redistribute it"); - puts("under the GPL license.\n"); + puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n"); + puts("and you are welcome to modify and redistribute it under the GPL license.\n"); puts("This program can be used to CHECK (-c,-m,-C), REPAIR (-r), ANALYZE (-a)"); puts("or OPTIMIZE (-o) tables. Some of the options (like -e or -q) can be"); puts("used same time. It works on MyISAM and in some cases on BDB tables."); @@ -198,12 +197,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), 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; @@ -215,10 +208,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), 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; @@ -226,11 +215,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), case 'o': what_to_do = DO_OPTIMIZE; break; -#ifndef DONT_ALLOW_USER_CHANGE - case 'u': - current_user = argument; - break; -#endif case 'p': if (argument) { @@ -244,15 +228,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), 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; @@ -287,11 +265,7 @@ static int get_options(int *argc, char ***argv) 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); - } + exit(ho_error); if (!what_to_do) { @@ -614,8 +588,8 @@ int main(int argc, char **argv) if (dbConnect(current_host, current_user, opt_password)) exit(EX_MYSQLERR); - if (opt_auto_repair && - init_dynamic_array(&tables4repair, sizeof(char)*(NAME_LEN*2+2),16,64)) + if (opt_auto_repair && + my_init_dynamic_array(&tables4repair, sizeof(char)*(NAME_LEN*2+2),16,64)) { first_error = 1; goto end; diff --git a/client/mysqldump.c b/client/mysqldump.c index 833f28bba98..9c27029582c 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -35,7 +35,7 @@ ** and adapted to mysqldump 05/11/01 by Jani Tolonen */ -#define DUMP_VERSION "9.00" +#define DUMP_VERSION "9.06" #include <my_global.h> #include <my_sys.h> @@ -46,7 +46,6 @@ #include "mysql.h" #include "mysql_version.h" #include "mysqld_error.h" -#include <my_getopt.h> /* Exit codes */ @@ -64,6 +63,9 @@ #define SHOW_EXTRA 5 #define QUOTE_CHAR '`' +/* Size of buffer for dump's select query */ +#define QUERY_LENGTH 1536 + static char *add_load_option(char *ptr, const char *object, const char *statement); @@ -94,8 +96,9 @@ static struct my_option my_long_options[] = "Dump all the databases. This will be same as --databases with all databases selected.", (gptr*) &opt_alldbs, (gptr*) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, - {"all", 'a', "Include all MySQL specific create options.", 0, 0, 0, - GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"all", 'a', "Include all MySQL specific create options.", + (gptr*) &create_options, (gptr*) &create_options, 0, GET_BOOL, NO_ARG, 0, + 0, 0, 0, 0, 0}, {"add-drop-table", OPT_DROP, "Add a 'drop table' before each create.", (gptr*) &opt_drop, (gptr*) &opt_drop, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -108,8 +111,8 @@ static struct my_option my_long_options[] = {"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}, - {"complete-insert", 'c', "Use complete insert statements.", 0, 0, 0, - GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"complete-insert", 'c', "Use complete insert statements.", (gptr*) &cFlag, + (gptr*) &cFlag, 0, GET_BOOL, NO_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}, @@ -155,7 +158,7 @@ static struct my_option my_long_options[] = {"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*) ¤t_host, - (gptr*) ¤t_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + (gptr*) ¤t_host, 0, GET_STR_ALLOC, 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}, @@ -173,11 +176,11 @@ static struct my_option my_long_options[] = (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}, + (gptr*) &tFlag, (gptr*) &tFlag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"no-data", 'd', "No row information.", (gptr*) &dFlag, (gptr*) &dFlag, 0, + GET_BOOL, 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.", + "Change the value of a variable. Please note that this option is deprecated; 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", @@ -189,8 +192,9 @@ static struct my_option my_long_options[] = {"pipe", 'W', "Use named pipes to connect to server", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, #endif - {"port", 'P', "Port number to use for connection.", 0, 0, 0, GET_LONG, - REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"port", 'P', "Port number to use for connection.", (gptr*) &opt_mysql_port, + (gptr*) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0, + 0}, {"quick", 'q', "Don't buffer query, dump directly to stdout.", (gptr*) &quick, (gptr*) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"quote-names",'Q', "Quote table and column names with a `", @@ -198,8 +202,7 @@ static struct my_option my_long_options[] = 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}, + 0, 0, 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}, @@ -222,15 +225,15 @@ static struct my_option my_long_options[] = (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, "", + {"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, + GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096, 512*1024L*1024L, MALLOC_OVERHEAD, 1024, 0}, - { "net_buffer_length", OPT_NET_BUFFER_LENGTH, "", + {"net_buffer_length", OPT_NET_BUFFER_LENGTH, "", (gptr*) &net_buffer_length, (gptr*) &net_buffer_length, 0, - GET_LONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L, + GET_ULONG, REQUIRED_ARG, 1024*1024L-1025, 4096, 16*1024L*1024L, MALLOC_OVERHEAD-1024, 1024, 0}, - { 0, 0, 0, 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[]= { "mysqldump","client",0 }; @@ -257,7 +260,6 @@ static void print_version(void) static void usage(void) { - uint i; print_version(); puts("By Igor Romanenko, Monty, Jani & Sinisa"); 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"); @@ -299,24 +301,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), opt_master_data=1; opt_first_slave=1; break; - case 'a': - create_options=1; - break; - case OPT_DEFAULT_CHARSET: - default_charset= argument; - break; - case OPT_CHARSETS_DIR: - charsets_dir= argument; - break; - case 'h': - my_free(current_host,MYF(MY_ALLOW_ZERO_PTR)); - current_host=my_strdup(argument,MYF(MY_WME)); - break; -#ifndef DONT_ALLOW_USER_CHANGE - case 'u': - current_user=argument; - break; -#endif case 'p': if (argument) { @@ -330,62 +314,31 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), else tty_password=1; break; - case 'P': - opt_mysql_port= (unsigned int) atoi(argument); - break; case 'r': if (!(md_result_file = my_fopen(argument, O_WRONLY | O_BINARY, MYF(MY_WME)))) exit(1); break; - case 'S': - opt_mysql_unix_port= argument; - break; case 'W': #ifdef __WIN__ opt_mysql_unix_port=MYSQL_NAMEDPIPE; #endif break; case 'T': - path= argument; opt_disable_keys=0; break; case '#': DBUG_PUSH(argument ? argument : "d:t:o"); break; - case 'c': cFlag=1; break; - case 'd': dFlag=1; break; - case 't': tFlag=1; break; case 'V': print_version(); exit(0); - case 'w': - where=argument; - break; case 'X': opt_xml = 1; opt_disable_keys=0; break; - default: - fprintf(stderr,"%s: Illegal option character '%c'\n",my_progname,opterr); - /* Fall throught */ case 'I': case '?': usage(); exit(0); - case (int) OPT_FTB: - fields_terminated= argument; - break; - case (int) OPT_LTB: - lines_terminated= argument; - break; - case (int) OPT_ENC: - enclosed= argument; - break; - case (int) OPT_O_ENC: - opt_enclosed= argument; - break; - case (int) OPT_ESC: - escaped= argument; - break; case (int) OPT_OPTIMIZE: extended_insert=opt_drop=opt_lock=lock_tables=quick=create_options= opt_disable_keys=1; @@ -407,11 +360,7 @@ static int get_options(int *argc, char ***argv) 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); - } + exit(ho_error); if (opt_delayed) opt_lock=0; /* Can't have lock with delayed */ @@ -910,7 +859,7 @@ static char *field_escape(char *to,const char *from,uint length) */ static void dumpTable(uint numFields, char *table) { - char query[1024], *end, buff[256],table_buff[NAME_LEN+3]; + char query[QUERY_LENGTH], *end, buff[256],table_buff[NAME_LEN+3]; MYSQL_RES *res; MYSQL_FIELD *field; MYSQL_ROW row; @@ -927,7 +876,8 @@ static void dumpTable(uint numFields, char *table) my_delete(filename, MYF(0)); /* 'INTO OUTFILE' doesn't work, if filename wasn't deleted */ to_unix_path(filename); - sprintf(query, "SELECT * INTO OUTFILE '%s'", filename); + sprintf(query, "SELECT /*!40001 SQL_NO_CACHE */ * INTO OUTFILE '%s'", + filename); end= strend(query); if (replace) end= strmov(end, " REPLACE"); @@ -958,7 +908,8 @@ static void dumpTable(uint numFields, char *table) if (!opt_xml) fprintf(md_result_file,"\n--\n-- Dumping data for table '%s'\n--\n", table); - sprintf(query, "SELECT * FROM %s", quote_name(table,table_buff)); + sprintf(query, "SELECT /*!40001 SQL_NO_CACHE */ * FROM %s", + quote_name(table,table_buff)); if (where) { if (!opt_xml) @@ -1424,8 +1375,6 @@ int main(int argc, char **argv) return(first_error); } } - if(mysql_query(sock, "set sql_query_cache_type=off") && verbose) - fprintf(stderr, "-- can't take off query cache (not supported).\n"); if (opt_alldbs) dump_all_databases(); /* Only one database and selected table(s) */ diff --git a/client/mysqlimport.c b/client/mysqlimport.c index e8403abe8c1..1933ea41bcf 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -25,11 +25,10 @@ ** * * ** ************************* */ -#define IMPORT_VERSION "3.0" +#define IMPORT_VERSION "3.4" #include "client_priv.h" #include "mysql_version.h" -#include <my_getopt.h> static void db_error_with_table(MYSQL *mysql, char *table); static void db_error(MYSQL *mysql); @@ -90,8 +89,9 @@ static struct my_option my_long_options[] = (gptr*) ¤t_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}, - {"ignore-lines", OPT_IGN_LINES, "Ignore first n lines of data infile.", 0, 0, - 0, GET_LL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"ignore-lines", OPT_IGN_LINES, "Ignore first n lines of data infile.", + (gptr*) &opt_ignore_lines, (gptr*) &opt_ignore_lines, 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}, @@ -110,7 +110,8 @@ static struct my_option my_long_options[] = NO_ARG, 0, 0, 0, 0, 0, 0}, #endif {"port", 'P', "Port number to use for connection.", (gptr*) &opt_mysql_port, - (gptr*) &opt_mysql_port, 0, GET_LONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + (gptr*) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0, + 0}, {"replace", 'r', "If duplicate unique key was found, replace old row.", (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, @@ -165,23 +166,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), char *argument) { switch(optid) { - case 'c': - opt_columns= argument; - break; - case OPT_DEFAULT_CHARSET: - default_charset= argument; - break; - case OPT_CHARSETS_DIR: - charsets_dir= argument; - break; - case 'h': - current_host= argument; - break; -#ifndef DONT_ALLOW_USER_CHANGE - case 'u': - current_user= argument; - break; -#endif case 'p': if (argument) { @@ -195,12 +179,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), else tty_password= 1; break; - case 'P': - opt_mysql_port= (unsigned int) atoi(argument); - break; - case 'S': - opt_mysql_unix_port= argument; - break; #ifdef __WIN__ case 'W': opt_mysql_unix_port=MYSQL_NAMEDPIPE; @@ -215,24 +193,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), case '?': usage(); exit(0); - case (int) OPT_FTB: - fields_terminated= argument; - break; - case (int) OPT_LTB: - lines_terminated= argument; - break; - case (int) OPT_ENC: - enclosed= argument; - break; - case (int) OPT_O_ENC: - opt_enclosed= argument; - break; - case (int) OPT_ESC: - escaped= argument; - break; - case (int) OPT_IGN_LINES: - opt_ignore_lines= argument; - break; #include "sslopt-case.h" } return 0; @@ -244,11 +204,8 @@ 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); - } + exit(ho_error); + if (enclosed && opt_enclosed) { fprintf(stderr, "You can't use ..enclosed.. and ..optionally-enclosed.. at the same time.\n"); diff --git a/client/mysqlmanager-pwgen.c b/client/mysqlmanager-pwgen.c index 97eb31eb9c8..40126e279b5 100644 --- a/client/mysqlmanager-pwgen.c +++ b/client/mysqlmanager-pwgen.c @@ -14,7 +14,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define MANAGER_PWGEN_VERSION "1.0" +#define MANAGER_PWGEN_VERSION "1.4" #include <my_global.h> #include <m_ctype.h> @@ -22,18 +22,23 @@ #include <m_string.h> #include <mysql_version.h> #include <errno.h> -#include <getopt.h> +#include <my_getopt.h> #include <md5.h> const char* outfile=0,*user="root"; -struct option long_options[] = +static struct my_option my_long_options[] = { - {"output-file",required_argument,0,'o'}, - {"user",required_argument,0,'u'}, - {"help",no_argument,0,'?'}, - {"version",no_argument,0,'V'}, - {0,0,0,0} + {"output-file", 'o', "Write the output to the file with the given name", + (gptr*) &outfile, (gptr*) &outfile, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, + 0, 0}, + {"user", 'u', "Put given user in the password file", (gptr*) &user, + (gptr*) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"help", '?', "Display this message and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, + 0, 0, 0, 0, 0, 0}, + {"version", 'V', "Display version info", 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 die(const char* fmt, ...) @@ -66,40 +71,36 @@ void usage() printf("This software comes with ABSOLUTELY NO WARRANTY\n\n"); printf("Generates a password file to be used by mysqltest.\n\n"); printf("Usage: %s [OPTIONS]\n", my_progname); - printf("-?,--help Display this message and exit\n\ --V,--version Display version info\n\ --u,--user= Put given user in the password file\n\ --o,--output-file= Write the output to the file with the given name\n"); + my_print_help(my_long_options); + my_print_variables(my_long_options); } -int parse_args(int argc, char** argv) +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument __attribute__((unused))) { - int c,option_index=0; - while ((c=getopt_long(argc,argv,"?Vu:o:",long_options,&option_index)) - != EOF) - { - switch (c) - { - case 'o': - outfile=optarg; - break; - case 'u': - user=optarg; - break; - case '?': - usage(); - exit(0); - case 'V': - print_version(); - exit(0); - default: - usage(); - exit(1); - } + switch (optid) { + case '?': + usage(); + exit(0); + case 'V': + print_version(); + exit(0); } return 0; } + +int parse_args(int argc, char** argv) +{ + int ho_error; + + if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) + exit(ho_error); + + return 0; +} + void get_pass(char* pw, int len) { FILE* fp; diff --git a/client/mysqlmanagerc.c b/client/mysqlmanagerc.c index a01f6c25f34..f200b993147 100644 --- a/client/mysqlmanagerc.c +++ b/client/mysqlmanagerc.c @@ -14,7 +14,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define MANAGER_CLIENT_VERSION "1.1" +#define MANAGER_CLIENT_VERSION "1.4" #include <my_global.h> #include <mysql.h> @@ -22,7 +22,7 @@ #include <mysqld_error.h> #include <my_sys.h> #include <m_string.h> -#include <getopt.h> +#include <my_getopt.h> #include <stdarg.h> #include <sys/stat.h> #include <unistd.h> @@ -35,23 +35,31 @@ static void die(const char* fmt, ...); const char* user="root",*host="localhost"; char* pass=0; -int quiet=0; +my_bool quiet=0; uint port=MYSQL_MANAGER_PORT; static const char *load_default_groups[]= { "mysqlmanagerc",0 }; char** default_argv; MYSQL_MANAGER *manager; FILE* fp, *fp_out; -struct option long_options[] = +static struct my_option my_long_options[] = { - {"host",required_argument,0,'h'}, - {"user",required_argument,0,'u'}, - {"password",optional_argument,0,'p',}, - {"port",required_argument,0,'P'}, - {"help",no_argument,0,'?'}, - {"version",no_argument,0,'V'}, - {"quiet",no_argument,0,'q'}, - {0,0,0,0} + {"host", 'h', "Connect to host.", (gptr*) &host, (gptr*) &host, 0, + GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"user", 'u', "User for login.", (gptr*) &user, (gptr*) &user, 0, + GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"password", 'p', "Password to use when connecting to server.", + 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, + {"port", 'P', "Port number to use for connection.", (gptr*) &port, + (gptr*) &port, 0, GET_UINT, REQUIRED_ARG, MYSQL_MANAGER_PORT, 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}, + {"version", 'V', "Output version information and exit.", 0, 0, 0, + GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"quiet", 'q', "Suppress all normal output.", (gptr*) &quiet, (gptr*) &quiet, + 0, GET_BOOL, 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 die(const char* fmt, ...) @@ -84,65 +92,51 @@ void usage() printf("This software comes with ABSOLUTELY NO WARRANTY\n\n"); printf("Command-line client for MySQL manager daemon.\n\n"); printf("Usage: %s [OPTIONS] < command_file\n", my_progname); - printf("\n\ - -?, --help Display this help and exit.\n"); - printf("\ - -h, --host=... Connect to host.\n\ - -u, --user=... User for login.\n\ - -p[password], --password[=...]\n\ - Password to use when connecting to server.\n\ - -P, --port=... Port number to use for connection.\n\ - -q, --quiet, --silent Suppress all normal output.\n\ - -V, --version Output version information and exit.\n\ - --no-defaults Don't read default options from any options file.\n\n"); + my_print_help(my_long_options); + printf(" --no-defaults Don't read default options from any options file.\n"); + my_print_variables(my_long_options); } -int parse_args(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 = 0; my_bool tty_password=0; + + switch (optid) { + case 'p': + if (argument) + { + my_free(pass, MYF(MY_ALLOW_ZERO_PTR)); + pass= my_strdup(argument, MYF(MY_FAE)); + while (*argument) *argument++= 'x'; /* Destroy argument */ + } + else + tty_password=1; + break; + case 'V': + print_version(); + exit(0); + case '?': + usage(); + exit(0); + } + return 0; +} + + +int parse_args(int argc, char **argv) +{ + int ho_error; load_defaults("my",load_default_groups,&argc,&argv); default_argv= argv; - while ((c = getopt_long(argc, argv, "h:p::u:P:?Vq", - long_options, &option_index)) != EOF) - { - switch (c) - { - case 'h': - host=optarg; - break; - case 'u': - user=optarg; - break; - case 'p': - if (optarg) - { - my_free(pass,MYF(MY_ALLOW_ZERO_PTR)); - pass=my_strdup(optarg,MYF(MY_FAE)); - while (*optarg) *optarg++= 'x'; /* Destroy argument */ - } - else - tty_password=1; - break; - case 'P': - port=atoi(optarg); - break; - case 'q': - quiet=1; - break; - case 'V': - print_version(); - exit(0); - case '?': - usage(); - exit(0); - default: - usage(); - exit(1); - } - } - return 0; + if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) + exit(ho_error); + + return 0; } int main(int argc, char** argv) { diff --git a/client/mysqlshow.c b/client/mysqlshow.c index 2326d72ea34..81b4d2ab4f7 100644 --- a/client/mysqlshow.c +++ b/client/mysqlshow.c @@ -16,7 +16,7 @@ /* Show databases, tables or columns */ -#define SHOW_VERSION "9.0" +#define SHOW_VERSION "9.4" #include <my_global.h> #include "client_priv.h" @@ -27,7 +27,6 @@ #include "mysqld_error.h" #include <signal.h> #include <stdarg.h> -#include <my_getopt.h> #include "sslopt-vars.h" static my_string host=0,opt_password=0,user=0; @@ -144,8 +143,9 @@ static struct my_option my_long_options[] = {"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}, + {"port", 'P', "Port number to use for connection.", (gptr*) &opt_mysql_port, + (gptr*) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0, + 0}, #ifdef __WIN__ {"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -197,15 +197,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), char *argument) { switch(optid) { - case 'c': - charsets_dir= argument; - break; case 'v': opt_verbose++; break; - case 'h': - host = argument; - break; case 'p': if (argument) { @@ -219,17 +213,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), else tty_password=1; break; -#ifndef DONT_ALLOW_USER_CHANGE - case 'u': - user=argument; - break; -#endif - case 'P': - opt_mysql_port= (unsigned int) atoi(argument); - break; - case 'S': - opt_mysql_unix_port= argument; - break; case 'W': #ifdef __WIN__ opt_mysql_unix_port=MYSQL_NAMEDPIPE; @@ -258,11 +241,7 @@ 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); - } + exit(ho_error); if (tty_password) opt_password=get_tty_password(NullS); diff --git a/client/mysqltest.c b/client/mysqltest.c index e75cc9190e5..b13f6b710eb 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -22,6 +22,7 @@ * Sasha Pachev <sasha@mysql.com> * Matt Wagner <matt@mysql.com> * Monty + * Jani **/ /********************************************************************** @@ -41,7 +42,7 @@ **********************************************************************/ -#define MTEST_VERSION "1.14" +#define MTEST_VERSION "1.23" #include <my_global.h> #include <mysql_embed.h> @@ -55,7 +56,7 @@ #include <hash.h> #include <stdio.h> #include <stdlib.h> -#include <getopt.h> +#include <my_getopt.h> #include <stdarg.h> #include <sys/stat.h> #include <unistd.h> @@ -95,10 +96,12 @@ enum {OPT_MANAGER_USER=256,OPT_MANAGER_HOST,OPT_MANAGER_PASSWD, OPT_MANAGER_PORT,OPT_MANAGER_WAIT_TIMEOUT}; -static int record = 0, verbose = 0, silent = 0, opt_sleep=0; +static int record = 0, opt_sleep=0; static char *db = 0, *pass=0; const char* user = 0, *host = 0, *unix_sock = 0, *opt_basedir="./"; -static int port = 0, opt_big_test=0, opt_compress=0; +static int port = 0; +static my_bool opt_big_test= 0, opt_compress= 0, silent= 0, verbose = 0, + tty_password= 0; static uint start_lineno, *lineno; const char* manager_user="root",*manager_host=0; char *manager_pass=0; @@ -661,7 +664,7 @@ int open_file(const char* name) } /* ugly long name, but we are following the convention */ -int do_wait_for_slave_to_stop(struct st_query* __attribute__((unused)) q) +int do_wait_for_slave_to_stop(struct st_query* q __attribute__((unused))) { MYSQL* mysql = &cur_con->mysql; #ifndef OS2 @@ -699,7 +702,7 @@ int do_wait_for_slave_to_stop(struct st_query* __attribute__((unused)) q) return 0; } -int do_require_manager(struct st_query* __attribute__((unused)) q) +int do_require_manager(struct st_query* a __attribute__((unused))) { if (!manager) abort_not_supported_test(); @@ -1022,20 +1025,20 @@ int do_let(struct st_query* q) return var_set(var_name, var_name_end, var_val_start, q->end); } -int do_rpl_probe(struct st_query* __attribute__((unused)) q) +int do_rpl_probe(struct st_query* q __attribute__((unused))) { if(mysql_rpl_probe(&cur_con->mysql)) die("Failed in mysql_rpl_probe(): %s", mysql_error(&cur_con->mysql)); return 0; } -int do_enable_rpl_parse(struct st_query* __attribute__((unused)) q) +int do_enable_rpl_parse(struct st_query* q __attribute__((unused))) { mysql_enable_rpl_parse(&cur_con->mysql); return 0; } -int do_disable_rpl_parse(struct st_query* __attribute__((unused)) q) +int do_disable_rpl_parse(struct st_query* q __attribute__((unused))) { mysql_disable_rpl_parse(&cur_con->mysql); return 0; @@ -1448,7 +1451,7 @@ int do_connect(struct st_query* q) if (!con_db[0]) con_db=db; /* Special database to allow one to connect without a database name */ - if (!strcmp(con_db,"*NO-ONE*")) + if (con_db && !strcmp(con_db,"*NO-ONE*")) con_db=0; if ((con_error = safe_connect(&next_con->mysql, con_host, con_user, con_pass, @@ -1785,36 +1788,74 @@ int read_query(struct st_query** q_ptr) return 0; } -struct option long_options[] = -{ - {"debug", optional_argument, 0, '#'}, - {"database", required_argument, 0, 'D'}, - {"basedir", required_argument, 0, 'b'}, - {"big-test", no_argument, 0, 'B'}, - {"compress", no_argument, 0, 'C'}, - {"help", no_argument, 0, '?'}, - {"host", required_argument, 0, 'h'}, - {"manager-user",required_argument, 0, OPT_MANAGER_USER}, - {"manager-host",required_argument, 0, OPT_MANAGER_HOST}, - {"manager-password",required_argument,0,OPT_MANAGER_PASSWD}, - {"manager-port",required_argument,0,OPT_MANAGER_PORT}, - {"manager-wait-timeout",required_argument,0,OPT_MANAGER_WAIT_TIMEOUT}, - {"password", optional_argument, 0, 'p'}, - {"port", required_argument, 0, 'P'}, - {"quiet", no_argument, 0, 's'}, - {"record", no_argument, 0, 'r'}, - {"result-file", required_argument, 0, 'R'}, - {"server-arg", required_argument, 0, 'A'}, - {"server-file", required_argument, 0, 'F'}, - {"silent", no_argument, 0, 's'}, - {"sleep", required_argument, 0, 'T'}, - {"socket", required_argument, 0, 'S'}, - {"test-file", required_argument, 0, 'x'}, - {"tmpdir", required_argument, 0, 't'}, - {"user", required_argument, 0, 'u'}, - {"verbose", no_argument, 0, 'v'}, - {"version", no_argument, 0, 'V'}, - {0, 0, 0, 0} + +static struct my_option my_long_options[] = +{ +#ifndef DBUG_OFF + {"debug", '#', "Output debug log. Often this is 'd:t:o,filename'", + 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, +#endif + {"database", 'D', "Database to use.", (gptr*) &db, (gptr*) &db, 0, + GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"basedir", 'b', "Basedir for tests", (gptr*) &opt_basedir, + (gptr*) &opt_basedir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"big-test", 'B', "Define BIG_TEST to 1", (gptr*) &opt_big_test, + (gptr*) &opt_big_test, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"compress", 'C', "Use the compressed server/client protocol", + (gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_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}, + {"manager-user", OPT_MANAGER_USER, "Undocumented: Used for debugging", + (gptr*) &manager_user, (gptr*) &manager_user, 0, GET_STR, REQUIRED_ARG, 0, + 0, 0, 0, 0, 0}, + {"manager-host", OPT_MANAGER_HOST, "Undocumented: Used for debugging", + (gptr*) &manager_host, (gptr*) &manager_host, 0, GET_STR, REQUIRED_ARG, + 0, 0, 0, 0, 0, 0}, + {"manager-password", OPT_MANAGER_PASSWD, "Undocumented: Used for debugging", + 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"manager-port", OPT_MANAGER_PORT, "Undocumented: Used for debugging", + (gptr*) &manager_port, (gptr*) &manager_port, 0, GET_INT, REQUIRED_ARG, + MYSQL_MANAGER_PORT, 0, 0, 0, 0, 0}, + {"manager-wait-timeout", OPT_MANAGER_WAIT_TIMEOUT, + "Undocumented: Used for debugging", (gptr*) &manager_wait_timeout, + (gptr*) &manager_wait_timeout, 0, GET_INT, REQUIRED_ARG, 3, 0, 0, 0, 0, 0}, + {"password", 'p', "Password to use when connecting to server.", + 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, + {"port", 'P', "Port number to use for connection.", (gptr*) &port, + (gptr*) &port, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"quiet", 's', "Suppress all normal output.", (gptr*) &silent, + (gptr*) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"record", 'r', "Record output of test_file into result file.", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"result-file", 'R', "Read/Store result from/in this file.", + (gptr*) &result_file, (gptr*) &result_file, 0, GET_STR, REQUIRED_ARG, + 0, 0, 0, 0, 0, 0}, + {"server-arg", 'A', "Send enbedded server this as a paramenter", + 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"server-file", 'F', "Read embedded server arguments from file", + 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"silent", 's', "Suppress all normal output. Synonym for --quiet.", + (gptr*) &silent, (gptr*) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"sleep", 'T', "Sleep always this many seconds on sleep commands", + (gptr*) &opt_sleep, (gptr*) &opt_sleep, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, + 0, 0, 0}, + {"socket", 'S', "Socket file to use for connection.", + (gptr*) &unix_sock, (gptr*) &unix_sock, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, + 0, 0, 0}, + {"test-file", 'x', "Read test from/in this file (default stdin).", + 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"tmpdir", 't', "Temporary directory where sockets are put", + 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"user", 'u', "User for login.", (gptr*) &user, (gptr*) &user, 0, GET_STR, + REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"verbose", 'v', "Write more.", (gptr*) &verbose, (gptr*) &verbose, 0, + GET_BOOL, 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} }; @@ -1827,170 +1868,97 @@ static void print_version(void) void usage() { print_version(); - printf("MySQL AB, by Sasha, Matt & Monty\n"); + printf("MySQL AB, by Sasha, Matt, Monty & Jani\n"); printf("This software comes with ABSOLUTELY NO WARRANTY\n\n"); printf("Runs a test against the mysql server and compares output with a results file.\n\n"); printf("Usage: %s [OPTIONS] [database] < test_file\n", my_progname); - printf("\n\ - -?, --help Display this help and exit.\n"); -#ifndef DBUG_OFF - puts("\ - -#, --debug=[...] Output debug log. Often this is 'd:t:o,filename`"); -#endif - printf("\ - -h, --host=... Connect to host.\n\ - -u, --user=... User for login.\n\ - -p[password], --password[=...]\n\ - Password to use when connecting to server.\n\ - -b, --basedir=... Basedir for tests\n\ - -B, --big-test Define BIG_TEST to 1\n\ - -C, --compress Use the compressed server/client protocol\n\ - -D, --database=... Database to use.\n\ - -P, --port=... Port number to use for connection.\n\ - --server-arg=... Send enbedded server this as a paramenter\n\ - --server-file=... Read embedded server arguments from file\n\ - -s, --silent, --quiet Suppress all normal output.\n\ - -S, --socket=... Socket file to use for connection.\n\ - -t, --tmpdir=... Temporary directory where sockets are put\n\ - -T, --sleep=# Sleep always this many seconds on sleep commands\n\ - -r, --record Record output of test_file into result file.\n\ - -R, --result-file=... Read/Store result from/in this file.\n\ - -x, --test-file=... Read test from/in this file (default stdin).\n\ - -v, --verbose Write more.\n\ - -V, --version Output version information and exit.\n\ - --no-defaults Don't read default options from any options file.\n\n"); + my_print_help(my_long_options); + printf(" --no-defaults Don't read default options from any options file.\n"); + my_print_variables(my_long_options); } + +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), + char *argument) +{ + switch(optid) { + case '#': + DBUG_PUSH(argument ? argument : "d:t:S:i:O,/tmp/mysqltest.trace"); + break; + case 'r': + record = 1; + break; + case (int)OPT_MANAGER_PASSWD: + my_free(manager_pass,MYF(MY_ALLOW_ZERO_PTR)); + manager_pass=my_strdup(argument, MYF(MY_FAE)); + while (*argument) *argument++= 'x'; /* Destroy argument */ + break; + case 'x': + { + char buff[FN_REFLEN]; + if (!test_if_hard_path(argument)) + { + strxmov(buff, opt_basedir, argument, NullS); + argument= buff; + } + fn_format(buff, argument, "", "", 4); + if (!(*++cur_file = my_fopen(buff, O_RDONLY, MYF(MY_WME)))) + die("Could not open %s: errno = %d", argument, errno); + break; + } + case 'p': + if (argument) + { + my_free(pass, MYF(MY_ALLOW_ZERO_PTR)); + pass= my_strdup(argument, MYF(MY_FAE)); + while (*argument) *argument++= 'x'; /* Destroy argument */ + } + else + tty_password= 1; + break; + case 't': + strnmov(TMPDIR, argument, sizeof(TMPDIR)); + break; + case 'A': + if (!embedded_server_arg_count) + { + embedded_server_arg_count=1; + embedded_server_args[0]= (char*) ""; + } + embedded_server_args[embedded_server_arg_count++]= + my_strdup(argument, MYF(MY_FAE)); + if (embedded_server_arg_count == MAX_SERVER_ARGS || + !embedded_server_args[embedded_server_arg_count-1]) + { + die("Can't use server argument"); + } + break; + case 'F': + if (read_server_arguments(argument)) + die(NullS); + break; + case 'V': + print_version(); + exit(0); + case '?': + usage(); + exit(1); + } + return 0; +} + + int parse_args(int argc, char **argv) { - int c, option_index = 0; - my_bool tty_password=0; + int ho_error; load_defaults("my",load_default_groups,&argc,&argv); default_argv= argv; - while ((c = getopt_long(argc, argv, "A:h:p::u:b:BCF:P:D:S:R:x:t:T:#:?rvVs", - long_options, &option_index)) != EOF) - { - switch(c) { - case '#': - DBUG_PUSH(optarg ? optarg : "d:t:S:i:O,/tmp/mysqltest.trace"); - break; - case 'v': - verbose = 1; - break; - case 'r': - record = 1; - break; - case (int)OPT_MANAGER_WAIT_TIMEOUT: - manager_wait_timeout=atoi(optarg); - break; - case (int)OPT_MANAGER_PORT: - manager_port=atoi(optarg); - break; - case (int)OPT_MANAGER_HOST: - manager_host=optarg; - break; - case (int)OPT_MANAGER_USER: - manager_user=optarg; - break; - case (int)OPT_MANAGER_PASSWD: - my_free(manager_pass,MYF(MY_ALLOW_ZERO_PTR)); - manager_pass=my_strdup(optarg,MYF(MY_FAE)); - while (*optarg) *optarg++= 'x'; /* Destroy argument */ - break; - case 'u': - user = optarg; - break; - case 'R': - result_file = optarg; - break; - case 'x': - { - char buff[FN_REFLEN]; - if (!test_if_hard_path(optarg)) - { - strxmov(buff, opt_basedir, optarg, NullS); - optarg=buff; - } - fn_format(buff,optarg,"","",4); - if (!(*++cur_file = my_fopen(buff, O_RDONLY, MYF(MY_WME)))) - die("Could not open %s: errno = %d", optarg, errno); - break; - } - case 'p': - if (optarg) - { - my_free(pass,MYF(MY_ALLOW_ZERO_PTR)); - pass=my_strdup(optarg,MYF(MY_FAE)); - while (*optarg) *optarg++= 'x'; /* Destroy argument */ - } - else - tty_password=1; - break; - case 'b': - opt_basedir= optarg; - break; - case 'B': - opt_big_test=1; - break; - case 'C': - opt_compress=1; - break; - case 'P': - port = atoi(optarg); - break; - case 'S': - unix_sock = optarg; - break; - case 'D': - db = optarg; - break; - case 'h': - host = optarg; - break; - case 's': - silent = 1; - break; - case 't': - strnmov(TMPDIR,optarg,sizeof(TMPDIR)); - break; - case 'T': - opt_sleep=atoi(optarg); - break; - case 'A': - if (!embedded_server_arg_count) - { - embedded_server_arg_count=1; - embedded_server_args[0]= (char*) ""; - } - embedded_server_args[embedded_server_arg_count++]= - my_strdup(optarg,MYF(MY_FAE)); - if (embedded_server_arg_count == MAX_SERVER_ARGS || - !embedded_server_args[embedded_server_arg_count-1]) - { - die("Can't use server argument"); - } - break; - case 'F': - if (read_server_arguments(optarg)) - die(NullS); - break; - case 'V': - print_version(); - exit(0); - case '?': - usage(); - exit(1); /* Unknown option */ - default: - fprintf(stderr,"Unknown option '%c'\n",c); - usage(); - exit(1); - } - } + if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) + exit(ho_error); - argc-=optind; - argv+=optind; if (argc > 1) { usage(); @@ -2361,7 +2329,7 @@ int main(int argc, char** argv) file_stack_end = file_stack + MAX_INCLUDE_DEPTH; cur_file = file_stack; lineno = lineno_stack; - init_dynamic_array(&q_lines, sizeof(struct st_query*), INIT_Q_LINES, + my_init_dynamic_array(&q_lines, sizeof(struct st_query*), INIT_Q_LINES, INIT_Q_LINES); memset(block_stack, 0, sizeof(block_stack)); block_stack_end = block_stack + BLOCK_STACK_DEPTH; @@ -2439,9 +2407,11 @@ int main(int argc, char** argv) case Q_QUERY: case Q_REAP: { - int flags = QUERY_REAP; /* we read the result always regardless - * of the mode for both full query and - * read-result only ( reap) */ + /* + We read the result always regardless of the mode for both full + query and read-result only (reap) + */ + int flags = QUERY_REAP; if (q->type != Q_REAP) /* for a full query, enable the send stage */ flags |= QUERY_SEND; if (q_send_flag) @@ -2468,12 +2438,13 @@ int main(int argc, char** argv) /* fix up query pointer if this is * first iteration for this line */ if (q->query == q->query_buf) q->query += q->first_word_len; - error |= run_query(&cur_con->mysql, q, QUERY_SEND); - /* run query can execute a query partially, depending on the flags - * QUERY_SEND flag without QUERY_REAP tells it to just send the - * query and read the result some time later when reap instruction - * is given on this connection + /* + run_query() can execute a query partially, depending on the flags + QUERY_SEND flag without QUERY_REAP tells it to just send the + query and read the result some time later when reap instruction + is given on this connection. */ + error |= run_query(&cur_con->mysql, q, QUERY_SEND); break; case Q_RESULT: get_file_name(save_file,q); diff --git a/client/thread_test.c b/client/thread_test.c index f7e2a6fd32a..2900ab712e2 100644 --- a/client/thread_test.c +++ b/client/thread_test.c @@ -28,9 +28,9 @@ int main(int argc __attribute__((unused)), char **argv __attribute__((unused))) #include <my_sys.h> #include <my_pthread.h> #include "mysql.h" -#include <getopt.h> +#include <my_getopt.h> -static my_bool version,verbose; +static my_bool version, verbose, tty_password= 0; static uint thread_count,number_of_tests=1000,number_of_threads=2; static pthread_cond_t COND_thread_count; static pthread_mutex_t LOCK_thread_count; @@ -84,23 +84,39 @@ end: } -static struct option long_options[] = +static struct my_option my_long_options[] = { - {"help", no_argument, 0, '?'}, - {"database", required_argument, 0, 'D'}, - {"host", required_argument, 0, 'h'}, - {"password", optional_argument, 0, 'p'}, - {"user", required_argument, 0, 'u'}, - {"version", no_argument, 0, 'V'}, - {"verbose", no_argument, 0, 'v'}, - {"query", required_argument, 0, 'Q'}, - {"port", required_argument, 0, 'P'}, - {"socket", required_argument, 0, 'S'}, - {"test-count",required_argument, 0, 'c'}, - {"thread-count",required_argument, 0, 't'}, - {0, 0, 0, 0} + {"help", '?', "Display this help and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, + 0, 0, 0, 0, 0}, + {"database", 'D', "Database to use", (gptr*) &database, (gptr*) &database, + 0, GET_STR_ALLOC, REQUIRED_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}, + {"user", 'u', "User for login if not current user", (gptr*) &user, + (gptr*) &user, 0, GET_STR_ALLOC, REQUIRED_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}, + {"verbose", 'v', "Write some progress indicators", (gptr*) &verbose, + (gptr*) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"query", 'Q', "Query to execute in each threads", (gptr*) &query, + (gptr*) &query, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"port", 'P', "Port number to use for connection", (gptr*) &tcp_port, + (gptr*) &tcp_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"socket", 'S', "Socket file to use for connection", (gptr*) &unix_socket, + (gptr*) &unix_socket, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"test-count", 'c', "Run test count times (default %d)", + (gptr*) &number_of_tests, (gptr*) &number_of_tests, 0, GET_UINT, + REQUIRED_ARG, 1000, 0, 0, 0, 0, 0}, + {"thread-count", 't', "Number of threads to start", + (gptr*) &number_of_threads, (gptr*) &number_of_threads, 0, GET_UINT, + REQUIRED_ARG, 2, 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[]= { "client",0 }; static void usage() @@ -110,103 +126,55 @@ static void usage() return; puts("This software comes with ABSOLUTELY NO WARRANTY.\n"); printf("Usage: %s [OPTIONS] [database]\n", my_progname); - printf("\n\ - -?, --help Display this help and exit\n\ - -c #, --test-count=# Run test count times (default %d)\n",number_of_tests); - printf("\ - -D, --database=.. Database to use\n\ - -h, --host=... Connect to host\n\ - -p[password], --password[=...]\n\ - Password to use when connecting to server\n\ - If password is not given it's asked from the tty.\n"); - printf("\n\ - -P --port=... Port number to use for connection\n\ - -Q, --query=... Query to execute in each threads\n\ - -S --socket=... Socket file to use for connection\n"); - printf("\ - -t --thread-count=# Number of threads to start (default: %d) \n\ - -u, --user=# User for login if not current user\n\ - -v, --verbose Write some progress indicators\n\ - -V, --version Output version information and exit\n", - number_of_threads); + my_print_help(my_long_options); print_defaults("my",load_default_groups); - + my_print_variables(my_long_options); printf("\nExample usage:\n\n\ %s -Q 'select * from mysql.user' -c %d -t %d\n", my_progname, number_of_tests, number_of_threads); } -static void 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=0,error=0; - bool tty_password=0; - load_defaults("my",load_default_groups,&argc,&argv); - - while ((c=getopt_long(argc,argv, "c:D:h:p::VQ:P:S:t:?I", - long_options, &option_index)) != EOF) - { - switch (c) { - case 'c': - number_of_tests=atoi(optarg); - break; - case 'D': - my_free(database,MYF(MY_ALLOW_ZERO_PTR)); - database=my_strdup(optarg,MYF(MY_WME)); - break; - case 'h': - host = optarg; - break; - case 'Q': /* Allow old 'q' option */ - query= optarg; - break; - case 'p': - if (optarg) - { - my_free(password,MYF(MY_ALLOW_ZERO_PTR)); - password=my_strdup(optarg,MYF(MY_FAE)); - while (*optarg) *optarg++= 'x'; /* Destroy argument */ - } - else - tty_password=1; - break; - case 'u': - my_free(user,MYF(MY_ALLOW_ZERO_PTR)); - user= my_strdup(optarg,MYF(0)); - break; - case 'P': - tcp_port= (unsigned int) atoi(optarg); - break; - case 'S': - my_free(unix_socket,MYF(MY_ALLOW_ZERO_PTR)); - unix_socket= my_strdup(optarg,MYF(0)); - break; - case 't': - number_of_threads=atoi(optarg); - break; - case 'v': - verbose=1; - break; - case 'V': - version=1; - usage(); - exit(0); - break; - default: - fprintf(stderr,"Illegal option character '%c'\n",opterr); - /* Fall through */ - case '?': - case 'I': /* Info */ - error++; - break; + switch (optid) { + case 'p': + if (argument) + { + my_free(password, MYF(MY_ALLOW_ZERO_PTR)); + password= my_strdup(argument, MYF(MY_FAE)); + while (*argument) *argument++= 'x'; /* Destroy argument */ } - } - if (error || argc != optind) - { + else + tty_password= 1; + break; + case 'V': + version= 1; + usage(); + exit(0); + break; + case '?': + case 'I': /* Info */ usage(); exit(1); + break; } + return 0; +} + + +static void get_options(int argc, char **argv) +{ + int ho_error; + + load_defaults("my",load_default_groups,&argc,&argv); + + if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) + exit(ho_error); + free_defaults(argv); if (tty_password) password=get_tty_password(NullS); |