summaryrefslogtreecommitdiff
path: root/client/mysqlshow.c
diff options
context:
space:
mode:
Diffstat (limited to 'client/mysqlshow.c')
-rw-r--r--client/mysqlshow.c276
1 files changed, 130 insertions, 146 deletions
diff --git a/client/mysqlshow.c b/client/mysqlshow.c
index 199318abc2f..0b47e06534f 100644
--- a/client/mysqlshow.c
+++ b/client/mysqlshow.c
@@ -1,35 +1,34 @@
-/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
-
+/* Copyright (C) 2000 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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
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 */
/* Show databases, tables or columns */
-#define SHOW_VERSION "8.3"
+#define SHOW_VERSION "9.4"
-#include <global.h>
+#include "client_priv.h"
#include <my_sys.h>
#include <m_string.h>
-#include "mysql.h"
-#include "mysql_version.h"
-#include "mysqld_error.h"
+#include <mysql.h>
+#include <mysqld_error.h>
#include <signal.h>
#include <stdarg.h>
-#include <getopt.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_status=0;
+static my_bool opt_show_keys=0,opt_compress=0,opt_status=0, tty_password=0;
static uint opt_verbose=0;
static void get_options(int *argc,char ***argv);
@@ -48,11 +47,11 @@ 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;
-#include "sslopt-vars.h"
int main(int argc, char **argv)
{
int error;
+ my_bool first_argument_uses_wildcards=0;
char *wild;
MYSQL mysql;
MY_INIT(argv[0]);
@@ -60,21 +59,37 @@ int main(int argc, char **argv)
get_options(&argc,&argv);
wild=0;
- if (argc && strcont(argv[argc-1],"*?%_"))
+ if (argc)
{
- char *pos;
-
- wild=argv[--argc];
- for (pos=wild ; *pos ; pos++)
- { /* Unix wildcards to sql */
- if (*pos == '*')
- *pos='%';
- else if (*pos == '?')
- *pos='_';
- }
+ char *pos= argv[argc-1], *to;
+ for (to= pos ; *pos ; pos++, to++)
+ {
+ switch (*pos)
+ {
+ case '*':
+ *pos= '%';
+ first_argument_uses_wildcards= 1;
+ break;
+ case '?':
+ *pos= '_';
+ first_argument_uses_wildcards= 1;
+ break;
+ case '%':
+ case '_':
+ first_argument_uses_wildcards= 1;
+ break;
+ case '\\':
+ pos++;
+ default: break;
+ }
+ *to= *pos;
+ }
+ *to= *pos; // just to copy a '\0' if '\\' was used
}
+ if (first_argument_uses_wildcards)
+ wild= argv[--argc];
else if (argc == 3) /* We only want one field */
- wild=argv[--argc];
+ wild= argv[--argc];
if (argc > 2)
{
@@ -87,10 +102,10 @@ int main(int argc, char **argv)
#ifdef HAVE_OPENSSL
if (opt_use_ssl)
mysql_ssl_set(&mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
- opt_ssl_capath);
+ opt_ssl_capath, opt_ssl_cipher);
#endif
if (!(mysql_real_connect(&mysql,host,user,opt_password,
- 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));
@@ -121,32 +136,52 @@ int main(int argc, char **argv)
return 0; /* No compiler warnings */
}
-
-static struct option long_options[] =
+static struct my_option my_long_options[] =
{
- {"character-sets-dir", required_argument, 0, 'c'},
- {"compress", no_argument, 0, 'C'},
- {"debug", optional_argument, 0, '#'},
- {"help", no_argument, 0, '?'},
- {"host", required_argument, 0, 'h'},
- {"status", no_argument, 0, 'i'},
- {"keys", no_argument, 0, 'k'},
- {"password", optional_argument, 0, 'p'},
- {"port", required_argument, 0, 'P'},
+ {"character-sets-dir", 'c', "Directory where character sets are",
+ (gptr*) &charsets_dir, (gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0,
+ 0, 0, 0, 0, 0},
+ {"compress", 'C', "Use compression in server/client protocol",
+ (gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
+ 0, 0, 0},
+ {"debug", '#', "Output debug log. Often this is 'd:t:o,filename'",
+ 0, 0, 0, GET_STR, OPT_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},
+ {"status", 'i', "Shows a lot of extra information about each table.",
+ (gptr*) &opt_status, (gptr*) &opt_status, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
+ 0, 0},
+ {"keys", 'k', "Show keys for table", (gptr*) &opt_show_keys,
+ (gptr*) &opt_show_keys, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"password", 'p',
+ "Password to use when connecting to server. If password is not given it's asked from the tty.",
+ 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
+ {"port", 'P', "Port number to use for connection.", (gptr*) &opt_mysql_port,
+ (gptr*) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0,
+ 0},
#ifdef __WIN__
- {"pipe", no_argument, 0, 'W'},
+ {"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG,
+ NO_ARG, 0, 0, 0, 0, 0, 0},
#endif
- {"socket", required_argument, 0, 'S'},
-#include "sslopt-longopts.h"
+ {"socket", 'S', "Socket file to use for connection.",
+ (gptr*) &opt_mysql_unix_port, (gptr*) &opt_mysql_unix_port, 0, GET_STR,
+ REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+#include <sslopt-longopts.h>
#ifndef DONT_ALLOW_USER_CHANGE
- {"user", required_argument, 0, 'u'},
+ {"user", 'u', "User for login if not current user.", (gptr*) &user,
+ (gptr*) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#endif
- {"verbose", no_argument, 0, 'v'},
- {"version", no_argument, 0, 'V'},
- {0, 0, 0, 0}
+ {"verbose", 'v',
+ "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},
+ {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
-
-
+
+
static void print_version(void)
{
printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,SHOW_VERSION,
@@ -160,33 +195,6 @@ static void usage(void)
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n");
puts("Shows the structure of a mysql database (databases,tables and columns)\n");
printf("Usage: %s [OPTIONS] [database [table [column]]]\n",my_progname);
- printf("\n\
- -#, --debug=... output debug log. Often this is 'd:t:o,filename`\n\
- -?, --help display this help and exit\n\
- -c, --character-sets-dir=...\n\
- Directory where character sets are\n\
- -C, --compress Use compression in server/client protocol\n\
- -h, --host=... connect to host\n\
- -i, --status Shows a lot of extra information about each table\n\
- -k, --keys show keys for table\n\
- -p, --password[=...] password to use when connecting to server\n\
- If password is not given it's asked from the tty.\n");
-#ifdef __WIN__
- puts("-W, --pipe Use named pipes to connect to server");
-#endif
- printf("\
- -P --port=... Port number to use for connection\n\
- -S --socket=... Socket file to use for connection\n");
-#include "sslopt-usage.h"
-#ifndef DONT_ALLOW_USER_CHANGE
- printf("\
- -u, --user=# user for login if not current user\n");
-#endif
- printf("\
- -v, --verbose more verbose output; You can use this multiple times\n\
- to get even more verbose output.\n\
- -V, --version output version information and exit\n");
-
puts("\n\
If last argument contains a shell or SQL wildcard (*,?,% or _) then only\n\
what\'s matched by the wildcard is shown.\n\
@@ -195,85 +203,61 @@ 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");
print_defaults("my",load_default_groups);
+ my_print_help(my_long_options);
+ 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 'v':
+ opt_verbose++;
+ break;
+ case 'p':
+ if (argument)
+ {
+ char *start=argument;
+ my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
+ opt_password=my_strdup(argument,MYF(MY_FAE));
+ while (*argument) *argument++= 'x'; /* Destroy argument */
+ if (*start)
+ start[1]=0; /* Cut length of argument */
+ }
+ else
+ tty_password=1;
+ break;
+ case 'W':
+#ifdef __WIN__
+ opt_mysql_unix_port=MYSQL_NAMEDPIPE;
+#endif
+ break;
+ case '#':
+ DBUG_PUSH(argument ? argument : "d:t:o");
+ break;
+#include <sslopt-case.h>
+ case 'V':
+ print_version();
+ exit(0);
+ break;
+ case '?':
+ case 'I': /* Info */
+ usage();
+ exit(0);
+ }
+ return 0;
}
static void
get_options(int *argc,char ***argv)
{
- int c,option_index;
- my_bool tty_password=0;
+ int ho_error;
- while ((c=getopt_long(*argc,*argv,"c:h:p::u:#::P:S:Ck?vVWi",long_options,
- &option_index)) != EOF)
- {
- switch(c) {
- case 'C':
- opt_compress=1;
- break;
- case 'c':
- charsets_dir= optarg;
- break;
- case 'v':
- opt_verbose++;
- break;
- case 'h':
- host = optarg;
- break;
- case 'i':
- opt_status=1;
- break;
- case 'k':
- opt_show_keys=1;
- break;
- case 'p':
- if (optarg)
- {
- char *start=optarg;
- my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
- opt_password=my_strdup(optarg,MYF(MY_FAE));
- while (*optarg) *optarg++= 'x'; /* Destroy argument */
- if (*start)
- start[1]=0; /* Cut length of argument */
- }
- else
- tty_password=1;
- break;
-#ifndef DONT_ALLOW_USER_CHANGE
- case 'u':
- user=optarg;
- break;
-#endif
- case 'P':
- opt_mysql_port= (unsigned int) atoi(optarg);
- break;
- case 'S':
- opt_mysql_unix_port= optarg;
- break;
- case 'W':
-#ifdef __WIN__
- opt_mysql_unix_port=MYSQL_NAMEDPIPE;
-#endif
- break;
-#include "sslopt-case.h"
- case '#':
- DBUG_PUSH(optarg ? optarg : "d:t:o");
- break;
- case 'V':
- print_version();
- exit(0);
- break;
- default:
- fprintf(stderr,"Illegal option character '%c'\n",opterr);
- /* Fall throught */
- case '?':
- case 'I': /* Info */
- usage();
- exit(0);
- }
- }
- (*argc)-=optind;
- (*argv)+=optind;
+ if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
+ exit(ho_error);
+
if (tty_password)
opt_password=get_tty_password(NullS);
return;
@@ -713,7 +697,7 @@ static void print_res_header(MYSQL_RES *result)
putchar('|');
while ((field = mysql_fetch_field(result)))
{
- printf(" %-*s|",field->max_length+1,field->name);
+ printf(" %-*s|",(int) field->max_length+1,field->name);
}
putchar('\n');
print_res_top(result);