summaryrefslogtreecommitdiff
path: root/client/mysqlshow.c
diff options
context:
space:
mode:
Diffstat (limited to 'client/mysqlshow.c')
-rw-r--r--client/mysqlshow.c121
1 files changed, 67 insertions, 54 deletions
diff --git a/client/mysqlshow.c b/client/mysqlshow.c
index 60d11e3bdec..c97ae1d8f97 100644
--- a/client/mysqlshow.c
+++ b/client/mysqlshow.c
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2000-2006 MySQL AB
+ Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
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
@@ -12,12 +12,12 @@
You should have received a copy of the GNU General Public License
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Show databases, tables or columns */
-#define SHOW_VERSION "9.5"
+#define SHOW_VERSION "9.10"
#include "client_priv.h"
#include <my_sys.h>
@@ -28,9 +28,11 @@
#include <stdarg.h>
#include <sslopt-vars.h>
-static my_string host=0,opt_password=0,user=0;
-static my_bool opt_show_keys= 0, opt_compress= 0, opt_count=0, opt_status= 0,
- tty_password= 0, opt_table_type= 0;
+static char * host=0, *opt_password=0, *user=0;
+static my_bool opt_show_keys= 0, opt_compress= 0, opt_count=0, opt_status= 0;
+static my_bool tty_password= 0, opt_table_type= 0;
+static my_bool debug_info_flag= 0, debug_check_flag= 0;
+static uint my_end_arg= 0;
static uint opt_verbose=0;
static char *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
@@ -54,7 +56,7 @@ static void print_res_top(MYSQL_RES *result);
static void print_res_row(MYSQL_RES *result,MYSQL_ROW cur);
static const char *load_default_groups[]= { "mysqlshow","client",0 };
-static my_string opt_mysql_unix_port=0;
+static char * opt_mysql_unix_port=0;
int main(int argc, char **argv)
{
@@ -122,7 +124,8 @@ int main(int argc, char **argv)
mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, default_charset);
if (!(mysql_real_connect(&mysql,host,user,opt_password,
- (first_argument_uses_wildcards) ? "" : argv[0],opt_mysql_port,opt_mysql_unix_port,
+ (first_argument_uses_wildcards) ? "" :
+ argv[0],opt_mysql_port,opt_mysql_unix_port,
0)))
{
fprintf(stderr,"%s: %s\n",my_progname,mysql_error(&mysql));
@@ -130,8 +133,7 @@ int main(int argc, char **argv)
}
mysql.reconnect= 1;
- switch (argc)
- {
+ switch (argc) {
case 0: error=list_dbs(&mysql,wild); break;
case 1:
if (opt_status)
@@ -152,7 +154,7 @@ int main(int argc, char **argv)
#ifdef HAVE_SMEM
my_free(shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
#endif
- my_end(0);
+ my_end(my_end_arg);
exit(error ? 1 : 0);
return 0; /* No compiler warnings */
}
@@ -160,35 +162,42 @@ int main(int argc, char **argv)
static struct my_option my_long_options[] =
{
#ifdef __NETWARE__
- {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.",
+ {"autoclose", OPT_AUTO_CLOSE, "Automatically close the screen on exit for Netware.",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
#endif
- {"character-sets-dir", 'c', "Directory where character sets are.",
- (gptr*) &charsets_dir, (gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0,
+ {"character-sets-dir", 'c', "Directory for character set files.",
+ &charsets_dir, &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},
+ "Set the default character set.", &default_charset,
+ &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"count", OPT_COUNT,
- "Show number of rows per table (may be slow for not MyISAM tables)",
- (gptr*) &opt_count, (gptr*) &opt_count, 0, GET_BOOL, NO_ARG, 0, 0, 0,
+ "Show number of rows per table (may be slow for non-MyISAM tables).",
+ &opt_count, &opt_count, 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,
+ &opt_compress, &opt_compress, 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},
+ {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
+ &debug_check_flag, &debug_check_flag, 0,
+ GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
+ &debug_info_flag, &debug_info_flag,
+ 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,
+ {"host", 'h', "Connect to host.", &host, &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,
+ &opt_status, &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},
+ {"keys", 'k', "Show keys for table.", &opt_show_keys,
+ &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.",
+ "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},
{"port", 'P', "Port number to use for connection or 0 for default to, in "
"order of preference, my.cnf, $MYSQL_TCP_PORT, "
@@ -196,33 +205,36 @@ static struct my_option my_long_options[] =
"/etc/services, "
#endif
"built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
- (gptr*) &opt_mysql_port,
- (gptr*) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
+ &opt_mysql_port,
+ &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 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},
#endif
- {"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
+ {"protocol", OPT_MYSQL_PROTOCOL,
+ "The protocol to use for connection (tcp, socket, pipe, memory).",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#ifdef HAVE_SMEM
{"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
- "Base name of shared memory.", (gptr*) &shared_memory_base_name, (gptr*) &shared_memory_base_name,
- 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ "Base name of shared memory.", &shared_memory_base_name,
+ &shared_memory_base_name, 0, GET_STR_ALLOC, REQUIRED_ARG,
+ 0, 0, 0, 0, 0, 0},
#endif
{"show-table-type", 't', "Show table type column.",
- (gptr*) &opt_table_type, (gptr*) &opt_table_type, 0, GET_BOOL,
+ &opt_table_type, &opt_table_type, 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,
+ {"socket", 'S', "The socket file to use for connection.",
+ &opt_mysql_unix_port, &opt_mysql_unix_port, 0, GET_STR,
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},
+ {"user", 'u', "User for login if not current user.", &user,
+ &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#endif
{"verbose", 'v',
- "More verbose output; You can use this multiple times to get even more verbose output.",
+ "More verbose output; you can use this multiple times to get even more "
+ "verbose output.",
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},
@@ -243,17 +255,17 @@ static void print_version(void)
static void usage(void)
{
print_version();
- puts("Copyright (C) 2000-2006 MySQL 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("Shows the structure of a mysql database (databases,tables and columns)\n");
+ puts("Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.");
+ 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");
printf("Usage: %s [OPTIONS] [database [table [column]]]\n",my_progname);
puts("\n\
If last argument contains a shell or SQL wildcard (*,?,% or _) then only\n\
what\'s matched by the wildcard is shown.\n\
If no database is given then all matching databases are shown.\n\
-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\
-are shown");
+If no table is given, then all matching tables in database are shown.\n\
+If no column is given, then all matching columns and column types in table\n\
+are shown.");
print_defaults("my",load_default_groups);
my_print_help(my_long_options);
my_print_variables(my_long_options);
@@ -275,6 +287,8 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
opt_verbose++;
break;
case 'p':
+ if (argument == disabled_my_option)
+ argument= (char*) ""; /* Don't require password */
if (argument)
{
char *start=argument;
@@ -294,16 +308,12 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
#endif
break;
case OPT_MYSQL_PROTOCOL:
- {
- if ((opt_protocol= find_type(argument, &sql_protocol_typelib,0)) <= 0)
- {
- fprintf(stderr, "Unknown option to protocol: %s\n", argument);
- exit(1);
- }
+ opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
+ opt->name);
break;
- }
case '#':
DBUG_PUSH(argument ? argument : "d:t:o");
+ debug_check_flag= 1;
break;
#include <sslopt-case.h>
case 'V':
@@ -337,6 +347,10 @@ get_options(int *argc,char ***argv)
*/
opt_verbose= 2;
}
+ if (debug_info_flag)
+ my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
+ if (debug_check_flag)
+ my_end_arg= MY_CHECK_ERROR;
return;
}
@@ -657,8 +671,7 @@ list_fields(MYSQL *mysql,const char *db,const char *table,
char query[1024],*end;
MYSQL_RES *result;
MYSQL_ROW row;
- ulong rows;
- LINT_INIT(rows);
+ ulong UNINIT_VAR(rows);
if (mysql_select_db(mysql,db))
{
@@ -745,7 +758,7 @@ print_header(const char *header,uint head_length,...)
for (i=0 ; i < length+2 ; i++)
putchar('-');
putchar('+');
- if (!(field=va_arg(args,my_string)))
+ if (!(field=va_arg(args,char *)))
break;
length=va_arg(args,uint);
}
@@ -769,7 +782,7 @@ print_header(const char *header,uint head_length,...)
for (i=0 ; i < length ; i++)
putchar(' ');
putchar('|');
- if (!(field=va_arg(args,my_string)))
+ if (!(field=va_arg(args,char *)))
break;
length=va_arg(args,uint);
}
@@ -784,7 +797,7 @@ print_header(const char *header,uint head_length,...)
for (i=0 ; i < length+2 ; i++)
putchar('-');
putchar('+');
- if (!(field=va_arg(args,my_string)))
+ if (!(field=va_arg(args,char *)))
break;
length=va_arg(args,uint);
}
@@ -810,7 +823,7 @@ print_row(const char *header,uint head_length,...)
field_length=(uint) strlen(field);
for (i=field_length ; i <= length ; i++)
putchar(' ');
- if (!(field=va_arg(args,my_string)))
+ if (!(field=va_arg(args,char *)))
break;
length=va_arg(args,uint);
}