~mysql/mysql-server/mysql-5.1

1810.3997.10 by Kent Boortz
Updated/added copyright headers
1
/*
1810.3997.15 by Alexander Nozdrin
For for Bug#12696072: FIX OUTDATED COPYRIGHT NOTICES IN RUNTIME RELATED CLIENT
2
   Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
973.2.1 by monty at mysql
Update copyright
3
2 by bk at mysql
Import changeset
4
   This program is free software; you can redistribute it and/or modify
5
   it under the terms of the GNU General Public License as published by
1810.2403.4 by kent at mysql
Many files:
6
   the Free Software Foundation; version 2 of the License.
973.2.1 by monty at mysql
Update copyright
7
2 by bk at mysql
Import changeset
8
   This program is distributed in the hope that it will be useful,
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
   GNU General Public License for more details.
973.2.1 by monty at mysql
Update copyright
12
2 by bk at mysql
Import changeset
13
   You should have received a copy of the GNU General Public License
14
   along with this program; if not, write to the Free Software
1810.3997.10 by Kent Boortz
Updated/added copyright headers
15
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
16
*/
2 by bk at mysql
Import changeset
17
18
/* mysql command tool
19
 * Commands compatible with mSQL by David J. Hughes
20
 *
21
 * Written by:
22
 *   Michael 'Monty' Widenius
973.124.2 by jani at mysql
merge
23
 *   Andi Gutmans  <andi@zend.com>
24
 *   Zeev Suraski  <zeev@zend.com>
25
 *   Jani Tolonen  <jani@mysql.com>
26
 *   Matt Wagner   <matt@mysql.com>
27
 *   Jeremy Cole   <jcole@mysql.com>
28
 *   Tonu Samuel   <tonu@mysql.com>
1616.159.39 by harrison at lordblink
Fix up history in readline implementation.
29
 *   Harrison Fisk <harrison@mysql.com>
2 by bk at mysql
Import changeset
30
 *
31
 **/
32
676.130.2 by monty at mysql
OS2 patch
33
#include "client_priv.h"
2 by bk at mysql
Import changeset
34
#include <m_ctype.h>
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
35
#include <stdarg.h>
2 by bk at mysql
Import changeset
36
#include <my_dir.h>
37
#ifndef __GNU_LIBRARY__
254.2.1 by jani at mysql
New mysql client.
38
#define __GNU_LIBRARY__		      // Skip warnings in getopt.h
2 by bk at mysql
Import changeset
39
#endif
40
#include "my_readline.h"
41
#include <signal.h>
750 by tonu at x153
OpenSSL changes
42
#include <violite.h>
2 by bk at mysql
Import changeset
43
1504.1.40 by vva at r18
fixed bug with locales in libedit
44
#if defined(USE_LIBEDIT_INTERFACE) && defined(HAVE_LOCALE_H)
45
#include <locale.h>
46
#endif
47
2476.284.5 by monty at mysql
Fixes Bug#30127: --debug-info no longer prints memory usage in mysql
48
const char *VER= "14.14";
289.2.1 by monty at mysql
New thr_alarm struct for better integration with OS2
49
513.4.1 by monty at mysql
Portability fixes
50
/* Don't try to make a nice table if the data is too big */
51
#define MAX_COLUMN_LENGTH	     1024
52
1810.2300.1 by mysqldev at mysql
mysql.cc, log.cc:
53
/* Buffer to hold 'version' and 'version_comment' */
2728.10.6 by Tatiana A. Nurnberg
Bug#43153: Version comment is too long
54
static char *server_version= NULL;
1810.2300.1 by mysqldev at mysql
mysql.cc, log.cc:
55
2476.287.1 by iggy at amd64
Bug#29903 The CMake build method does not produce the embedded library.
56
/* Array of options to pass to libemysqld */
57
#define MAX_SERVER_ARGS               64
58
3329 by Magne Mahre
WL#5154 Remove deprecated 4.1 features
59
/* Version numbers for deprecation messages */
60
#define VER_CELOSIA "5.6"
61
2475.68.2 by monty at mysql
WL#3817: Simplify string / memory area types and make things more consistent (first part)
62
void* sql_alloc(unsigned size);	     // Don't use mysqld alloc for these
2 by bk at mysql
Import changeset
63
void sql_element_free(void *ptr);
64
#include "sql_string.h"
65
66
extern "C" {
67
#if defined(HAVE_CURSES_H) && defined(HAVE_TERM_H)
68
#include <curses.h>
69
#include <term.h>
70
#else
71
#if defined(HAVE_TERMIOS_H)
72
#include <termios.h>
73
#include <unistd.h>
74
#elif defined(HAVE_TERMBITS_H)
75
#include <termbits.h>
76
#elif defined(HAVE_ASM_TERMBITS_H) && (!defined __GLIBC__ || !(__GLIBC__ > 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ > 0))
254.2.1 by jani at mysql
New mysql client.
77
#include <asm/termbits.h>		// Standard linux
2 by bk at mysql
Import changeset
78
#endif
79
#undef VOID
80
#if defined(HAVE_TERMCAP_H)
81
#include <termcap.h>
82
#else
83
#ifdef HAVE_CURSES_H
84
#include <curses.h>
85
#endif
254.2.1 by jani at mysql
New mysql client.
86
#undef SYSV				// hack to avoid syntax error
2 by bk at mysql
Import changeset
87
#ifdef HAVE_TERM_H
88
#include <term.h>
89
#endif
90
#endif
91
#endif
92
3089 by Davi Arnaut
Fix for a few assorted compiler warnings.
93
#if defined(__WIN__)
2 by bk at mysql
Import changeset
94
#include <conio.h>
1346.96.3 by monty at mysql
Fixes for Netware
95
#elif !defined(__NETWARE__)
2 by bk at mysql
Import changeset
96
#include <readline/readline.h>
97
#define HAVE_READLINE
98
#endif
99
  //int vidattr(long unsigned int attrs);	// Was missing in sun curses
100
}
101
102
#if !defined(HAVE_VIDATTR)
103
#undef vidattr
254.2.1 by jani at mysql
New mysql client.
104
#define vidattr(A) {}			// Can't get this to work
2 by bk at mysql
Import changeset
105
#endif
106
1346.96.3 by monty at mysql
Fixes for Netware
107
#ifdef FN_NO_CASE_SENCE
1494.8.12 by root at home
mysqltest.c, mysqlimport.c, mysqldump.c, mysqlcheck.c, mysql.cc:
108
#define cmp_database(cs,A,B) my_strcasecmp((cs), (A), (B))
2 by bk at mysql
Import changeset
109
#else
1494.8.12 by root at home
mysqltest.c, mysqlimport.c, mysqldump.c, mysqlcheck.c, mysql.cc:
110
#define cmp_database(cs,A,B) strcmp((A),(B))
2 by bk at mysql
Import changeset
111
#endif
112
3089 by Davi Arnaut
Fix for a few assorted compiler warnings.
113
#if !defined(__WIN__) && !defined(__NETWARE__) && !defined(THREAD)
1346.96.3 by monty at mysql
Fixes for Netware
114
#define USE_POPEN
115
#endif
116
2 by bk at mysql
Import changeset
117
#include "completion_hash.h"
1810.3997.15 by Alexander Nozdrin
For for Bug#12696072: FIX OUTDATED COPYRIGHT NOTICES IN RUNTIME RELATED CLIENT
118
#include <welcome_copyright_notice.h> // ORACLE_WELCOME_COPYRIGHT_NOTICE
2 by bk at mysql
Import changeset
119
973.124.2 by jani at mysql
merge
120
#define PROMPT_CHAR '\\'
1504.20.16 by jani at hynda
Added --delimiter option to mysql
121
#define DEFAULT_DELIMITER ";"
973.124.2 by jani at mysql
merge
122
1810.3919.1 by Alexey Kopytov
Bug #45236: large blob inserts from mysqldump fail, possible
123
#define MAX_BATCH_BUFFER_SIZE (1024L * 1024L * 1024L)
1810.3863.1 by Alexey Kopytov
Fix for bug#41486: extra character appears in BLOB for every
124
2 by bk at mysql
Import changeset
125
typedef struct st_status
126
{
127
  int exit_status;
128
  ulong query_start_line;
129
  char *file_name;
130
  LINE_BUFFER *line_buff;
131
  bool batch,add_to_history;
132
} STATUS;
133
134
135
static HashTable ht;
1239.1.1 by monty at mysql
Removed wrong mutex lock (hangup in kill on HPUX)
136
static char **defaults_argv;
2 by bk at mysql
Import changeset
137
138
enum enum_info_type { INFO_INFO,INFO_ERROR,INFO_RESULT};
139
typedef enum enum_info_type INFO_TYPE;
140
141
static MYSQL mysql;			/* The connection */
2476.284.5 by monty at mysql
Fixes Bug#30127: --debug-info no longer prints memory usage in mysql
142
static my_bool ignore_errors=0,wait_flag=0,quick=0,
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
143
               connected=0,opt_raw_data=0,unbuffered=0,output_tables=0,
1810.2323.19 by monty at mysql
Fixed compiler warnings detected by option -Wshadow and -Wunused:
144
	       opt_rehash=1,skip_updates=0,safe_updates=0,one_database=0,
973.124.2 by jani at mysql
merge
145
	       opt_compress=0, using_opt_local_infile=0,
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
146
	       vertical=0, line_numbers=1, column_names=1,opt_html=0,
147
               opt_xml=0,opt_nopager=1, opt_outfile=0, named_cmds= 0,
1546.59.8 by monty at mysql
After merge fixes
148
	       tty_password= 0, opt_nobeep=0, opt_reconnect=1,
1616.75.4 by jani at netsonic
- Added missing documentation to some mysql.cc options.
149
	       default_charset_used= 0, opt_secure_auth= 0,
1773.306.1 by geert at kemuri
Adding --show-warnings option for the mysql command line tool so warnings,
150
               default_pager_set= 0, opt_sigint_ignore= 0,
2876 by Jim Winstead
Merge from 5.0-bugteam
151
               show_warnings= 0, executing_query= 0, interrupted_query= 0,
152
               ignore_spaces= 0;
2476.284.5 by monty at mysql
Fixes Bug#30127: --debug-info no longer prints memory usage in mysql
153
static my_bool debug_info_flag, debug_check_flag;
2303.84.1 by monty at mysql
Added --debug-info to most clients to detect memory leaks in mysql-test-run
154
static my_bool column_types_flag;
1810.3428.1 by kaa at polly
Fix for:
155
static my_bool preserve_comments= 0;
1346.564.125 by hf at deer
Fix to make Windows compilation smoother
156
static ulong opt_max_allowed_packet, opt_net_buffer_length;
973.124.2 by jani at mysql
merge
157
static uint verbose=0,opt_silent=0,opt_mysql_port=0, opt_local_infile=0;
2476.284.5 by monty at mysql
Fixes Bug#30127: --debug-info no longer prints memory usage in mysql
158
static uint my_end_arg;
2475.68.2 by monty at mysql
WL#3817: Simplify string / memory area types and make things more consistent (first part)
159
static char * opt_mysql_unix_port=0;
2 by bk at mysql
Import changeset
160
static int connect_flag=CLIENT_INTERACTIVE;
161
static char *current_host,*current_db,*current_user=0,*opt_password=0,
1504.20.16 by jani at hynda
Added --delimiter option to mysql
162
            *current_prompt=0, *delimiter_str= 0,
1538.11.2 by bar at r18
--with-collation argument for configure. Now one can for example use this:
163
            *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME;
2 by bk at mysql
Import changeset
164
static char *histfile;
1700.112.2 by jani at omakaista
Some bug fixes and a feature add to mysql-test-run
165
static char *histfile_tmp;
2 by bk at mysql
Import changeset
166
static String glob_buffer,old_buffer;
973.124.2 by jani at mysql
merge
167
static String processed_prompt;
168
static char *full_username=0,*part_username=0,*default_prompt=0;
474.6.1 by sasha at sashanet
rpl000016.test sync
169
static int wait_time = 5;
2 by bk at mysql
Import changeset
170
static STATUS status;
278.1.3 by monty at mysql
Added connect_timeout and fix for transactions per statement
171
static ulong select_limit,max_join_size,opt_connect_timeout=0;
898 by monty at mysql
Portability fix.
172
static char mysql_charsets_dir[FN_REFLEN+1];
681.2.2 by monty at mysql
Fixes for embedded MySQL
173
static const char *xmlmeta[] = {
669.1.1 by monty at mysql
Added all changes from old 4.0 version:
174
  "&", "&amp;",
175
  "<", "&lt;",
1616.1567.1 by jimw at mysql
Change 'mysql' client to output XML like the 'mysqldump'
176
  ">", "&gt;",
177
  "\"", "&quot;",
2871.15.23 by Jim Winstead
The handling of NUL bytes in column data in the various output formats
178
  /* Turn \0 into a space. Why not &#0;? That's not valid XML or HTML. */
179
  "\0", " ",
669.1.1 by monty at mysql
Added all changes from old 4.0 version:
180
  0, 0
181
};
973.124.2 by jani at mysql
merge
182
static const char *day_names[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
183
static const char *month_names[]={"Jan","Feb","Mar","Apr","May","Jun","Jul",
184
			    "Aug","Sep","Oct","Nov","Dec"};
185
static char default_pager[FN_REFLEN];
186
static char pager[FN_REFLEN], outfile[FN_REFLEN];
187
static FILE *PAGER, *OUTFILE;
188
static MEM_ROOT hash_mem_root;
189
static uint prompt_counter;
1504.20.16 by jani at hynda
Added --delimiter option to mysql
190
static char delimiter[16]= DEFAULT_DELIMITER;
191
static uint delimiter_length= 1;
2 by bk at mysql
Import changeset
192
1354.36.1 by wax at mysql
Add shared memory protocol and option --protocol
193
#ifdef HAVE_SMEM
194
static char *shared_memory_base_name=0;
195
#endif
196
static uint opt_protocol=0;
1494.8.12 by root at home
mysqltest.c, mysqlimport.c, mysqldump.c, mysqlcheck.c, mysql.cc:
197
static CHARSET_INFO *charset_info= &my_charset_latin1;
1616.1489.1 by serg at serg
protect against malicious server trying to crash command-line client :)
198
2 by bk at mysql
Import changeset
199
#include "sslopt-vars.h"
200
201
const char *default_dbug_option="d:t:o,/tmp/mysql.trace";
202
254.2.1 by jani at mysql
New mysql client.
203
void tee_fprintf(FILE *file, const char *fmt, ...);
204
void tee_fputs(const char *s, FILE *file);
205
void tee_puts(const char *s, FILE *file);
261.1.1 by jani at mysql
Added function tee_putc to mysql.cc.
206
void tee_putc(int c, FILE *file);
1810.1535.1 by cmiller at zippy
Bug#18265: mysql client: No longer right-justifies numeric columns
207
static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool);
2 by bk at mysql
Import changeset
208
/* The names of functions that actually do the manipulation. */
209
static int get_options(int argc,char **argv);
2476.285.5 by monty at mysql
Fixed a lot of compiler warnings and errors detected by Forte C++ on Solaris
210
extern "C" my_bool get_one_option(int optid, const struct my_option *opt,
211
                                  char *argument);
2 by bk at mysql
Import changeset
212
static int com_quit(String *str,char*),
213
	   com_go(String *str,char*), com_ego(String *str,char*),
274.1.1 by monty at mysql
Split error message for crashed table to 3 different error messages.
214
	   com_print(String *str,char*),
2 by bk at mysql
Import changeset
215
	   com_help(String *str,char*), com_clear(String *str,char*),
216
	   com_connect(String *str,char*), com_status(String *str,char*),
217
	   com_use(String *str,char*), com_source(String *str, char*),
274.1.1 by monty at mysql
Split error message for crashed table to 3 different error messages.
218
	   com_rehash(String *str, char*), com_tee(String *str, char*),
1810.1342.1 by aelkin at mysql
BUG#16217 forced to introduce a separate mysql client command to adopt its
219
           com_notee(String *str, char*), com_charset(String *str,char*),
1773.306.1 by geert at kemuri
Adding --show-warnings option for the mysql command line tool so warnings,
220
           com_prompt(String *str, char*), com_delimiter(String *str, char*),
221
     com_warnings(String *str, char*), com_nowarnings(String *str, char*);
2 by bk at mysql
Import changeset
222
1346.96.3 by monty at mysql
Fixes for Netware
223
#ifdef USE_POPEN
274.1.1 by monty at mysql
Split error message for crashed table to 3 different error messages.
224
static int com_nopager(String *str, char*), com_pager(String *str, char*),
1346.96.3 by monty at mysql
Fixes for Netware
225
           com_edit(String *str,char*), com_shell(String *str, char *);
274.1.1 by monty at mysql
Split error message for crashed table to 3 different error messages.
226
#endif
227
1810.562.1 by jimw at mysql
Fix 'source' command in mysql client to handle delimiter command
228
static int read_and_execute(bool interactive);
2 by bk at mysql
Import changeset
229
static int sql_connect(char *host,char *database,char *user,char *password,
230
		       uint silent);
1810.2300.1 by mysqldev at mysql
mysql.cc, log.cc:
231
static const char *server_version_string(MYSQL *mysql);
1538.19.1 by monty at mysql
Added SQLSTATE to client/server protocol
232
static int put_info(const char *str,INFO_TYPE info,uint error=0,
233
		    const char *sql_state=0);
234
static int put_error(MYSQL *mysql);
2 by bk at mysql
Import changeset
235
static void safe_put_field(const char *pos,ulong length);
973.11.2 by jani at mysql
Fixed a bug in mysql.cc
236
static void xmlencode_print(const char *src, uint length);
254.2.1 by jani at mysql
New mysql client.
237
static void init_pager();
238
static void end_pager();
1346.96.3 by monty at mysql
Fixes for Netware
239
static void init_tee(const char *);
254.2.1 by jani at mysql
New mysql client.
240
static void end_tee();
973.124.2 by jani at mysql
merge
241
static const char* construct_prompt();
1403.11.7 by jani at inet
Changed get_arg() so that it can be used to fetch more than
242
static char *get_arg(char *line, my_bool get_next_arg);
973.124.2 by jani at mysql
merge
243
static void init_username();
244
static void add_int_to_prompt(int toadd);
2 by bk at mysql
Import changeset
245
246
/* A structure which contains information on the commands this program
247
   can understand. */
248
249
typedef struct {
250
  const char *name;		/* User printable name of the function. */
251
  char cmd_char;		/* msql command character */
252
  int (*func)(String *str,char *); /* Function to call to do the job. */
253
  bool takes_params;		/* Max parameters for command */
254
  const char *doc;		/* Documentation for this function.  */
255
} COMMANDS;
256
257
static COMMANDS commands[] = {
1354.1.25 by vva at genie
add help command on server side
258
  { "?",      '?', com_help,   1, "Synonym for `help'." },
1810.3882.9 by Sergey Glukhov
Bug#41268 Help Text for \c is misleading in client command line interface(addon)
259
  { "clear",  'c', com_clear,  0, "Clear the current input statement."},
23 by jcole at burghcom
Aesthetic changes only.
260
  { "connect",'r', com_connect,1,
254.2.1 by jani at mysql
New mysql client.
261
    "Reconnect to the server. Optional arguments are db and host." },
1616.70.7 by jani at netsonic
Fixed Bug#1472, mysql \h output out of order.
262
  { "delimiter", 'd', com_delimiter,    1,
1810.3830.12 by Georgi Kodinov
Bug #26724: mysql command line client, ignores input to internal cmd after space
263
    "Set statement delimiter." },
1346.96.3 by monty at mysql
Fixes for Netware
264
#ifdef USE_POPEN
254.2.1 by jani at mysql
New mysql client.
265
  { "edit",   'e', com_edit,   0, "Edit command with $EDITOR."},
274.1.1 by monty at mysql
Split error message for crashed table to 3 different error messages.
266
#endif
23 by jcole at burghcom
Aesthetic changes only.
267
  { "ego",    'G', com_ego,    0,
254.2.1 by jani at mysql
New mysql client.
268
    "Send command to mysql server, display result vertically."},
269
  { "exit",   'q', com_quit,   0, "Exit mysql. Same as quit."},
270
  { "go",     'g', com_go,     0, "Send command to mysql server." },
1616.70.7 by jani at netsonic
Fixed Bug#1472, mysql \h output out of order.
271
  { "help",   'h', com_help,   1, "Display this help." },
1346.96.3 by monty at mysql
Fixes for Netware
272
#ifdef USE_POPEN
254.2.1 by jani at mysql
New mysql client.
273
  { "nopager",'n', com_nopager,0, "Disable pager, print to stdout." },
274
#endif
275
  { "notee",  't', com_notee,  0, "Don't write into outfile." },
1346.96.3 by monty at mysql
Fixes for Netware
276
#ifdef USE_POPEN
254.2.1 by jani at mysql
New mysql client.
277
  { "pager",  'P', com_pager,  1, 
278
    "Set PAGER [to_pager]. Print the query results via PAGER." },
279
#endif
280
  { "print",  'p', com_print,  0, "Print current command." },
973.124.2 by jani at mysql
merge
281
  { "prompt", 'R', com_prompt, 1, "Change your mysql prompt."},
254.2.1 by jani at mysql
New mysql client.
282
  { "quit",   'q', com_quit,   0, "Quit mysql." },
283
  { "rehash", '#', com_rehash, 0, "Rebuild completion hash." },
2 by bk at mysql
Import changeset
284
  { "source", '.', com_source, 1,
1616.2441.1 by paul at snake
mysql.cc:
285
    "Execute an SQL script file. Takes a file name as an argument."},
254.2.1 by jani at mysql
New mysql client.
286
  { "status", 's', com_status, 0, "Get status information from the server."},
1346.96.3 by monty at mysql
Fixes for Netware
287
#ifdef USE_POPEN
891.1.8 by jani at mysql
Added internal command \! to mysql client which can be used
288
  { "system", '!', com_shell,  1, "Execute a system shell command."},
289
#endif
254.2.1 by jani at mysql
New mysql client.
290
  { "tee",    'T', com_tee,    1, 
291
    "Set outfile [to_outfile]. Append everything into given outfile." },
23 by jcole at burghcom
Aesthetic changes only.
292
  { "use",    'u', com_use,    1,
254.2.1 by jani at mysql
New mysql client.
293
    "Use another database. Takes database name as argument." },
1810.1342.1 by aelkin at mysql
BUG#16217 forced to introduce a separate mysql client command to adopt its
294
  { "charset",    'C', com_charset,    1,
295
    "Switch to another charset. Might be needed for processing binlog with multi-byte charsets." },
1773.310.3 by geert at kemuri
\W enables show warnings, \w disables; Showing message while interactive when using the \w and \W commands; using strmov instead of my_strdup; removed case for options, my_getopt does it
296
  { "warnings", 'W', com_warnings,  0,
1773.306.1 by geert at kemuri
Adding --show-warnings option for the mysql command line tool so warnings,
297
    "Show warnings after every statement." },
1773.310.3 by geert at kemuri
\W enables show warnings, \w disables; Showing message while interactive when using the \w and \W commands; using strmov instead of my_strdup; removed case for options, my_getopt does it
298
  { "nowarning", 'w', com_nowarnings, 0,
1773.306.1 by geert at kemuri
Adding --show-warnings option for the mysql command line tool so warnings,
299
    "Don't show warnings after every statement." },
254.2.1 by jani at mysql
New mysql client.
300
  /* Get bash-like expansion for some commands */
23 by jcole at burghcom
Aesthetic changes only.
301
  { "create table",     0, 0, 0, ""},
302
  { "create database",  0, 0, 0, ""},
303
  { "show databases",   0, 0, 0, ""},
304
  { "show fields from", 0, 0, 0, ""},
305
  { "show keys from",   0, 0, 0, ""},
306
  { "show tables",      0, 0, 0, ""},
307
  { "load data from",   0, 0, 0, ""},
308
  { "alter table",      0, 0, 0, ""},
309
  { "set option",       0, 0, 0, ""},
310
  { "lock tables",      0, 0, 0, ""},
311
  { "unlock tables",    0, 0, 0, ""},
1810.3569.12 by cmiller at cornsilk
Bug#24624: MySQL client ignores its own completion table
312
  /* generated 2006-12-28.  Refresh occasionally from lexer. */
313
  { "ACTION", 0, 0, 0, ""},
314
  { "ADD", 0, 0, 0, ""},
315
  { "AFTER", 0, 0, 0, ""},
316
  { "AGAINST", 0, 0, 0, ""},
317
  { "AGGREGATE", 0, 0, 0, ""},
318
  { "ALL", 0, 0, 0, ""},
319
  { "ALGORITHM", 0, 0, 0, ""},
320
  { "ALTER", 0, 0, 0, ""},
321
  { "ANALYZE", 0, 0, 0, ""},
322
  { "AND", 0, 0, 0, ""},
323
  { "ANY", 0, 0, 0, ""},
324
  { "AS", 0, 0, 0, ""},
325
  { "ASC", 0, 0, 0, ""},
326
  { "ASCII", 0, 0, 0, ""},
327
  { "ASENSITIVE", 0, 0, 0, ""},
328
  { "AUTO_INCREMENT", 0, 0, 0, ""},
329
  { "AVG", 0, 0, 0, ""},
330
  { "AVG_ROW_LENGTH", 0, 0, 0, ""},
331
  { "BACKUP", 0, 0, 0, ""},
332
  { "BDB", 0, 0, 0, ""},
333
  { "BEFORE", 0, 0, 0, ""},
334
  { "BEGIN", 0, 0, 0, ""},
335
  { "BERKELEYDB", 0, 0, 0, ""},
336
  { "BETWEEN", 0, 0, 0, ""},
337
  { "BIGINT", 0, 0, 0, ""},
338
  { "BINARY", 0, 0, 0, ""},
339
  { "BINLOG", 0, 0, 0, ""},
340
  { "BIT", 0, 0, 0, ""},
341
  { "BLOB", 0, 0, 0, ""},
342
  { "BOOL", 0, 0, 0, ""},
343
  { "BOOLEAN", 0, 0, 0, ""},
344
  { "BOTH", 0, 0, 0, ""},
345
  { "BTREE", 0, 0, 0, ""},
346
  { "BY", 0, 0, 0, ""},
347
  { "BYTE", 0, 0, 0, ""},
348
  { "CACHE", 0, 0, 0, ""},
349
  { "CALL", 0, 0, 0, ""},
350
  { "CASCADE", 0, 0, 0, ""},
351
  { "CASCADED", 0, 0, 0, ""},
352
  { "CASE", 0, 0, 0, ""},
353
  { "CHAIN", 0, 0, 0, ""},
354
  { "CHANGE", 0, 0, 0, ""},
355
  { "CHANGED", 0, 0, 0, ""},
356
  { "CHAR", 0, 0, 0, ""},
357
  { "CHARACTER", 0, 0, 0, ""},
358
  { "CHARSET", 0, 0, 0, ""},
359
  { "CHECK", 0, 0, 0, ""},
360
  { "CHECKSUM", 0, 0, 0, ""},
361
  { "CIPHER", 0, 0, 0, ""},
362
  { "CLIENT", 0, 0, 0, ""},
363
  { "CLOSE", 0, 0, 0, ""},
364
  { "CODE", 0, 0, 0, ""},
365
  { "COLLATE", 0, 0, 0, ""},
366
  { "COLLATION", 0, 0, 0, ""},
367
  { "COLUMN", 0, 0, 0, ""},
368
  { "COLUMNS", 0, 0, 0, ""},
369
  { "COMMENT", 0, 0, 0, ""},
370
  { "COMMIT", 0, 0, 0, ""},
371
  { "COMMITTED", 0, 0, 0, ""},
372
  { "COMPACT", 0, 0, 0, ""},
373
  { "COMPRESSED", 0, 0, 0, ""},
374
  { "CONCURRENT", 0, 0, 0, ""},
375
  { "CONDITION", 0, 0, 0, ""},
376
  { "CONNECTION", 0, 0, 0, ""},
377
  { "CONSISTENT", 0, 0, 0, ""},
378
  { "CONSTRAINT", 0, 0, 0, ""},
379
  { "CONTAINS", 0, 0, 0, ""},
380
  { "CONTINUE", 0, 0, 0, ""},
381
  { "CONVERT", 0, 0, 0, ""},
382
  { "CREATE", 0, 0, 0, ""},
383
  { "CROSS", 0, 0, 0, ""},
384
  { "CUBE", 0, 0, 0, ""},
385
  { "CURRENT_DATE", 0, 0, 0, ""},
386
  { "CURRENT_TIME", 0, 0, 0, ""},
387
  { "CURRENT_TIMESTAMP", 0, 0, 0, ""},
388
  { "CURRENT_USER", 0, 0, 0, ""},
389
  { "CURSOR", 0, 0, 0, ""},
390
  { "DATA", 0, 0, 0, ""},
391
  { "DATABASE", 0, 0, 0, ""},
392
  { "DATABASES", 0, 0, 0, ""},
393
  { "DATE", 0, 0, 0, ""},
394
  { "DATETIME", 0, 0, 0, ""},
395
  { "DAY", 0, 0, 0, ""},
396
  { "DAY_HOUR", 0, 0, 0, ""},
397
  { "DAY_MICROSECOND", 0, 0, 0, ""},
398
  { "DAY_MINUTE", 0, 0, 0, ""},
399
  { "DAY_SECOND", 0, 0, 0, ""},
400
  { "DEALLOCATE", 0, 0, 0, ""},     
401
  { "DEC", 0, 0, 0, ""},
402
  { "DECIMAL", 0, 0, 0, ""},
403
  { "DECLARE", 0, 0, 0, ""},
404
  { "DEFAULT", 0, 0, 0, ""},
405
  { "DEFINER", 0, 0, 0, ""},
406
  { "DELAYED", 0, 0, 0, ""},
407
  { "DELAY_KEY_WRITE", 0, 0, 0, ""},
408
  { "DELETE", 0, 0, 0, ""},
409
  { "DESC", 0, 0, 0, ""},
410
  { "DESCRIBE", 0, 0, 0, ""},
411
  { "DES_KEY_FILE", 0, 0, 0, ""},
412
  { "DETERMINISTIC", 0, 0, 0, ""},
413
  { "DIRECTORY", 0, 0, 0, ""},
414
  { "DISABLE", 0, 0, 0, ""},
415
  { "DISCARD", 0, 0, 0, ""},
416
  { "DISTINCT", 0, 0, 0, ""},
417
  { "DISTINCTROW", 0, 0, 0, ""},
418
  { "DIV", 0, 0, 0, ""},
419
  { "DO", 0, 0, 0, ""},
420
  { "DOUBLE", 0, 0, 0, ""},
421
  { "DROP", 0, 0, 0, ""},
422
  { "DUAL", 0, 0, 0, ""},
423
  { "DUMPFILE", 0, 0, 0, ""},
424
  { "DUPLICATE", 0, 0, 0, ""},
425
  { "DYNAMIC", 0, 0, 0, ""},
426
  { "EACH", 0, 0, 0, ""},
427
  { "ELSE", 0, 0, 0, ""},
428
  { "ELSEIF", 0, 0, 0, ""},
429
  { "ENABLE", 0, 0, 0, ""},
430
  { "ENCLOSED", 0, 0, 0, ""},
431
  { "END", 0, 0, 0, ""},
432
  { "ENGINE", 0, 0, 0, ""},
433
  { "ENGINES", 0, 0, 0, ""},
434
  { "ENUM", 0, 0, 0, ""},
435
  { "ERRORS", 0, 0, 0, ""},
436
  { "ESCAPE", 0, 0, 0, ""},
437
  { "ESCAPED", 0, 0, 0, ""},
438
  { "EVENTS", 0, 0, 0, ""},
439
  { "EXECUTE", 0, 0, 0, ""},
440
  { "EXISTS", 0, 0, 0, ""},
441
  { "EXIT", 0, 0, 0, ""},
442
  { "EXPANSION", 0, 0, 0, ""},
443
  { "EXPLAIN", 0, 0, 0, ""},
444
  { "EXTENDED", 0, 0, 0, ""},
445
  { "FALSE", 0, 0, 0, ""},
446
  { "FAST", 0, 0, 0, ""},
447
  { "FETCH", 0, 0, 0, ""},
448
  { "FIELDS", 0, 0, 0, ""},
449
  { "FILE", 0, 0, 0, ""},
450
  { "FIRST", 0, 0, 0, ""},
451
  { "FIXED", 0, 0, 0, ""},
452
  { "FLOAT", 0, 0, 0, ""},
453
  { "FLOAT4", 0, 0, 0, ""},
454
  { "FLOAT8", 0, 0, 0, ""},
455
  { "FLUSH", 0, 0, 0, ""},
456
  { "FOR", 0, 0, 0, ""},
457
  { "FORCE", 0, 0, 0, ""},
458
  { "FOREIGN", 0, 0, 0, ""},
459
  { "FOUND", 0, 0, 0, ""},
460
  { "FRAC_SECOND", 0, 0, 0, ""},
461
  { "FROM", 0, 0, 0, ""},
462
  { "FULL", 0, 0, 0, ""},
463
  { "FULLTEXT", 0, 0, 0, ""},
464
  { "FUNCTION", 0, 0, 0, ""},
465
  { "GEOMETRY", 0, 0, 0, ""},
466
  { "GEOMETRYCOLLECTION", 0, 0, 0, ""},
467
  { "GET_FORMAT", 0, 0, 0, ""},
468
  { "GLOBAL", 0, 0, 0, ""},
469
  { "GRANT", 0, 0, 0, ""},
470
  { "GRANTS", 0, 0, 0, ""},
471
  { "GROUP", 0, 0, 0, ""},
472
  { "HANDLER", 0, 0, 0, ""},
473
  { "HASH", 0, 0, 0, ""},
474
  { "HAVING", 0, 0, 0, ""},
475
  { "HELP", 0, 0, 0, ""},
476
  { "HIGH_PRIORITY", 0, 0, 0, ""},
477
  { "HOSTS", 0, 0, 0, ""},
478
  { "HOUR", 0, 0, 0, ""},
479
  { "HOUR_MICROSECOND", 0, 0, 0, ""},
480
  { "HOUR_MINUTE", 0, 0, 0, ""},
481
  { "HOUR_SECOND", 0, 0, 0, ""},
482
  { "IDENTIFIED", 0, 0, 0, ""},
483
  { "IF", 0, 0, 0, ""},
484
  { "IGNORE", 0, 0, 0, ""},
485
  { "IMPORT", 0, 0, 0, ""},
486
  { "IN", 0, 0, 0, ""},
487
  { "INDEX", 0, 0, 0, ""},
488
  { "INDEXES", 0, 0, 0, ""},
489
  { "INFILE", 0, 0, 0, ""},
490
  { "INNER", 0, 0, 0, ""},
491
  { "INNOBASE", 0, 0, 0, ""},
492
  { "INNODB", 0, 0, 0, ""},
493
  { "INOUT", 0, 0, 0, ""},
494
  { "INSENSITIVE", 0, 0, 0, ""},
495
  { "INSERT", 0, 0, 0, ""},
496
  { "INSERT_METHOD", 0, 0, 0, ""},
497
  { "INT", 0, 0, 0, ""},
498
  { "INT1", 0, 0, 0, ""},
499
  { "INT2", 0, 0, 0, ""},
500
  { "INT3", 0, 0, 0, ""},
501
  { "INT4", 0, 0, 0, ""},
502
  { "INT8", 0, 0, 0, ""},
503
  { "INTEGER", 0, 0, 0, ""},
504
  { "INTERVAL", 0, 0, 0, ""},
505
  { "INTO", 0, 0, 0, ""},
506
  { "IO_THREAD", 0, 0, 0, ""},
507
  { "IS", 0, 0, 0, ""},
508
  { "ISOLATION", 0, 0, 0, ""},
509
  { "ISSUER", 0, 0, 0, ""},
510
  { "ITERATE", 0, 0, 0, ""},
511
  { "INVOKER", 0, 0, 0, ""},
512
  { "JOIN", 0, 0, 0, ""},
513
  { "KEY", 0, 0, 0, ""},
514
  { "KEYS", 0, 0, 0, ""},
515
  { "KILL", 0, 0, 0, ""},
516
  { "LANGUAGE", 0, 0, 0, ""},
517
  { "LAST", 0, 0, 0, ""},
518
  { "LEADING", 0, 0, 0, ""},
519
  { "LEAVE", 0, 0, 0, ""},
520
  { "LEAVES", 0, 0, 0, ""},
521
  { "LEFT", 0, 0, 0, ""},
522
  { "LEVEL", 0, 0, 0, ""},
523
  { "LIKE", 0, 0, 0, ""},
524
  { "LIMIT", 0, 0, 0, ""},
525
  { "LINES", 0, 0, 0, ""},
526
  { "LINESTRING", 0, 0, 0, ""},
527
  { "LOAD", 0, 0, 0, ""},
528
  { "LOCAL", 0, 0, 0, ""},
529
  { "LOCALTIME", 0, 0, 0, ""},
530
  { "LOCALTIMESTAMP", 0, 0, 0, ""},
531
  { "LOCK", 0, 0, 0, ""},
532
  { "LOCKS", 0, 0, 0, ""},
533
  { "LOGS", 0, 0, 0, ""},
534
  { "LONG", 0, 0, 0, ""},
535
  { "LONGBLOB", 0, 0, 0, ""},
536
  { "LONGTEXT", 0, 0, 0, ""},
537
  { "LOOP", 0, 0, 0, ""},
538
  { "LOW_PRIORITY", 0, 0, 0, ""},
539
  { "MASTER", 0, 0, 0, ""},
540
  { "MASTER_CONNECT_RETRY", 0, 0, 0, ""},
541
  { "MASTER_HOST", 0, 0, 0, ""},
542
  { "MASTER_LOG_FILE", 0, 0, 0, ""},
543
  { "MASTER_LOG_POS", 0, 0, 0, ""},
544
  { "MASTER_PASSWORD", 0, 0, 0, ""},
545
  { "MASTER_PORT", 0, 0, 0, ""},
546
  { "MASTER_SERVER_ID", 0, 0, 0, ""},
547
  { "MASTER_SSL", 0, 0, 0, ""},
548
  { "MASTER_SSL_CA", 0, 0, 0, ""},
549
  { "MASTER_SSL_CAPATH", 0, 0, 0, ""},
550
  { "MASTER_SSL_CERT", 0, 0, 0, ""},
551
  { "MASTER_SSL_CIPHER", 0, 0, 0, ""},
552
  { "MASTER_SSL_KEY", 0, 0, 0, ""},
553
  { "MASTER_USER", 0, 0, 0, ""},
554
  { "MATCH", 0, 0, 0, ""},
555
  { "MAX_CONNECTIONS_PER_HOUR", 0, 0, 0, ""},
556
  { "MAX_QUERIES_PER_HOUR", 0, 0, 0, ""},
557
  { "MAX_ROWS", 0, 0, 0, ""},
558
  { "MAX_UPDATES_PER_HOUR", 0, 0, 0, ""},
559
  { "MAX_USER_CONNECTIONS", 0, 0, 0, ""},
560
  { "MEDIUM", 0, 0, 0, ""},
561
  { "MEDIUMBLOB", 0, 0, 0, ""},
562
  { "MEDIUMINT", 0, 0, 0, ""},
563
  { "MEDIUMTEXT", 0, 0, 0, ""},
564
  { "MERGE", 0, 0, 0, ""},
565
  { "MICROSECOND", 0, 0, 0, ""},
566
  { "MIDDLEINT", 0, 0, 0, ""},
567
  { "MIGRATE", 0, 0, 0, ""},
568
  { "MINUTE", 0, 0, 0, ""},
569
  { "MINUTE_MICROSECOND", 0, 0, 0, ""},
570
  { "MINUTE_SECOND", 0, 0, 0, ""},
571
  { "MIN_ROWS", 0, 0, 0, ""},
572
  { "MOD", 0, 0, 0, ""},
573
  { "MODE", 0, 0, 0, ""},
574
  { "MODIFIES", 0, 0, 0, ""},
575
  { "MODIFY", 0, 0, 0, ""},
576
  { "MONTH", 0, 0, 0, ""},
577
  { "MULTILINESTRING", 0, 0, 0, ""},
578
  { "MULTIPOINT", 0, 0, 0, ""},
579
  { "MULTIPOLYGON", 0, 0, 0, ""},
580
  { "MUTEX", 0, 0, 0, ""},
581
  { "NAME", 0, 0, 0, ""},
582
  { "NAMES", 0, 0, 0, ""},
583
  { "NATIONAL", 0, 0, 0, ""},
584
  { "NATURAL", 0, 0, 0, ""},
585
  { "NDB", 0, 0, 0, ""},
586
  { "NDBCLUSTER", 0, 0, 0, ""},
587
  { "NCHAR", 0, 0, 0, ""},
588
  { "NEW", 0, 0, 0, ""},
589
  { "NEXT", 0, 0, 0, ""},
590
  { "NO", 0, 0, 0, ""},
591
  { "NONE", 0, 0, 0, ""},
592
  { "NOT", 0, 0, 0, ""},
593
  { "NO_WRITE_TO_BINLOG", 0, 0, 0, ""},
594
  { "NULL", 0, 0, 0, ""},
595
  { "NUMERIC", 0, 0, 0, ""},
596
  { "NVARCHAR", 0, 0, 0, ""},
597
  { "OFFSET", 0, 0, 0, ""},
598
  { "OLD_PASSWORD", 0, 0, 0, ""},
599
  { "ON", 0, 0, 0, ""},
600
  { "ONE", 0, 0, 0, ""},
601
  { "ONE_SHOT", 0, 0, 0, ""},
602
  { "OPEN", 0, 0, 0, ""},
603
  { "OPTIMIZE", 0, 0, 0, ""},
604
  { "OPTION", 0, 0, 0, ""},
605
  { "OPTIONALLY", 0, 0, 0, ""},
606
  { "OR", 0, 0, 0, ""},
607
  { "ORDER", 0, 0, 0, ""},
608
  { "OUT", 0, 0, 0, ""},
609
  { "OUTER", 0, 0, 0, ""},
610
  { "OUTFILE", 0, 0, 0, ""},
611
  { "PACK_KEYS", 0, 0, 0, ""},
612
  { "PARTIAL", 0, 0, 0, ""},
613
  { "PASSWORD", 0, 0, 0, ""},
614
  { "PHASE", 0, 0, 0, ""},
615
  { "POINT", 0, 0, 0, ""},
616
  { "POLYGON", 0, 0, 0, ""},
617
  { "PRECISION", 0, 0, 0, ""},
618
  { "PREPARE", 0, 0, 0, ""},
619
  { "PREV", 0, 0, 0, ""},
620
  { "PRIMARY", 0, 0, 0, ""},
621
  { "PRIVILEGES", 0, 0, 0, ""},
622
  { "PROCEDURE", 0, 0, 0, ""},
623
  { "PROCESS", 0, 0, 0, ""},
624
  { "PROCESSLIST", 0, 0, 0, ""},
625
  { "PURGE", 0, 0, 0, ""},
626
  { "QUARTER", 0, 0, 0, ""},
627
  { "QUERY", 0, 0, 0, ""},
628
  { "QUICK", 0, 0, 0, ""},
629
  { "RAID0", 0, 0, 0, ""},
630
  { "RAID_CHUNKS", 0, 0, 0, ""},
631
  { "RAID_CHUNKSIZE", 0, 0, 0, ""},
632
  { "RAID_TYPE", 0, 0, 0, ""},
633
  { "READ", 0, 0, 0, ""},
634
  { "READS", 0, 0, 0, ""},
635
  { "REAL", 0, 0, 0, ""},
636
  { "RECOVER", 0, 0, 0, ""},
637
  { "REDUNDANT", 0, 0, 0, ""},
638
  { "REFERENCES", 0, 0, 0, ""},
639
  { "REGEXP", 0, 0, 0, ""},
640
  { "RELAY_LOG_FILE", 0, 0, 0, ""},
641
  { "RELAY_LOG_POS", 0, 0, 0, ""},
642
  { "RELAY_THREAD", 0, 0, 0, ""},
643
  { "RELEASE", 0, 0, 0, ""},
644
  { "RELOAD", 0, 0, 0, ""},
645
  { "RENAME", 0, 0, 0, ""},
646
  { "REPAIR", 0, 0, 0, ""},
647
  { "REPEATABLE", 0, 0, 0, ""},
648
  { "REPLACE", 0, 0, 0, ""},
649
  { "REPLICATION", 0, 0, 0, ""},
650
  { "REPEAT", 0, 0, 0, ""},
651
  { "REQUIRE", 0, 0, 0, ""},
652
  { "RESET", 0, 0, 0, ""},
653
  { "RESTORE", 0, 0, 0, ""},
654
  { "RESTRICT", 0, 0, 0, ""},
655
  { "RESUME", 0, 0, 0, ""},
656
  { "RETURN", 0, 0, 0, ""},
657
  { "RETURNS", 0, 0, 0, ""},
658
  { "REVOKE", 0, 0, 0, ""},
659
  { "RIGHT", 0, 0, 0, ""},
660
  { "RLIKE", 0, 0, 0, ""},
661
  { "ROLLBACK", 0, 0, 0, ""},
662
  { "ROLLUP", 0, 0, 0, ""},
663
  { "ROUTINE", 0, 0, 0, ""},
664
  { "ROW", 0, 0, 0, ""},
665
  { "ROWS", 0, 0, 0, ""},
666
  { "ROW_FORMAT", 0, 0, 0, ""},
667
  { "RTREE", 0, 0, 0, ""},
668
  { "SAVEPOINT", 0, 0, 0, ""},
669
  { "SCHEMA", 0, 0, 0, ""},
670
  { "SCHEMAS", 0, 0, 0, ""},
671
  { "SECOND", 0, 0, 0, ""},
672
  { "SECOND_MICROSECOND", 0, 0, 0, ""},
673
  { "SECURITY", 0, 0, 0, ""},
674
  { "SELECT", 0, 0, 0, ""},
675
  { "SENSITIVE", 0, 0, 0, ""},
676
  { "SEPARATOR", 0, 0, 0, ""},
677
  { "SERIAL", 0, 0, 0, ""},
678
  { "SERIALIZABLE", 0, 0, 0, ""},
679
  { "SESSION", 0, 0, 0, ""},
680
  { "SET", 0, 0, 0, ""},
681
  { "SHARE", 0, 0, 0, ""},
682
  { "SHOW", 0, 0, 0, ""},
683
  { "SHUTDOWN", 0, 0, 0, ""},
684
  { "SIGNED", 0, 0, 0, ""},
685
  { "SIMPLE", 0, 0, 0, ""},
686
  { "SLAVE", 0, 0, 0, ""},
687
  { "SNAPSHOT", 0, 0, 0, ""},
688
  { "SMALLINT", 0, 0, 0, ""},
689
  { "SOME", 0, 0, 0, ""},
690
  { "SONAME", 0, 0, 0, ""},
691
  { "SOUNDS", 0, 0, 0, ""},
692
  { "SPATIAL", 0, 0, 0, ""},
693
  { "SPECIFIC", 0, 0, 0, ""},
694
  { "SQL", 0, 0, 0, ""},
695
  { "SQLEXCEPTION", 0, 0, 0, ""},
696
  { "SQLSTATE", 0, 0, 0, ""},
697
  { "SQLWARNING", 0, 0, 0, ""},
698
  { "SQL_BIG_RESULT", 0, 0, 0, ""},
699
  { "SQL_BUFFER_RESULT", 0, 0, 0, ""},
700
  { "SQL_CACHE", 0, 0, 0, ""},
701
  { "SQL_CALC_FOUND_ROWS", 0, 0, 0, ""},
702
  { "SQL_NO_CACHE", 0, 0, 0, ""},
703
  { "SQL_SMALL_RESULT", 0, 0, 0, ""},
704
  { "SQL_THREAD", 0, 0, 0, ""},
705
  { "SQL_TSI_FRAC_SECOND", 0, 0, 0, ""},
706
  { "SQL_TSI_SECOND", 0, 0, 0, ""},
707
  { "SQL_TSI_MINUTE", 0, 0, 0, ""},
708
  { "SQL_TSI_HOUR", 0, 0, 0, ""},
709
  { "SQL_TSI_DAY", 0, 0, 0, ""},
710
  { "SQL_TSI_WEEK", 0, 0, 0, ""},
711
  { "SQL_TSI_MONTH", 0, 0, 0, ""},
712
  { "SQL_TSI_QUARTER", 0, 0, 0, ""},
713
  { "SQL_TSI_YEAR", 0, 0, 0, ""},
714
  { "SSL", 0, 0, 0, ""},
715
  { "START", 0, 0, 0, ""},
716
  { "STARTING", 0, 0, 0, ""},
717
  { "STATUS", 0, 0, 0, ""},
718
  { "STOP", 0, 0, 0, ""},
719
  { "STORAGE", 0, 0, 0, ""},
720
  { "STRAIGHT_JOIN", 0, 0, 0, ""},
721
  { "STRING", 0, 0, 0, ""},
722
  { "STRIPED", 0, 0, 0, ""},
723
  { "SUBJECT", 0, 0, 0, ""},
724
  { "SUPER", 0, 0, 0, ""},
725
  { "SUSPEND", 0, 0, 0, ""},
726
  { "TABLE", 0, 0, 0, ""},
727
  { "TABLES", 0, 0, 0, ""},
728
  { "TABLESPACE", 0, 0, 0, ""},
729
  { "TEMPORARY", 0, 0, 0, ""},
730
  { "TEMPTABLE", 0, 0, 0, ""},
731
  { "TERMINATED", 0, 0, 0, ""},
732
  { "TEXT", 0, 0, 0, ""},
733
  { "THEN", 0, 0, 0, ""},
734
  { "TIME", 0, 0, 0, ""},
735
  { "TIMESTAMP", 0, 0, 0, ""},
736
  { "TIMESTAMPADD", 0, 0, 0, ""},
737
  { "TIMESTAMPDIFF", 0, 0, 0, ""},
738
  { "TINYBLOB", 0, 0, 0, ""},
739
  { "TINYINT", 0, 0, 0, ""},
740
  { "TINYTEXT", 0, 0, 0, ""},
741
  { "TO", 0, 0, 0, ""},
742
  { "TRAILING", 0, 0, 0, ""},
743
  { "TRANSACTION", 0, 0, 0, ""},
744
  { "TRIGGER", 0, 0, 0, ""},
745
  { "TRIGGERS", 0, 0, 0, ""},
746
  { "TRUE", 0, 0, 0, ""},
747
  { "TRUNCATE", 0, 0, 0, ""},
748
  { "TYPE", 0, 0, 0, ""},
749
  { "TYPES", 0, 0, 0, ""},
750
  { "UNCOMMITTED", 0, 0, 0, ""},
751
  { "UNDEFINED", 0, 0, 0, ""},
752
  { "UNDO", 0, 0, 0, ""},
753
  { "UNICODE", 0, 0, 0, ""},
754
  { "UNION", 0, 0, 0, ""},
755
  { "UNIQUE", 0, 0, 0, ""},
756
  { "UNKNOWN", 0, 0, 0, ""},
757
  { "UNLOCK", 0, 0, 0, ""},
758
  { "UNSIGNED", 0, 0, 0, ""},
759
  { "UNTIL", 0, 0, 0, ""},
760
  { "UPDATE", 0, 0, 0, ""},
761
  { "UPGRADE", 0, 0, 0, ""},
762
  { "USAGE", 0, 0, 0, ""},
763
  { "USE", 0, 0, 0, ""},
764
  { "USER", 0, 0, 0, ""},
765
  { "USER_RESOURCES", 0, 0, 0, ""},
766
  { "USE_FRM", 0, 0, 0, ""},
767
  { "USING", 0, 0, 0, ""},
768
  { "UTC_DATE", 0, 0, 0, ""},
769
  { "UTC_TIME", 0, 0, 0, ""},
770
  { "UTC_TIMESTAMP", 0, 0, 0, ""},
771
  { "VALUE", 0, 0, 0, ""},
772
  { "VALUES", 0, 0, 0, ""},
773
  { "VARBINARY", 0, 0, 0, ""},
774
  { "VARCHAR", 0, 0, 0, ""},
775
  { "VARCHARACTER", 0, 0, 0, ""},
776
  { "VARIABLES", 0, 0, 0, ""},
777
  { "VARYING", 0, 0, 0, ""},
778
  { "WARNINGS", 0, 0, 0, ""},
779
  { "WEEK", 0, 0, 0, ""},
780
  { "WHEN", 0, 0, 0, ""},
781
  { "WHERE", 0, 0, 0, ""},
782
  { "WHILE", 0, 0, 0, ""},
783
  { "VIEW", 0, 0, 0, ""},
784
  { "WITH", 0, 0, 0, ""},
785
  { "WORK", 0, 0, 0, ""},
786
  { "WRITE", 0, 0, 0, ""},
787
  { "X509", 0, 0, 0, ""},
788
  { "XOR", 0, 0, 0, ""},
789
  { "XA", 0, 0, 0, ""},
790
  { "YEAR", 0, 0, 0, ""},
791
  { "YEAR_MONTH", 0, 0, 0, ""},
792
  { "ZEROFILL", 0, 0, 0, ""},
793
  { "ABS", 0, 0, 0, ""},
794
  { "ACOS", 0, 0, 0, ""},
795
  { "ADDDATE", 0, 0, 0, ""},
796
  { "ADDTIME", 0, 0, 0, ""},
797
  { "AES_ENCRYPT", 0, 0, 0, ""},
798
  { "AES_DECRYPT", 0, 0, 0, ""},
799
  { "AREA", 0, 0, 0, ""},
800
  { "ASIN", 0, 0, 0, ""},
801
  { "ASBINARY", 0, 0, 0, ""},
802
  { "ASTEXT", 0, 0, 0, ""},
803
  { "ASWKB", 0, 0, 0, ""},
804
  { "ASWKT", 0, 0, 0, ""},
805
  { "ATAN", 0, 0, 0, ""},
806
  { "ATAN2", 0, 0, 0, ""},
807
  { "BENCHMARK", 0, 0, 0, ""},
808
  { "BIN", 0, 0, 0, ""},
809
  { "BIT_COUNT", 0, 0, 0, ""},
810
  { "BIT_OR", 0, 0, 0, ""},
811
  { "BIT_AND", 0, 0, 0, ""},
812
  { "BIT_XOR", 0, 0, 0, ""},
813
  { "CAST", 0, 0, 0, ""},
814
  { "CEIL", 0, 0, 0, ""},
815
  { "CEILING", 0, 0, 0, ""},
816
  { "BIT_LENGTH", 0, 0, 0, ""},
817
  { "CENTROID", 0, 0, 0, ""},
818
  { "CHAR_LENGTH", 0, 0, 0, ""},
819
  { "CHARACTER_LENGTH", 0, 0, 0, ""},
820
  { "COALESCE", 0, 0, 0, ""},
821
  { "COERCIBILITY", 0, 0, 0, ""},
822
  { "COMPRESS", 0, 0, 0, ""},
823
  { "CONCAT", 0, 0, 0, ""},
824
  { "CONCAT_WS", 0, 0, 0, ""},
825
  { "CONNECTION_ID", 0, 0, 0, ""},
826
  { "CONV", 0, 0, 0, ""},
827
  { "CONVERT_TZ", 0, 0, 0, ""},
828
  { "COUNT", 0, 0, 0, ""},
829
  { "COS", 0, 0, 0, ""},
830
  { "COT", 0, 0, 0, ""},
831
  { "CRC32", 0, 0, 0, ""},
832
  { "CROSSES", 0, 0, 0, ""},
833
  { "CURDATE", 0, 0, 0, ""},
834
  { "CURTIME", 0, 0, 0, ""},
835
  { "DATE_ADD", 0, 0, 0, ""},
836
  { "DATEDIFF", 0, 0, 0, ""},
837
  { "DATE_FORMAT", 0, 0, 0, ""},
838
  { "DATE_SUB", 0, 0, 0, ""},
839
  { "DAYNAME", 0, 0, 0, ""},
840
  { "DAYOFMONTH", 0, 0, 0, ""},
841
  { "DAYOFWEEK", 0, 0, 0, ""},
842
  { "DAYOFYEAR", 0, 0, 0, ""},
843
  { "DECODE", 0, 0, 0, ""},
844
  { "DEGREES", 0, 0, 0, ""},
845
  { "DES_ENCRYPT", 0, 0, 0, ""},
846
  { "DES_DECRYPT", 0, 0, 0, ""},
847
  { "DIMENSION", 0, 0, 0, ""},
848
  { "DISJOINT", 0, 0, 0, ""},
849
  { "ELT", 0, 0, 0, ""},
850
  { "ENCODE", 0, 0, 0, ""},
851
  { "ENCRYPT", 0, 0, 0, ""},
852
  { "ENDPOINT", 0, 0, 0, ""},
853
  { "ENVELOPE", 0, 0, 0, ""},
854
  { "EQUALS", 0, 0, 0, ""},
855
  { "EXTERIORRING", 0, 0, 0, ""},
856
  { "EXTRACT", 0, 0, 0, ""},
857
  { "EXP", 0, 0, 0, ""},
858
  { "EXPORT_SET", 0, 0, 0, ""},
859
  { "FIELD", 0, 0, 0, ""},
860
  { "FIND_IN_SET", 0, 0, 0, ""},
861
  { "FLOOR", 0, 0, 0, ""},
862
  { "FORMAT", 0, 0, 0, ""},
863
  { "FOUND_ROWS", 0, 0, 0, ""},
864
  { "FROM_DAYS", 0, 0, 0, ""},
865
  { "FROM_UNIXTIME", 0, 0, 0, ""},
866
  { "GET_LOCK", 0, 0, 0, ""},
867
  { "GEOMETRYN", 0, 0, 0, ""},
868
  { "GEOMETRYTYPE", 0, 0, 0, ""},
869
  { "GEOMCOLLFROMTEXT", 0, 0, 0, ""},
870
  { "GEOMCOLLFROMWKB", 0, 0, 0, ""},
871
  { "GEOMETRYCOLLECTIONFROMTEXT", 0, 0, 0, ""},
872
  { "GEOMETRYCOLLECTIONFROMWKB", 0, 0, 0, ""},
873
  { "GEOMETRYFROMTEXT", 0, 0, 0, ""},
874
  { "GEOMETRYFROMWKB", 0, 0, 0, ""},
875
  { "GEOMFROMTEXT", 0, 0, 0, ""},
876
  { "GEOMFROMWKB", 0, 0, 0, ""},
877
  { "GLENGTH", 0, 0, 0, ""},
878
  { "GREATEST", 0, 0, 0, ""},
879
  { "GROUP_CONCAT", 0, 0, 0, ""},
880
  { "GROUP_UNIQUE_USERS", 0, 0, 0, ""},
881
  { "HEX", 0, 0, 0, ""},
882
  { "IFNULL", 0, 0, 0, ""},
883
  { "INET_ATON", 0, 0, 0, ""},
884
  { "INET_NTOA", 0, 0, 0, ""},
885
  { "INSTR", 0, 0, 0, ""},
886
  { "INTERIORRINGN", 0, 0, 0, ""},
887
  { "INTERSECTS", 0, 0, 0, ""},
888
  { "ISCLOSED", 0, 0, 0, ""},
889
  { "ISEMPTY", 0, 0, 0, ""},
890
  { "ISNULL", 0, 0, 0, ""},
891
  { "IS_FREE_LOCK", 0, 0, 0, ""},
892
  { "IS_USED_LOCK", 0, 0, 0, ""},
893
  { "LAST_INSERT_ID", 0, 0, 0, ""},
894
  { "ISSIMPLE", 0, 0, 0, ""},
895
  { "LAST_DAY", 0, 0, 0, ""},
896
  { "LCASE", 0, 0, 0, ""},
897
  { "LEAST", 0, 0, 0, ""},
898
  { "LENGTH", 0, 0, 0, ""},
899
  { "LN", 0, 0, 0, ""},
900
  { "LINEFROMTEXT", 0, 0, 0, ""},
901
  { "LINEFROMWKB", 0, 0, 0, ""},
902
  { "LINESTRINGFROMTEXT", 0, 0, 0, ""},
903
  { "LINESTRINGFROMWKB", 0, 0, 0, ""},
904
  { "LOAD_FILE", 0, 0, 0, ""},
905
  { "LOCATE", 0, 0, 0, ""},
906
  { "LOG", 0, 0, 0, ""},
907
  { "LOG2", 0, 0, 0, ""},
908
  { "LOG10", 0, 0, 0, ""},
909
  { "LOWER", 0, 0, 0, ""},
910
  { "LPAD", 0, 0, 0, ""},
911
  { "LTRIM", 0, 0, 0, ""},
912
  { "MAKE_SET", 0, 0, 0, ""},
913
  { "MAKEDATE", 0, 0, 0, ""},
914
  { "MAKETIME", 0, 0, 0, ""},
915
  { "MASTER_POS_WAIT", 0, 0, 0, ""},
916
  { "MAX", 0, 0, 0, ""},
917
  { "MBRCONTAINS", 0, 0, 0, ""},
918
  { "MBRDISJOINT", 0, 0, 0, ""},
919
  { "MBREQUAL", 0, 0, 0, ""},
920
  { "MBRINTERSECTS", 0, 0, 0, ""},
921
  { "MBROVERLAPS", 0, 0, 0, ""},
922
  { "MBRTOUCHES", 0, 0, 0, ""},
923
  { "MBRWITHIN", 0, 0, 0, ""},
924
  { "MD5", 0, 0, 0, ""},
925
  { "MID", 0, 0, 0, ""},
926
  { "MIN", 0, 0, 0, ""},
927
  { "MLINEFROMTEXT", 0, 0, 0, ""},
928
  { "MLINEFROMWKB", 0, 0, 0, ""},
929
  { "MPOINTFROMTEXT", 0, 0, 0, ""},
930
  { "MPOINTFROMWKB", 0, 0, 0, ""},
931
  { "MPOLYFROMTEXT", 0, 0, 0, ""},
932
  { "MPOLYFROMWKB", 0, 0, 0, ""},
933
  { "MONTHNAME", 0, 0, 0, ""},
934
  { "MULTILINESTRINGFROMTEXT", 0, 0, 0, ""},
935
  { "MULTILINESTRINGFROMWKB", 0, 0, 0, ""},
936
  { "MULTIPOINTFROMTEXT", 0, 0, 0, ""},
937
  { "MULTIPOINTFROMWKB", 0, 0, 0, ""},
938
  { "MULTIPOLYGONFROMTEXT", 0, 0, 0, ""},
939
  { "MULTIPOLYGONFROMWKB", 0, 0, 0, ""},
940
  { "NAME_CONST", 0, 0, 0, ""},
941
  { "NOW", 0, 0, 0, ""},
942
  { "NULLIF", 0, 0, 0, ""},
943
  { "NUMGEOMETRIES", 0, 0, 0, ""},
944
  { "NUMINTERIORRINGS", 0, 0, 0, ""},
945
  { "NUMPOINTS", 0, 0, 0, ""},
946
  { "OCTET_LENGTH", 0, 0, 0, ""},
947
  { "OCT", 0, 0, 0, ""},
948
  { "ORD", 0, 0, 0, ""},
949
  { "OVERLAPS", 0, 0, 0, ""},
950
  { "PERIOD_ADD", 0, 0, 0, ""},
951
  { "PERIOD_DIFF", 0, 0, 0, ""},
952
  { "PI", 0, 0, 0, ""},
953
  { "POINTFROMTEXT", 0, 0, 0, ""},
954
  { "POINTFROMWKB", 0, 0, 0, ""},
955
  { "POINTN", 0, 0, 0, ""},
956
  { "POLYFROMTEXT", 0, 0, 0, ""},
957
  { "POLYFROMWKB", 0, 0, 0, ""},
958
  { "POLYGONFROMTEXT", 0, 0, 0, ""},
959
  { "POLYGONFROMWKB", 0, 0, 0, ""},
960
  { "POSITION", 0, 0, 0, ""},
961
  { "POW", 0, 0, 0, ""},
962
  { "POWER", 0, 0, 0, ""},
963
  { "QUOTE", 0, 0, 0, ""},
964
  { "RADIANS", 0, 0, 0, ""},
965
  { "RAND", 0, 0, 0, ""},
966
  { "RELEASE_LOCK", 0, 0, 0, ""},
967
  { "REVERSE", 0, 0, 0, ""},
968
  { "ROUND", 0, 0, 0, ""},
969
  { "ROW_COUNT", 0, 0, 0, ""},
970
  { "RPAD", 0, 0, 0, ""},
971
  { "RTRIM", 0, 0, 0, ""},
972
  { "SEC_TO_TIME", 0, 0, 0, ""},
973
  { "SESSION_USER", 0, 0, 0, ""},
974
  { "SUBDATE", 0, 0, 0, ""},
975
  { "SIGN", 0, 0, 0, ""},
976
  { "SIN", 0, 0, 0, ""},
977
  { "SHA", 0, 0, 0, ""},
978
  { "SHA1", 0, 0, 0, ""},
979
  { "SLEEP", 0, 0, 0, ""},
980
  { "SOUNDEX", 0, 0, 0, ""},
981
  { "SPACE", 0, 0, 0, ""},
982
  { "SQRT", 0, 0, 0, ""},
983
  { "SRID", 0, 0, 0, ""},
984
  { "STARTPOINT", 0, 0, 0, ""},
985
  { "STD", 0, 0, 0, ""},
986
  { "STDDEV", 0, 0, 0, ""},
987
  { "STDDEV_POP", 0, 0, 0, ""},
988
  { "STDDEV_SAMP", 0, 0, 0, ""},
989
  { "STR_TO_DATE", 0, 0, 0, ""},
990
  { "STRCMP", 0, 0, 0, ""},
991
  { "SUBSTR", 0, 0, 0, ""},
992
  { "SUBSTRING", 0, 0, 0, ""},
993
  { "SUBSTRING_INDEX", 0, 0, 0, ""},
994
  { "SUBTIME", 0, 0, 0, ""},
995
  { "SUM", 0, 0, 0, ""},
996
  { "SYSDATE", 0, 0, 0, ""},
997
  { "SYSTEM_USER", 0, 0, 0, ""},
998
  { "TAN", 0, 0, 0, ""},
999
  { "TIME_FORMAT", 0, 0, 0, ""},
1000
  { "TIME_TO_SEC", 0, 0, 0, ""},
1001
  { "TIMEDIFF", 0, 0, 0, ""},
1002
  { "TO_DAYS", 0, 0, 0, ""},
1003
  { "TOUCHES", 0, 0, 0, ""},
1004
  { "TRIM", 0, 0, 0, ""},
1005
  { "UCASE", 0, 0, 0, ""},
1006
  { "UNCOMPRESS", 0, 0, 0, ""},
1007
  { "UNCOMPRESSED_LENGTH", 0, 0, 0, ""},
1008
  { "UNHEX", 0, 0, 0, ""},
1009
  { "UNIQUE_USERS", 0, 0, 0, ""},
1010
  { "UNIX_TIMESTAMP", 0, 0, 0, ""},
1011
  { "UPPER", 0, 0, 0, ""},
1012
  { "UUID", 0, 0, 0, ""},
1013
  { "VARIANCE", 0, 0, 0, ""},
1014
  { "VAR_POP", 0, 0, 0, ""},
1015
  { "VAR_SAMP", 0, 0, 0, ""},
1016
  { "VERSION", 0, 0, 0, ""},
1017
  { "WEEKDAY", 0, 0, 0, ""},
1018
  { "WEEKOFYEAR", 0, 0, 0, ""},
1019
  { "WITHIN", 0, 0, 0, ""},
1020
  { "X", 0, 0, 0, ""},
1021
  { "Y", 0, 0, 0, ""},
1022
  { "YEARWEEK", 0, 0, 0, ""},
1023
  /* end sentinel */
23 by jcole at burghcom
Aesthetic changes only.
1024
  { (char *)NULL,       0, 0, 0, ""}
2 by bk at mysql
Import changeset
1025
};
1026
1027
static const char *load_default_groups[]= { "mysql","client",0 };
2476.287.1 by iggy at amd64
Bug#29903 The CMake build method does not produce the embedded library.
1028
1029
static int         embedded_server_arg_count= 0;
1030
static char       *embedded_server_args[MAX_SERVER_ARGS];
1031
static const char *embedded_server_groups[]=
818.11.1 by monty at mysql
Cleaned up SSL documentation
1032
{ "server", "embedded", "mysql_SERVER", 0 };
2 by bk at mysql
Import changeset
1033
1034
#ifdef HAVE_READLINE
1616.159.39 by harrison at lordblink
Fix up history in readline implementation.
1035
/*
1036
 HIST_ENTRY is defined for libedit, but not for the real readline
1037
 Need to redefine it for real readline to find it
1038
*/
1616.798.1 by vva at r18
fixed :
1039
#if !defined(HAVE_HIST_ENTRY)
1616.159.39 by harrison at lordblink
Fix up history in readline implementation.
1040
typedef struct _hist_entry {
1041
  const char      *line;
1042
  const char      *data;
1043
} HIST_ENTRY; 
1044
#endif
1045
1403.60.1 by vva at r18
changes for readline/libedit configuration
1046
extern "C" int add_history(const char *command); /* From readline directory */
1047
extern "C" int read_history(const char *command);
1048
extern "C" int write_history(const char *command);
1616.159.39 by harrison at lordblink
Fix up history in readline implementation.
1049
extern "C" HIST_ENTRY *history_get(int num);
1050
extern "C" int history_length;
1051
static int not_in_history(const char *line);
2 by bk at mysql
Import changeset
1052
static void initialize_readline (char *name);
1616.159.39 by harrison at lordblink
Fix up history in readline implementation.
1053
static void fix_history(String *final_command);
2 by bk at mysql
Import changeset
1054
#endif
1055
1810.854.1 by monty at mysql
Review of code pushed since last 5.0 pull:
1056
static COMMANDS *find_command(char *name,char cmd_name);
1403.16.1 by jani at inet
mysql multiline comment, by Sergey Gluhov.
1057
static bool add_line(String &buffer,char *line,char *in_string,
1810.3863.1 by Alexey Kopytov
Fix for bug#41486: extra character appears in BLOB for every
1058
                     bool *ml_comment, bool truncated);
2 by bk at mysql
Import changeset
1059
static void remove_cntrl(String &buffer);
1060
static void print_table_data(MYSQL_RES *result);
1061
static void print_table_data_html(MYSQL_RES *result);
669.1.1 by monty at mysql
Added all changes from old 4.0 version:
1062
static void print_table_data_xml(MYSQL_RES *result);
2 by bk at mysql
Import changeset
1063
static void print_tab_data(MYSQL_RES *result);
1064
static void print_table_data_vertically(MYSQL_RES *result);
1773.306.1 by geert at kemuri
Adding --show-warnings option for the mysql command line tool so warnings,
1065
static void print_warnings(void);
2 by bk at mysql
Import changeset
1066
static ulong start_timer(void);
1067
static void end_timer(ulong start_time,char *buff);
1068
static void mysql_end_timer(ulong start_time,char *buff);
1069
static void nice_time(double sec,char *buff,bool part_second);
2476.285.5 by monty at mysql
Fixed a lot of compiler warnings and errors detected by Forte C++ on Solaris
1070
extern "C" sig_handler mysql_end(int sig);
1071
extern "C" sig_handler handle_sigint(int sig);
2 by bk at mysql
Import changeset
1072
1073
int main(int argc,char *argv[])
1074
{
1075
  char buff[80];
1076
1077
  MY_INIT(argv[0]);
1078
  DBUG_ENTER("main");
1079
  DBUG_PROCESS(argv[0]);
1504.20.16 by jani at hynda
Added --delimiter option to mysql
1080
  
1081
  delimiter_str= delimiter;
973.124.2 by jani at mysql
merge
1082
  default_prompt = my_strdup(getenv("MYSQL_PS1") ? 
1083
			     getenv("MYSQL_PS1") : 
1084
			     "mysql> ",MYF(MY_WME));
1085
  current_prompt = my_strdup(default_prompt,MYF(MY_WME));
1086
  prompt_counter=0;
1087
1346.96.3 by monty at mysql
Fixes for Netware
1088
  outfile[0]=0;			// no (default) outfile
1089
  strmov(pager, "stdout");	// the default, if --pager wasn't given
676.1.11 by monty at mysql
The environment variable PAGER is now used as the default pager
1090
  {
1091
    char *tmp=getenv("PAGER");
1616.75.4 by jani at netsonic
- Added missing documentation to some mysql.cc options.
1092
    if (tmp && strlen(tmp))
1093
    {
1094
      default_pager_set= 1;
1095
      strmov(default_pager, tmp);
1096
    }
676.1.11 by monty at mysql
The environment variable PAGER is now used as the default pager
1097
  }
2 by bk at mysql
Import changeset
1098
  if (!isatty(0) || !isatty(1))
1099
  {
1100
    status.batch=1; opt_silent=1;
1101
    ignore_errors=0;
1102
  }
1103
  else
1104
    status.add_to_history=1;
1105
  status.exit_status=1;
1616.2763.3 by cmiller at cornsilk
Bug#17583: mysql drops connection when stdout is not writable
1106
1107
  {
1108
    /* 
1109
     The file descriptor-layer may be out-of-sync with the file-number layer,
1110
     so we make sure that "stdout" is really open.  If its file is closed then
1111
     explicitly close the FD layer. 
1112
    */
1113
    int stdout_fileno_copy;
1114
    stdout_fileno_copy= dup(fileno(stdout)); /* Okay if fileno fails. */
1115
    if (stdout_fileno_copy == -1)
1116
      fclose(stdout);
1117
    else
1118
      close(stdout_fileno_copy);             /* Clean up dup(). */
1119
  }
1120
2 by bk at mysql
Import changeset
1121
  load_defaults("my",load_default_groups,&argc,&argv);
1239.1.1 by monty at mysql
Removed wrong mutex lock (hangup in kill on HPUX)
1122
  defaults_argv=argv;
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1123
  if (get_options(argc, (char **) argv))
2 by bk at mysql
Import changeset
1124
  {
1239.1.1 by monty at mysql
Removed wrong mutex lock (hangup in kill on HPUX)
1125
    free_defaults(defaults_argv);
2 by bk at mysql
Import changeset
1126
    my_end(0);
1127
    exit(1);
1128
  }
1129
  if (status.batch && !status.line_buff &&
1810.3863.1 by Alexey Kopytov
Fix for bug#41486: extra character appears in BLOB for every
1130
      !(status.line_buff= batch_readline_init(MAX_BATCH_BUFFER_SIZE, stdin)))
1239.1.1 by monty at mysql
Removed wrong mutex lock (hangup in kill on HPUX)
1131
  {
3452.51.22 by Dmitry Shulga
Follow up fix for bug#57450.
1132
    put_info("Can't initialize batch_readline - may be the input source is "
1133
             "a directory or a block device.", INFO_ERROR, 0);
1239.1.1 by monty at mysql
Removed wrong mutex lock (hangup in kill on HPUX)
1134
    free_defaults(defaults_argv);
1616.398.3 by hf at deer
Addition to the fix for bug #3791 (libmysqld mysql segfaults if can's find
1135
    my_end(0);
1136
    exit(1);
1137
  }
2476.287.1 by iggy at amd64
Bug#29903 The CMake build method does not produce the embedded library.
1138
  if (mysql_server_init(embedded_server_arg_count, embedded_server_args, 
1139
                        (char**) embedded_server_groups))
1616.398.3 by hf at deer
Addition to the fix for bug #3791 (libmysqld mysql segfaults if can's find
1140
  {
1810.3644.1 by hf at mysql
Bug #25097 mysql_server_init fails silently if no errmsg.sys is present.
1141
    put_error(NULL);
1616.398.3 by hf at deer
Addition to the fix for bug #3791 (libmysqld mysql segfaults if can's find
1142
    free_defaults(defaults_argv);
1143
    my_end(0);
2 by bk at mysql
Import changeset
1144
    exit(1);
1239.1.1 by monty at mysql
Removed wrong mutex lock (hangup in kill on HPUX)
1145
  }
2 by bk at mysql
Import changeset
1146
  glob_buffer.realloc(512);
818.15.8 by monty at mysql
Updated manual about embedded version.
1147
  completion_hash_init(&ht, 128);
1148
  init_alloc_root(&hash_mem_root, 16384, 0);
818.2.7 by monty at mysql
Added support of INSERT to MERGE tables
1149
  bzero((char*) &mysql, sizeof(mysql));
2 by bk at mysql
Import changeset
1150
  if (sql_connect(current_host,current_db,current_user,opt_password,
1151
		  opt_silent))
1152
  {
121 by monty at mysql
Fixes for MyISAM and packed keys + AIX
1153
    quick=1;					// Avoid history
1154
    status.exit_status=1;
1155
    mysql_end(-1);
2 by bk at mysql
Import changeset
1156
  }
1157
  if (!status.batch)
1158
    ignore_errors=1;				// Don't abort monitor
1616.943.44 by jani at elisa-laajakaista
Added option --sigint-ignore to mysql.cc
1159
1160
  if (opt_sigint_ignore)
1161
    signal(SIGINT, SIG_IGN);
1162
  else
1616.2554.1 by jimw at mysql
In the command-line client, try to abort the current query by issuing a
1163
    signal(SIGINT, handle_sigint);              // Catch SIGINT to clean up
973.215.51 by Sinisa at nasamreza
solves coredump
1164
  signal(SIGQUIT, mysql_end);			// Catch SIGQUIT to clean up
2 by bk at mysql
Import changeset
1165
1166
  put_info("Welcome to the MySQL monitor.  Commands end with ; or \\g.",
1167
	   INFO_INFO);
1168
  sprintf((char*) glob_buffer.ptr(),
1810.2300.1 by mysqldev at mysql
mysql.cc, log.cc:
1169
	  "Your MySQL connection id is %lu\nServer version: %s\n",
1170
	  mysql_thread_id(&mysql), server_version_string(&mysql));
2 by bk at mysql
Import changeset
1171
  put_info((char*) glob_buffer.ptr(),INFO_INFO);
1172
1810.3997.15 by Alexander Nozdrin
For for Bug#12696072: FIX OUTDATED COPYRIGHT NOTICES IN RUNTIME RELATED CLIENT
1173
  put_info(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000, 2011"), INFO_INFO);
1174
2 by bk at mysql
Import changeset
1175
#ifdef HAVE_READLINE
1616.3020.2 by jani at omakaista
Fixes for 4.1 to be as in 5.0 and above.
1176
  initialize_readline((char*) my_progname);
669.1.1 by monty at mysql
Added all changes from old 4.0 version:
1177
  if (!status.batch && !quick && !opt_html && !opt_xml)
2 by bk at mysql
Import changeset
1178
  {
1009 by monty at mysql
Big code cleanup/review before 4.0.2 release.
1179
    /* read-history from file, default ~/.mysql_history*/
2 by bk at mysql
Import changeset
1180
    if (getenv("MYSQL_HISTFILE"))
1181
      histfile=my_strdup(getenv("MYSQL_HISTFILE"),MYF(MY_WME));
1182
    else if (getenv("HOME"))
1183
    {
38.1.1 by monty at mysql
FLUSH TABLE table_list
1184
      histfile=(char*) my_malloc((uint) strlen(getenv("HOME"))
1185
				 + (uint) strlen("/.mysql_history")+2,
2 by bk at mysql
Import changeset
1186
				 MYF(MY_WME));
1187
      if (histfile)
1188
	sprintf(histfile,"%s/.mysql_history",getenv("HOME"));
1810.1644.2 by msvensson at neptunus
BUG#16803 "ln -s /dev/null .mysql_history" doesn't work!
1189
      char link_name[FN_REFLEN];
1190
      if (my_readlink(link_name, histfile, 0) == 0 &&
1191
          strncmp(link_name, "/dev/null", 10) == 0)
1192
      {
1193
        /* The .mysql_history file is a symlink to /dev/null, don't use it */
1194
        my_free(histfile, MYF(MY_ALLOW_ZERO_PTR));
1195
        histfile= 0;
1196
      }
2 by bk at mysql
Import changeset
1197
    }
2871.15.6 by Jim Winstead
The mysql command-line client did not properly handle MYSQL_HISTFILE being set
1198
1199
    /* We used to suggest setting MYSQL_HISTFILE=/dev/null. */
1200
    if (histfile && strncmp(histfile, "/dev/null", 10) == 0)
1201
      histfile= NULL;
1202
1203
    if (histfile && histfile[0])
2 by bk at mysql
Import changeset
1204
    {
1205
      if (verbose)
254.2.1 by jani at mysql
New mysql client.
1206
	tee_fprintf(stdout, "Reading history-file %s\n",histfile);
2 by bk at mysql
Import changeset
1207
      read_history(histfile);
1700.112.2 by jani at omakaista
Some bug fixes and a feature add to mysql-test-run
1208
      if (!(histfile_tmp= (char*) my_malloc((uint) strlen(histfile) + 5,
1209
					    MYF(MY_WME))))
1210
      {
1211
	fprintf(stderr, "Couldn't allocate memory for temp histfile!\n");
1212
	exit(1);
1213
      }
1214
      sprintf(histfile_tmp, "%s.TMP", histfile);
2 by bk at mysql
Import changeset
1215
    }
1216
  }
3351.1.43 by Georgi Kodinov
Bug #44178: mysql cli does not comply with GPLv2 clause 2c
1217
2 by bk at mysql
Import changeset
1218
#endif
3351.1.43 by Georgi Kodinov
Bug #44178: mysql cli does not comply with GPLv2 clause 2c
1219
1403.4.37 by monty at mysql
Changed mysql-test to print warnings for not existing table to DROP TABLE
1220
  sprintf(buff, "%s",
1810.3862.5 by Sergey Glukhov
Bug#41268 Help Text for \c is misleading in client command line interface
1221
	  "Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\n");
2 by bk at mysql
Import changeset
1222
  put_info(buff,INFO_INFO);
1810.562.1 by jimw at mysql
Fix 'source' command in mysql client to handle delimiter command
1223
  status.exit_status= read_and_execute(!status.batch);
254.2.1 by jani at mysql
New mysql client.
1224
  if (opt_outfile)
1225
    end_tee();
2 by bk at mysql
Import changeset
1226
  mysql_end(0);
1227
#ifndef _lint
1228
  DBUG_RETURN(0);				// Keep compiler happy
1229
#endif
1230
}
1231
1232
sig_handler mysql_end(int sig)
1233
{
818.2.7 by monty at mysql
Added support of INSERT to MERGE tables
1234
  mysql_close(&mysql);
2 by bk at mysql
Import changeset
1235
#ifdef HAVE_READLINE
2871.15.6 by Jim Winstead
The mysql command-line client did not properly handle MYSQL_HISTFILE being set
1236
  if (!status.batch && !quick && !opt_html && !opt_xml &&
1237
      histfile && histfile[0])
2 by bk at mysql
Import changeset
1238
  {
1239
    /* write-history */
1240
    if (verbose)
254.2.1 by jani at mysql
New mysql client.
1241
      tee_fprintf(stdout, "Writing history-file %s\n",histfile);
1700.112.2 by jani at omakaista
Some bug fixes and a feature add to mysql-test-run
1242
    if (!write_history(histfile_tmp))
1243
      my_rename(histfile_tmp, histfile, MYF(MY_WME));
2 by bk at mysql
Import changeset
1244
  }
1245
  batch_readline_end(status.line_buff);
1246
  completion_hash_free(&ht);
818.15.8 by monty at mysql
Updated manual about embedded version.
1247
  free_root(&hash_mem_root,MYF(0));
1248
2 by bk at mysql
Import changeset
1249
#endif
121 by monty at mysql
Fixes for MyISAM and packed keys + AIX
1250
  if (sig >= 0)
1251
    put_info(sig ? "Aborted" : "Bye", INFO_RESULT);
2 by bk at mysql
Import changeset
1252
  glob_buffer.free();
1253
  old_buffer.free();
973.124.2 by jani at mysql
merge
1254
  processed_prompt.free();
2728.10.6 by Tatiana A. Nurnberg
Bug#43153: Version comment is too long
1255
  my_free(server_version,MYF(MY_ALLOW_ZERO_PTR));
2 by bk at mysql
Import changeset
1256
  my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
1257
  my_free(opt_mysql_unix_port,MYF(MY_ALLOW_ZERO_PTR));
1258
  my_free(histfile,MYF(MY_ALLOW_ZERO_PTR));
1700.112.2 by jani at omakaista
Some bug fixes and a feature add to mysql-test-run
1259
  my_free(histfile_tmp,MYF(MY_ALLOW_ZERO_PTR));
2 by bk at mysql
Import changeset
1260
  my_free(current_db,MYF(MY_ALLOW_ZERO_PTR));
1261
  my_free(current_host,MYF(MY_ALLOW_ZERO_PTR));
1262
  my_free(current_user,MYF(MY_ALLOW_ZERO_PTR));
973.124.2 by jani at mysql
merge
1263
  my_free(full_username,MYF(MY_ALLOW_ZERO_PTR));
1264
  my_free(part_username,MYF(MY_ALLOW_ZERO_PTR));
1265
  my_free(default_prompt,MYF(MY_ALLOW_ZERO_PTR));
1354.36.1 by wax at mysql
Add shared memory protocol and option --protocol
1266
#ifdef HAVE_SMEM
1267
  my_free(shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
1268
#endif
973.124.2 by jani at mysql
merge
1269
  my_free(current_prompt,MYF(MY_ALLOW_ZERO_PTR));
2476.287.1 by iggy at amd64
Bug#29903 The CMake build method does not produce the embedded library.
1270
  while (embedded_server_arg_count > 1)
1271
    my_free(embedded_server_args[--embedded_server_arg_count],MYF(0));
818.11.1 by monty at mysql
Cleaned up SSL documentation
1272
  mysql_server_end();
1239.1.1 by monty at mysql
Removed wrong mutex lock (hangup in kill on HPUX)
1273
  free_defaults(defaults_argv);
2476.284.5 by monty at mysql
Fixes Bug#30127: --debug-info no longer prints memory usage in mysql
1274
  my_end(my_end_arg);
2 by bk at mysql
Import changeset
1275
  exit(status.exit_status);
1276
}
1277
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1278
1616.2554.1 by jimw at mysql
In the command-line client, try to abort the current query by issuing a
1279
/*
1280
  This function handles sigint calls
1281
  If query is in process, kill query
1282
  no query in process, terminate like previous behavior
1283
 */
1284
sig_handler handle_sigint(int sig)
1285
{
1286
  char kill_buffer[40];
1287
  MYSQL *kill_mysql= NULL;
1288
1289
  /* terminate if no query being executed, or we already tried interrupting */
3184.3.1 by Tatiana A. Nurnberg
manual merge of 28141
1290
  /* terminate if no query being executed, or we already tried interrupting */
1810.3959.2 by Tatiana A. Nurnberg
Bug#28141: Control C on query waiting on lock causes ERROR 1053 (server shutdown)
1291
  if (!executing_query || (interrupted_query == 2))
1292
  {
1293
    tee_fprintf(stdout, "Ctrl-C -- exit!\n");
2542.50.2 by iggy at amd64
Merge amd64.(none):/src/bug26243/my50-bug26243
1294
    goto err;
1810.3959.2 by Tatiana A. Nurnberg
Bug#28141: Control C on query waiting on lock causes ERROR 1053 (server shutdown)
1295
  }
1616.2554.1 by jimw at mysql
In the command-line client, try to abort the current query by issuing a
1296
1297
  kill_mysql= mysql_init(kill_mysql);
1298
  if (!mysql_real_connect(kill_mysql,current_host, current_user, opt_password,
1299
                          "", opt_mysql_port, opt_mysql_unix_port,0))
1810.3959.2 by Tatiana A. Nurnberg
Bug#28141: Control C on query waiting on lock causes ERROR 1053 (server shutdown)
1300
  {
1301
    tee_fprintf(stdout, "Ctrl-C -- sorry, cannot connect to server to kill query, giving up ...\n");
2542.50.2 by iggy at amd64
Merge amd64.(none):/src/bug26243/my50-bug26243
1302
    goto err;
1810.3959.2 by Tatiana A. Nurnberg
Bug#28141: Control C on query waiting on lock causes ERROR 1053 (server shutdown)
1303
  }
1304
1305
  interrupted_query++;
1306
1307
  /* mysqld < 5 does not understand KILL QUERY, skip to KILL CONNECTION */
1308
  if ((interrupted_query == 1) && (mysql_get_server_version(&mysql) < 50000))
1309
    interrupted_query= 2;
1310
1616.2554.1 by jimw at mysql
In the command-line client, try to abort the current query by issuing a
1311
  /* kill_buffer is always big enough because max length of %lu is 15 */
1810.3959.2 by Tatiana A. Nurnberg
Bug#28141: Control C on query waiting on lock causes ERROR 1053 (server shutdown)
1312
  sprintf(kill_buffer, "KILL %s%lu",
1313
          (interrupted_query == 1) ? "QUERY " : "",
1314
          mysql_thread_id(&mysql));
1315
  tee_fprintf(stdout, "Ctrl-C -- sending \"%s\" to server ...\n", kill_buffer);
1810.3864.1 by Ignacio Galarza
Bug#29125 Windows Server X64: so many compiler warnings
1316
  mysql_real_query(kill_mysql, kill_buffer, (uint) strlen(kill_buffer));
1616.2554.1 by jimw at mysql
In the command-line client, try to abort the current query by issuing a
1317
  mysql_close(kill_mysql);
1810.3959.2 by Tatiana A. Nurnberg
Bug#28141: Control C on query waiting on lock causes ERROR 1053 (server shutdown)
1318
  tee_fprintf(stdout, "Ctrl-C -- query aborted.\n");
2542.50.2 by iggy at amd64
Merge amd64.(none):/src/bug26243/my50-bug26243
1319
1320
  return;
1321
1322
err:
1323
#ifdef _WIN32
1324
  /*
1325
   When SIGINT is raised on Windows, the OS creates a new thread to handle the
1326
   interrupt. Once that thread completes, the main thread continues running 
1327
   only to find that it's resources have already been free'd when the sigint 
1328
   handler called mysql_end(). 
1329
  */
1330
  mysql_thread_end();
1331
  return;
1332
#else
1333
  mysql_end(sig);
1334
#endif  
1616.2554.1 by jimw at mysql
In the command-line client, try to abort the current query by issuing a
1335
}
1336
1337
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1338
static struct my_option my_long_options[] =
2 by bk at mysql
Import changeset
1339
{
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1340
  {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
1341
   0, 0, 0, 0, 0},
1616.75.4 by jani at netsonic
- Added missing documentation to some mysql.cc options.
1342
  {"help", 'I', "Synonym for -?", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
1343
   0, 0, 0, 0, 0},
1346.843.12 by jani at elisa-laajakaista
Several fixes for Netware.
1344
#ifdef __NETWARE__
3333.1.22 by Staale Smedseng
Recommit of Bug#49447.
1345
  {"autoclose", OPT_AUTO_CLOSE, "Automatically close the screen on exit for Netware.",
1346.843.12 by jani at elisa-laajakaista
Several fixes for Netware.
1346
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1347
#endif
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1348
  {"auto-rehash", OPT_AUTO_REHASH,
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1349
   "Enable automatic rehashing. One doesn't need to use 'rehash' to get table "
1350
   "and field completion, but startup and reconnecting may take a longer time. "
1351
   "Disable with --disable-auto-rehash.",
1352
   &opt_rehash, &opt_rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
1810.2323.19 by monty at mysql
Fixed compiler warnings detected by option -Wshadow and -Wunused:
1353
   0, 0},
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1354
  {"no-auto-rehash", 'A',
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1355
   "No automatic rehashing. One has to use 'rehash' to get table and field "
1356
   "completion. This gives a quicker start of mysql and disables rehashing "
1357
   "on reconnect.",
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1358
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1359
  {"batch", 'B',
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1360
   "Don't use history file. Disable interactive behavior. (Enables --silent.)",
1361
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1362
  {"character-sets-dir", OPT_CHARSETS_DIR,
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1363
   "Directory for character set files.", &charsets_dir,
1364
   &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
2303.84.1 by monty at mysql
Added --debug-info to most clients to detect memory leaks in mysql-test-run
1365
  {"column-type-info", OPT_COLUMN_TYPES, "Display column type information.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1366
   &column_types_flag, &column_types_flag,
2303.84.1 by monty at mysql
Added --debug-info to most clients to detect memory leaks in mysql-test-run
1367
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1810.3428.5 by kaa at polly
Changed the help text for --comments to make it clear which option
1368
  {"comments", 'c', "Preserve comments. Send comments to the server."
3333.1.22 by Staale Smedseng
Recommit of Bug#49447.
1369
   " The default is --skip-comments (discard comments), enable with --comments.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1370
   &preserve_comments, &preserve_comments,
1810.3428.5 by kaa at polly
Changed the help text for --comments to make it clear which option
1371
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1372
  {"compress", 'C', "Use compression in server/client protocol.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1373
   &opt_compress, &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1374
   0, 0, 0},
1616.75.4 by jani at netsonic
- Added missing documentation to some mysql.cc options.
1375
#ifdef DBUG_OFF
3333.1.22 by Staale Smedseng
Recommit of Bug#49447.
1376
  {"debug", '#', "This is a non-debug version. Catch this and exit.",
1616.70.31 by serg at serg
compilation error fixed
1377
   0,0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
1616.75.4 by jani at netsonic
- Added missing documentation to some mysql.cc options.
1378
#else
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1379
  {"debug", '#', "Output debug log.", &default_dbug_option,
1380
   &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1381
#endif
2871.1.12 by Jim Winstead
Remove extraneous space in --debug-check usage info.
1382
  {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1383
   &debug_check_flag, &debug_check_flag, 0,
2476.284.5 by monty at mysql
Fixes Bug#30127: --debug-info no longer prints memory usage in mysql
1384
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1385
  {"debug-info", 'T', "Print some debug info at exit.", &debug_info_flag,
1386
   &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1387
  {"database", 'D', "Database to use.", &current_db,
1388
   &current_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
2303.84.1 by monty at mysql
Added --debug-info to most clients to detect memory leaks in mysql-test-run
1389
  {"default-character-set", OPT_DEFAULT_CHARSET,
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1390
   "Set the default character set.", &default_charset,
1391
   &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1392
  {"delimiter", OPT_DELIMITER, "Delimiter to be used.", &delimiter_str,
1393
   &delimiter_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3333.1.22 by Staale Smedseng
Recommit of Bug#49447.
1394
  {"execute", 'e', "Execute command and quit. (Disables --force and history file.)", 0,
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1395
   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1396
  {"vertical", 'E', "Print the output of a query (rows) vertically.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1397
   &vertical, &vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1398
   0},
3333.1.22 by Staale Smedseng
Recommit of Bug#49447.
1399
  {"force", 'f', "Continue even if we get an SQL error.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1400
   &ignore_errors, &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1401
   0, 0, 0, 0},
1402
  {"named-commands", 'G',
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1403
   "Enable named commands. Named commands mean this program's internal "
1404
   "commands; see mysql> help . When enabled, the named commands can be "
1405
   "used from any line of the query, otherwise only from the first line, "
1406
   "before an enter. Disable with --disable-named-commands. This option "
1407
   "is disabled by default.",
1408
   &named_cmds, &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1409
   0, 0},
1616.2709.1 by greenman at greendragongames
Fix for Bug #19364 "mysql --help gives old informations".
1410
  {"no-named-commands", 'g',
3333.1.22 by Staale Smedseng
Recommit of Bug#49447.
1411
   "Named commands are disabled. Use \\* form only, or use named commands "
1412
   "only in the beginning of a line ending with a semicolon (;). Since "
1413
   "version 10.9, the client now starts with this option ENABLED by default. "
1414
   "Disable with '-G'. Long format commands still work from the first line. "
1415
   "WARNING: option deprecated; use --disable-named-commands instead.",
1616.2709.1 by greenman at greendragongames
Fix for Bug #19364 "mysql --help gives old informations".
1416
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1810.3888.7 by Jim Winstead
Fix support for -i (--ignore-spaces) in the mysql command line application,
1417
  {"ignore-spaces", 'i', "Ignore space after function names.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1418
   &ignore_spaces, &ignore_spaces, 0, GET_BOOL, NO_ARG, 0, 0,
1810.3888.7 by Jim Winstead
Fix support for -i (--ignore-spaces) in the mysql command line application,
1419
   0, 0, 0, 0},
973.124.2 by jani at mysql
merge
1420
  {"local-infile", OPT_LOCAL_INFILE, "Enable/disable LOAD DATA LOCAL INFILE.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1421
   &opt_local_infile,
1422
   &opt_local_infile, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
1423
  {"no-beep", 'b', "Turn off beep on error.", &opt_nobeep,
1424
   &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, 
1425
  {"host", 'h', "Connect to host.", &current_host,
1426
   &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1427
  {"html", 'H', "Produce HTML output.", &opt_html, &opt_html,
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1428
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1429
  {"xml", 'X', "Produce XML output.", &opt_xml, &opt_xml, 0,
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1430
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1431
  {"line-numbers", OPT_LINE_NUMBERS, "Write line numbers for errors.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1432
   &line_numbers, &line_numbers, 0, GET_BOOL,
1009 by monty at mysql
Big code cleanup/review before 4.0.2 release.
1433
   NO_ARG, 1, 0, 0, 0, 0, 0},  
3329 by Magne Mahre
WL#5154 Remove deprecated 4.1 features
1434
  {"skip-line-numbers", 'L', "Don't write line number for errors.", 0, 0, 0, GET_NO_ARG,
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1435
   NO_ARG, 0, 0, 0, 0, 0, 0},
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1436
  {"unbuffered", 'n', "Flush buffer after each query.", &unbuffered,
1437
   &unbuffered, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1438
  {"column-names", OPT_COLUMN_NAMES, "Write column names in results.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1439
   &column_names, &column_names, 0, GET_BOOL,
973.202.2 by Sinisa at nasamreza
small fix for a bug introduced when someone made a new getopt scheme
1440
   NO_ARG, 1, 0, 0, 0, 0, 0},
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1441
  {"skip-column-names", 'N',
3329 by Magne Mahre
WL#5154 Remove deprecated 4.1 features
1442
   "Don't write column names in results.",
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1443
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1444
  {"set-variable", 'O',
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1445
   "Change the value of a variable. Please note that this option is "
1446
   "deprecated; you can set variables directly with --variable-name=value.",
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1447
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3333.1.22 by Staale Smedseng
Recommit of Bug#49447.
1448
  {"sigint-ignore", OPT_SIGINT_IGNORE, "Ignore SIGINT (CTRL-C).",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1449
   &opt_sigint_ignore,  &opt_sigint_ignore, 0, GET_BOOL,
1616.943.44 by jani at elisa-laajakaista
Added option --sigint-ignore to mysql.cc
1450
   NO_ARG, 0, 0, 0, 0, 0, 0},
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1451
  {"one-database", 'o',
3452.28.1 by Nirbhay Choubey
Bug #54899 : --one-database option cannot handle DROP/CREATE DATABASE commands
1452
   "Ignore statements except those that occur while the default "
1453
   "database is the one named at the command line.",
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1454
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1346.96.3 by monty at mysql
Fixes for Netware
1455
#ifdef USE_POPEN
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1456
  {"pager", OPT_PAGER,
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1457
   "Pager to use to display results. If you don't supply an option, the "
1458
   "default pager is taken from your ENV variable PAGER. Valid pagers are "
1459
   "less, more, cat [> filename], etc. See interactive help (\\h) also. "
1460
   "This option does not work in batch mode. Disable with --disable-pager. "
1461
   "This option is disabled by default.",
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1462
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
1616.2709.1 by greenman at greendragongames
Fix for Bug #19364 "mysql --help gives old informations".
1463
  {"no-pager", OPT_NOPAGER,
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1464
   "Disable pager and print to stdout. See interactive help (\\h) also. "
1465
   "WARNING: option deprecated; use --disable-pager instead.",
1616.2709.1 by greenman at greendragongames
Fix for Bug #19364 "mysql --help gives old informations".
1466
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1467
#endif
1468
  {"password", 'p',
1469
   "Password to use when connecting to server. If password is not given it's asked from the tty.",
1470
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
2 by bk at mysql
Import changeset
1471
#ifdef __WIN__
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1472
  {"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG,
1473
   NO_ARG, 0, 0, 0, 0, 0, 0},
2 by bk at mysql
Import changeset
1474
#endif
1810.3328.1 by tnurnberg at mysql
Bug #15327: configure: --with-tcp-port option being partially ignored
1475
  {"port", 'P', "Port number to use for connection or 0 for default to, in "
1476
   "order of preference, my.cnf, $MYSQL_TCP_PORT, "
1477
#if MYSQL_PORT_DEFAULT == 0
1478
   "/etc/services, "
1479
#endif
1480
   "built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1481
   &opt_mysql_port,
1482
   &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,  0},
973.177.8 by jani at netsonic
- Added new type GET_STRALC to my_getopt.
1483
  {"prompt", OPT_PROMPT, "Set the mysql prompt to this value.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1484
   &current_prompt, &current_prompt, 0, GET_STR_ALLOC,
973.177.8 by jani at netsonic
- Added new type GET_STRALC to my_getopt.
1485
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3333.1.22 by Staale Smedseng
Recommit of Bug#49447.
1486
  {"protocol", OPT_MYSQL_PROTOCOL, "The protocol to use for connection (tcp, socket, pipe, memory).",
1354.36.1 by wax at mysql
Add shared memory protocol and option --protocol
1487
   0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1488
  {"quick", 'q',
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1489
   "Don't cache result, print it row by row. This may slow down the server "
1490
   "if the output is suspended. Doesn't use history file.",
1491
   &quick, &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1538.30.1 by serg at serg
consistency fix - all help texts for command-line options should end with a dot.
1492
  {"raw", 'r', "Write fields without conversion. Used with --batch.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1493
   &opt_raw_data, &opt_raw_data, 0, GET_BOOL, NO_ARG, 0, 0, 0,
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1494
   0, 0, 0},
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1495
  {"reconnect", OPT_RECONNECT, "Reconnect if the connection is lost. Disable "
1496
   "with --disable-reconnect. This option is enabled by default.",
1497
   &opt_reconnect, &opt_reconnect, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
1498
  {"silent", 's', "Be more silent. Print results with a tab as separator, "
1499
   "each row on new line.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1354.36.1 by wax at mysql
Add shared memory protocol and option --protocol
1500
#ifdef HAVE_SMEM
1616.821.4 by paul at kitebird
Names listed as options should look like options,
1501
  {"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1502
   "Base name of shared memory.", &shared_memory_base_name,
1503
   &shared_memory_base_name, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1354.36.1 by wax at mysql
Add shared memory protocol and option --protocol
1504
#endif
3333.1.22 by Staale Smedseng
Recommit of Bug#49447.
1505
  {"socket", 'S', "The socket file to use for connection.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1506
   &opt_mysql_unix_port, &opt_mysql_unix_port, 0, GET_STR_ALLOC,
973.177.8 by jani at netsonic
- Added new type GET_STRALC to my_getopt.
1507
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
2 by bk at mysql
Import changeset
1508
#include "sslopt-longopts.h"
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1509
  {"table", 't', "Output in table format.", &output_tables,
1510
   &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1511
  {"tee", OPT_TEE,
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1512
   "Append everything into outfile. See interactive help (\\h) also. "
1513
   "Does not work in batch mode. Disable with --disable-tee. "
1514
   "This option is disabled by default.",
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1515
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1516
  {"no-tee", OPT_NOTEE, "Disable outfile. See interactive help (\\h) also. "
1517
   "WARNING: Option deprecated; use --disable-tee instead.",
1518
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
2 by bk at mysql
Import changeset
1519
#ifndef DONT_ALLOW_USER_CHANGE
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1520
  {"user", 'u', "User for login if not current user.", &current_user,
1521
   &current_user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
2 by bk at mysql
Import changeset
1522
#endif
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1523
  {"safe-updates", 'U', "Only allow UPDATE and DELETE that uses keys.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1524
   &safe_updates, &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1525
   0, 0, 0, 0},
1331.1.10 by jani at netsonic
Small fixes in mysql and myisampack
1526
  {"i-am-a-dummy", 'U', "Synonym for option --safe-updates, -U.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1527
   &safe_updates, &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
1331.1.10 by jani at netsonic
Small fixes in mysql and myisampack
1528
   0, 0, 0, 0},
1538.30.1 by serg at serg
consistency fix - all help texts for command-line options should end with a dot.
1529
  {"verbose", 'v', "Write more. (-v -v -v gives the table output format).", 0,
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1530
   0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1531
  {"version", 'V', "Output version information and exit.", 0, 0, 0,
1532
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1533
  {"wait", 'w', "Wait and retry if connection is down.", 0, 0, 0, GET_NO_ARG,
1534
   NO_ARG, 0, 0, 0, 0, 0, 0},
1616.75.4 by jani at netsonic
- Added missing documentation to some mysql.cc options.
1535
  {"connect_timeout", OPT_CONNECT_TIMEOUT,
1536
   "Number of seconds before connection timeout.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1537
   &opt_connect_timeout, &opt_connect_timeout, 0, GET_ULONG, REQUIRED_ARG,
1538
   0, 0, 3600*12, 0, 0, 0},
1616.75.4 by jani at netsonic
- Added missing documentation to some mysql.cc options.
1539
  {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET,
3333.1.22 by Staale Smedseng
Recommit of Bug#49447.
1540
   "The maximum packet length to send to or receive from server.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1541
   &opt_max_allowed_packet, &opt_max_allowed_packet, 0,
1810.3534.1 by tnurnberg at mysql
Bug#31177: Server variables can't be set to their current values
1542
   GET_ULONG, REQUIRED_ARG, 16 *1024L*1024L, 4096,
1543
   (longlong) 2*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
1616.75.4 by jani at netsonic
- Added missing documentation to some mysql.cc options.
1544
  {"net_buffer_length", OPT_NET_BUFFER_LENGTH,
3333.1.22 by Staale Smedseng
Recommit of Bug#49447.
1545
   "The buffer size for TCP/IP and socket communication.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1546
   &opt_net_buffer_length, &opt_net_buffer_length, 0, GET_ULONG,
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1547
   REQUIRED_ARG, 16384, 1024, 512*1024*1024L, MALLOC_OVERHEAD, 1024, 0},
1616.75.4 by jani at netsonic
- Added missing documentation to some mysql.cc options.
1548
  {"select_limit", OPT_SELECT_LIMIT,
3333.1.22 by Staale Smedseng
Recommit of Bug#49447.
1549
   "Automatic limit for SELECT when using --safe-updates.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1550
   &select_limit, &select_limit, 0, GET_ULONG, REQUIRED_ARG, 1000L,
1551
   1, ULONG_MAX, 0, 1, 0},
1616.75.4 by jani at netsonic
- Added missing documentation to some mysql.cc options.
1552
  {"max_join_size", OPT_MAX_JOIN_SIZE,
3333.1.22 by Staale Smedseng
Recommit of Bug#49447.
1553
   "Automatic limit for rows in a join when using --safe-updates.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1554
   &max_join_size, &max_join_size, 0, GET_ULONG, REQUIRED_ARG, 1000000L,
1555
   1, ULONG_MAX, 0, 1, 0},
1616.26.1 by konstantin at oak
Second part of WL #519:
1556
  {"secure-auth", OPT_SECURE_AUTH, "Refuse client connecting to server if it"
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1557
    " uses old (pre-4.1.1) protocol.", &opt_secure_auth,
1558
    &opt_secure_auth, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
2476.287.1 by iggy at amd64
Bug#29903 The CMake build method does not produce the embedded library.
1559
  {"server-arg", OPT_SERVER_ARG, "Send embedded server this as a parameter.",
1560
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1773.306.1 by geert at kemuri
Adding --show-warnings option for the mysql command line tool so warnings,
1561
  {"show-warnings", OPT_SHOW_WARNINGS, "Show warnings after every statement.",
3425 by Davi Arnaut
Bug#42733: Type-punning warnings when compiling MySQL --
1562
    &show_warnings, &show_warnings, 0, GET_BOOL, NO_ARG,
1773.306.1 by geert at kemuri
Adding --show-warnings option for the mysql command line tool so warnings,
1563
    0, 0, 0, 0, 0, 0},
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1564
  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
2 by bk at mysql
Import changeset
1565
};
1566
1567
1568
static void usage(int version)
1569
{
1346.623.1 by monty at mysql
Added patches from Novell
1570
  /* Divert all help information on NetWare to logger screen. */
1571
#ifdef __NETWARE__
1572
#define printf	consoleprintf
1573
#endif
1616.1862.2 by msvensson at neptunus
BUG#2596 MySQL Client Segmentation Fault on Solaris 9
1574
1575
#if defined(USE_LIBEDIT_INTERFACE)
1576
  const char* readline= "";
1577
#else
1578
  const char* readline= "readline";
1579
#endif
1580
1616.1900.1 by rburnett at mysql
Bug #10245 VC++ compiler error with mysql.cc
1581
#ifdef HAVE_READLINE
1616.1862.2 by msvensson at neptunus
BUG#2596 MySQL Client Segmentation Fault on Solaris 9
1582
  printf("%s  Ver %s Distrib %s, for %s (%s) using %s %s\n",
1583
	 my_progname, VER, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE,
1584
         readline, rl_library_version);
1616.1900.1 by rburnett at mysql
Bug #10245 VC++ compiler error with mysql.cc
1585
#else
1810.1133.9 by knielsen at mysql
Bug#15097: Missing \n in header printed by mysql --help when HAVE_READLINE
1586
  printf("%s  Ver %s Distrib %s, for %s (%s)\n", my_progname, VER,
1616.1900.1 by rburnett at mysql
Bug #10245 VC++ compiler error with mysql.cc
1587
	MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
1588
#endif
1589
2 by bk at mysql
Import changeset
1590
  if (version)
1591
    return;
1810.3997.15 by Alexander Nozdrin
For for Bug#12696072: FIX OUTDATED COPYRIGHT NOTICES IN RUNTIME RELATED CLIENT
1592
  puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000, 2011"));
2 by bk at mysql
Import changeset
1593
  printf("Usage: %s [OPTIONS] [database]\n", my_progname);
973.124.3 by jani at mysql
Merge and two bug fixes in my_getopt.c
1594
  my_print_help(my_long_options);
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1595
  print_defaults("my", load_default_groups);
1596
  my_print_variables(my_long_options);
1346.623.1 by monty at mysql
Added patches from Novell
1597
  NETWARE_SET_SCREEN_MODE(1);
1598
#ifdef __NETWARE__
1599
#undef printf
1600
#endif
2 by bk at mysql
Import changeset
1601
}
1602
1346.623.1 by monty at mysql
Added patches from Novell
1603
2476.285.5 by monty at mysql
Fixed a lot of compiler warnings and errors detected by Forte C++ on Solaris
1604
my_bool
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1605
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
1606
	       char *argument)
2 by bk at mysql
Import changeset
1607
{
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1608
  switch(optid) {
1346.843.12 by jani at elisa-laajakaista
Several fixes for Netware.
1609
#ifdef __NETWARE__
1610
  case OPT_AUTO_CLOSE:
1611
    setscreenmode(SCR_AUTOCLOSE_ON_EXIT);
1612
    break;
1613
#endif
973.202.15 by jani at inet
Fixed a bug in mysql client.
1614
  case OPT_CHARSETS_DIR:
1810.2845.4 by ram at mysql
Fix for
1615
    strmake(mysql_charsets_dir, argument, sizeof(mysql_charsets_dir) - 1);
973.202.15 by jani at inet
Fixed a bug in mysql client.
1616
    charsets_dir = mysql_charsets_dir;
1617
    break;
1546.59.8 by monty at mysql
After merge fixes
1618
  case  OPT_DEFAULT_CHARSET:
1619
    default_charset_used= 1;
1620
    break;
1504.20.16 by jani at hynda
Added --delimiter option to mysql
1621
  case OPT_DELIMITER:
1810.2377.2 by jpipes at shakedown
Fix for Bug #21412 (client allows DELIMITER with backslash character)
1622
    if (argument == disabled_my_option) 
1623
    {
1504.20.16 by jani at hynda
Added --delimiter option to mysql
1624
      strmov(delimiter, DEFAULT_DELIMITER);
1810.2377.2 by jpipes at shakedown
Fix for Bug #21412 (client allows DELIMITER with backslash character)
1625
    }
1626
    else 
1627
    {
1628
      /* Check that delimiter does not contain a backslash */
1629
      if (!strstr(argument, "\\")) 
1630
      {
1631
        strmake(delimiter, argument, sizeof(delimiter) - 1);
1632
      }
1633
      else 
1634
      {
1635
        put_info("DELIMITER cannot contain a backslash character", INFO_ERROR);
1636
        return 0;
1637
      } 
1638
    }
1616.1711.24 by georg at sap
fixed conversion errors (Windows IA64 build)
1639
    delimiter_length= (uint)strlen(delimiter);
1504.20.16 by jani at hynda
Added --delimiter option to mysql
1640
    delimiter_str= delimiter;
1641
    break;
973.202.15 by jani at inet
Fixed a bug in mysql client.
1642
  case OPT_LOCAL_INFILE:
1643
    using_opt_local_infile=1;
1644
    break;
1645
  case OPT_TEE:
1646
    if (argument == disabled_my_option)
1647
    {
254.2.1 by jani at mysql
New mysql client.
1648
      if (opt_outfile)
1649
	end_tee();
973.202.15 by jani at inet
Fixed a bug in mysql client.
1650
    }
1651
    else
1346.96.3 by monty at mysql
Fixes for Netware
1652
      init_tee(argument);
973.202.15 by jani at inet
Fixed a bug in mysql client.
1653
    break;
1654
  case OPT_NOTEE:
3333.2.3 by Magne Mahre
WL#5182 Remove more deprecated 4.1/5.0 features
1655
    WARN_DEPRECATED(VER_CELOSIA, "--no-tee", "--disable-tee");
973.202.15 by jani at inet
Fixed a bug in mysql client.
1656
    if (opt_outfile)
1657
      end_tee();
1658
    break;
1659
  case OPT_PAGER:
1343 by jani at netsonic
Fixed some bugs in mysql, mysqladmin and mysqld.
1660
    if (argument == disabled_my_option)
1661
      opt_nopager= 1;
973.202.15 by jani at inet
Fixed a bug in mysql client.
1662
    else
1343 by jani at netsonic
Fixed some bugs in mysql, mysqladmin and mysqld.
1663
    {
1664
      opt_nopager= 0;
1616.75.4 by jani at netsonic
- Added missing documentation to some mysql.cc options.
1665
      if (argument && strlen(argument))
1666
      {
1667
	default_pager_set= 1;
1810.2845.4 by ram at mysql
Fix for
1668
	strmake(pager, argument, sizeof(pager) - 1);
1616.75.4 by jani at netsonic
- Added missing documentation to some mysql.cc options.
1669
	strmov(default_pager, pager);
1670
      }
1671
      else if (default_pager_set)
1343 by jani at netsonic
Fixed some bugs in mysql, mysqladmin and mysqld.
1672
	strmov(pager, default_pager);
1616.75.4 by jani at netsonic
- Added missing documentation to some mysql.cc options.
1673
      else
1674
	opt_nopager= 1;
1343 by jani at netsonic
Fixed some bugs in mysql, mysqladmin and mysqld.
1675
    }
973.202.15 by jani at inet
Fixed a bug in mysql client.
1676
    break;
1677
  case OPT_NOPAGER:
3329 by Magne Mahre
WL#5154 Remove deprecated 4.1 features
1678
    WARN_DEPRECATED(VER_CELOSIA, "--no-pager", "--disable-pager");
973.202.15 by jani at inet
Fixed a bug in mysql client.
1679
    opt_nopager= 1;
1810.1740.1 by anjuta at arthur
BUG#19363: mysql --no_pager makes core dump.
1680
    break;
1354.36.1 by wax at mysql
Add shared memory protocol and option --protocol
1681
  case OPT_MYSQL_PROTOCOL:
2709.4.1 by Vladislav Vaintroub
Bug#38522: 5 seconds delay when closing application using embedded server
1682
#ifndef EMBEDDED_LIBRARY
2469.155.1 by jani at omakaista
Added find_type_or_exit and find_bit_type_or_exit as wrappers
1683
    opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
1684
                                    opt->name);
2709.4.1 by Vladislav Vaintroub
Bug#38522: 5 seconds delay when closing application using embedded server
1685
#endif
1354.36.1 by wax at mysql
Add shared memory protocol and option --protocol
1686
    break;
2476.287.1 by iggy at amd64
Bug#29903 The CMake build method does not produce the embedded library.
1687
  case OPT_SERVER_ARG:
1688
#ifdef EMBEDDED_LIBRARY
1689
    /*
1690
      When the embedded server is being tested, the client needs to be
1691
      able to pass command-line arguments to the embedded server so it can
1692
      locate the language files and data directory.
1693
    */
1694
    if (!embedded_server_arg_count)
1695
    {
1696
      embedded_server_arg_count= 1;
1697
      embedded_server_args[0]= (char*) "";
1698
    }
1699
    if (embedded_server_arg_count == MAX_SERVER_ARGS-1 ||
1700
        !(embedded_server_args[embedded_server_arg_count++]=
1701
          my_strdup(argument, MYF(MY_FAE))))
1702
    {
1703
        put_info("Can't use server argument", INFO_ERROR);
1704
        return 0;
1705
    }
1706
#else /*EMBEDDED_LIBRARY */
1707
    printf("WARNING: --server-arg option not supported in this configuration.\n");
1708
#endif
1709
    break;
973.202.15 by jani at inet
Fixed a bug in mysql client.
1710
  case 'A':
1810.2323.19 by monty at mysql
Fixed compiler warnings detected by option -Wshadow and -Wunused:
1711
    opt_rehash= 0;
973.202.15 by jani at inet
Fixed a bug in mysql client.
1712
    break;
1713
  case 'N':
1714
    column_names= 0;
1715
    break;
1716
  case 'e':
1717
    status.batch= 1;
1718
    status.add_to_history= 0;
1616.354.1 by serg at serg
mysql.cc:
1719
    if (!status.line_buff)
1720
      ignore_errors= 0;                         // do it for the first -e only
1721
    if (!(status.line_buff= batch_readline_command(status.line_buff, argument)))
973.202.15 by jani at inet
Fixed a bug in mysql client.
1722
      return 1;
1723
    break;
3329 by Magne Mahre
WL#5154 Remove deprecated 4.1 features
1724
  case 'g':
1725
    WARN_DEPRECATED(VER_CELOSIA, "-g, --no-named-commands", "--skip-named-commands");
1726
    break;
973.202.15 by jani at inet
Fixed a bug in mysql client.
1727
  case 'o':
1728
    if (argument == disabled_my_option)
1729
      one_database= 0;
1730
    else
1731
      one_database= skip_updates= 1;
1732
    break;
3329 by Magne Mahre
WL#5154 Remove deprecated 4.1 features
1733
  case 'O':
1734
    WARN_DEPRECATED(VER_CELOSIA, "-O, --set-variable", "--variable-name=value");
1735
    break;
973.202.15 by jani at inet
Fixed a bug in mysql client.
1736
  case 'p':
1737
    if (argument == disabled_my_option)
1738
      argument= (char*) "";			// Don't require password
1739
    if (argument)
1740
    {
1741
      char *start= argument;
1742
      my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
1743
      opt_password= my_strdup(argument, MYF(MY_FAE));
1744
      while (*argument) *argument++= 'x';		// Destroy argument
1745
      if (*start)
1746
	start[1]=0 ;
1616.801.20 by jani at netsonic
Fixed a bug in mysql.cc. Overriding password prompting
1747
      tty_password= 0;
973.202.15 by jani at inet
Fixed a bug in mysql client.
1748
    }
1749
    else
1750
      tty_password= 1;
1751
    break;
1752
  case '#':
1753
    DBUG_PUSH(argument ? argument : default_dbug_option);
2476.284.5 by monty at mysql
Fixes Bug#30127: --debug-info no longer prints memory usage in mysql
1754
    debug_info_flag= 1;
973.202.15 by jani at inet
Fixed a bug in mysql client.
1755
    break;
1756
  case 's':
1757
    if (argument == disabled_my_option)
1758
      opt_silent= 0;
1759
    else
1760
      opt_silent++;
1761
    break;
1762
  case 'v':
1763
    if (argument == disabled_my_option)
1764
      verbose= 0;
1765
    else
1766
      verbose++;
1767
    break;
1768
  case 'B':
1616.354.1 by serg at serg
mysql.cc:
1769
    status.batch= 1;
1770
    status.add_to_history= 0;
1616.354.2 by serg at serg
don't let -B increment opt_silent twice
1771
    set_if_bigger(opt_silent,1);                         // more silent
973.202.15 by jani at inet
Fixed a bug in mysql client.
1772
    break;
1773
  case 'W':
2 by bk at mysql
Import changeset
1774
#ifdef __WIN__
1354.36.1 by wax at mysql
Add shared memory protocol and option --protocol
1775
    opt_protocol = MYSQL_PROTOCOL_PIPE;
2 by bk at mysql
Import changeset
1776
#endif
973.202.15 by jani at inet
Fixed a bug in mysql client.
1777
    break;
1288.1.1 by monty at mysql
Changed table_list->name -> table_list->alias to find places where we where using alias instead of table_name.
1778
#include <sslopt-case.h>
973.202.15 by jani at inet
Fixed a bug in mysql client.
1779
  case 'V':
1780
    usage(1);
1781
    exit(0);
1782
  case 'I':
1783
  case '?':
1784
    usage(0);
1785
    exit(0);
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1786
  }
1787
  return 0;
1788
}
1789
1790
1791
static int get_options(int argc, char **argv)
1792
{
1793
  char *tmp, *pagpoint;
1794
  int ho_error;
1346.564.125 by hf at deer
Fix to make Windows compilation smoother
1795
  MYSQL_PARAMETERS *mysql_params= mysql_get_parameters();
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1796
1797
  tmp= (char *) getenv("MYSQL_HOST");
1798
  if (tmp)
1799
    current_host= my_strdup(tmp, MYF(MY_WME));
1800
1801
  pagpoint= getenv("PAGER");
1802
  if (!((char*) (pagpoint)))
1803
  {
1804
    strmov(pager, "stdout");
1805
    opt_nopager= 1;
1806
  }
1807
  else
1808
    strmov(pager, pagpoint);
1809
  strmov(default_pager, pager);
1810
1346.564.125 by hf at deer
Fix to make Windows compilation smoother
1811
  opt_max_allowed_packet= *mysql_params->p_max_allowed_packet;
1812
  opt_net_buffer_length= *mysql_params->p_net_buffer_length;
1813
1346.652.110 by ram at r18
Added global my_getopt_error_reporter function pointer which is
1814
  if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
973.202.6 by jani at hynda
Added useful exit error code for programs using my_getopt in case
1815
    exit(ho_error);
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1816
1346.564.125 by hf at deer
Fix to make Windows compilation smoother
1817
  *mysql_params->p_max_allowed_packet= opt_max_allowed_packet;
1818
  *mysql_params->p_net_buffer_length= opt_net_buffer_length;
1819
254.2.1 by jani at mysql
New mysql client.
1820
  if (status.batch) /* disable pager and outfile in this case */
1821
  {
1822
    strmov(default_pager, "stdout");
1823
    strmov(pager, "stdout");
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1824
    opt_nopager= 1;
1616.75.4 by jani at netsonic
- Added missing documentation to some mysql.cc options.
1825
    default_pager_set= 0;
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1826
    opt_outfile= 0;
1490 by papa at gbichot
Added options reconnect/enable-reconnect/disable-reconnect/skip-reconnect to the 'mysql' command-line client.
1827
    opt_reconnect= 0;
1165 by jani at netsonic
Fixed a bug in mysql when running in non-interactive mode (batch)
1828
    connect_flag= 0; /* Not in interactive mode */
254.2.1 by jani at mysql
New mysql client.
1829
  }
1810.1512.2 by serg at mysql
mysql.cc:
1830
  
1616.62.68 by bar at r18
mysqlimport.c, mysqldump.c, mysqlcheck.c, mysql.cc:
1831
  if (strcmp(default_charset, charset_info->csname) &&
1832
      !(charset_info= get_charset_by_csname(default_charset, 
1538.1.3 by bar at r18
mysqlimport.c, mysqldump.c, mysqlcheck.c:
1833
					    MY_CS_PRIMARY, MYF(MY_WME))))
1494.8.12 by root at home
mysqltest.c, mysqlimport.c, mysqldump.c, mysqlcheck.c, mysql.cc:
1834
    exit(1);
2 by bk at mysql
Import changeset
1835
  if (argc > 1)
1836
  {
1837
    usage(0);
1838
    exit(1);
1839
  }
1840
  if (argc == 1)
1841
  {
1346.129.53 by jani at hynda
Fixed a bug in --one-database.
1842
    skip_updates= 0;
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1843
    my_free(current_db, MYF(MY_ALLOW_ZERO_PTR));
1844
    current_db= my_strdup(*argv, MYF(MY_WME));
2 by bk at mysql
Import changeset
1845
  }
1846
  if (tty_password)
973.123.1 by jani at mysql
Changed mysql, mysqladmin, mysqlshow, mysqldump, mysqlimport,
1847
    opt_password= get_tty_password(NullS);
2476.284.5 by monty at mysql
Fixes Bug#30127: --debug-info no longer prints memory usage in mysql
1848
  if (debug_info_flag)
1849
    my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
1850
  if (debug_check_flag)
1851
    my_end_arg= MY_CHECK_ERROR;
1810.3888.7 by Jim Winstead
Fix support for -i (--ignore-spaces) in the mysql command line application,
1852
1853
  if (ignore_spaces)
1854
    connect_flag|= CLIENT_IGNORE_SPACE;
1855
2 by bk at mysql
Import changeset
1856
  return(0);
1857
}
1858
1810.562.1 by jimw at mysql
Fix 'source' command in mysql client to handle delimiter command
1859
static int read_and_execute(bool interactive)
2 by bk at mysql
Import changeset
1860
{
2119.378.35 by brian at zim
Final patch to remove the last of the OS2 support.
1861
#if defined(__NETWARE__)
2 by bk at mysql
Import changeset
1862
  char linebuffer[254];
1616.2004.2 by jimw at mysql
Fix use of _cgets() to handle an input line that exceeds our buffer space
1863
  String buffer;
2 by bk at mysql
Import changeset
1864
#endif
1616.2286.1 by SergeyV at selena
Fixes bug #12929. Uses my_cgets instead of _cgets function, thus eliminating
1865
#if defined(__WIN__)
1866
  String tmpbuf;
1867
  String buffer;
1868
#endif
1869
2 by bk at mysql
Import changeset
1870
  char	*line;
1871
  char	in_string=0;
1872
  ulong line_number=0;
1403.16.1 by jani at inet
mysql multiline comment, by Sergey Gluhov.
1873
  bool ml_comment= 0;  
2 by bk at mysql
Import changeset
1874
  COMMANDS *com;
1875
  status.exit_status=1;
3452.51.13 by Dmitry Shulga
Fixed bug#57450 - mysql client enter in an infinite loop
1876
2 by bk at mysql
Import changeset
1877
  for (;;)
1878
  {
1810.562.1 by jimw at mysql
Fix 'source' command in mysql client to handle delimiter command
1879
    if (!interactive)
2 by bk at mysql
Import changeset
1880
    {
3452.51.13 by Dmitry Shulga
Fixed bug#57450 - mysql client enter in an infinite loop
1881
      line=batch_readline(status.line_buff);
1810.3456.8 by bar at mysql
Bug#29323 mysql client only accetps ANSI encoded files
1882
      /*
1883
        Skip UTF8 Byte Order Marker (BOM) 0xEFBBBF.
1884
        Editors like "notepad" put this marker in
1885
        the very beginning of a text file when
1886
        you save the file using "Unicode UTF-8" format.
1887
      */
2646.1.12 by Tatiana A. Nurnberg
Bug#35480: BOM detection code crashes mysql CLI with zero-sized input
1888
      if (line && !line_number &&
1810.3456.8 by bar at mysql
Bug#29323 mysql client only accetps ANSI encoded files
1889
           (uchar) line[0] == 0xEF &&
1890
           (uchar) line[1] == 0xBB &&
1891
           (uchar) line[2] == 0xBF)
1892
        line+= 3;
2 by bk at mysql
Import changeset
1893
      line_number++;
1894
      if (!glob_buffer.length())
1895
	status.query_start_line=line_number;
1896
    }
1897
    else
263.1.1 by jani at mysql
Bug fix to mysql.cc for windows version.
1898
    {
1616.1907.1 by jimw at mysql
Change mysql prompt while inside a multiline comment. (Bug #9186)
1899
      char *prompt= (char*) (ml_comment ? "   /*> " :
1900
                             glob_buffer.is_empty() ?  construct_prompt() :
1346.96.3 by monty at mysql
Fixes for Netware
1901
			     !in_string ? "    -> " :
1902
			     in_string == '\'' ?
1346.361.4 by jani at netsonic
Fixed Bug#1291, client displays wrong prompt when in the middle of
1903
			     "    '> " : (in_string == '`' ?
1904
			     "    `> " :
1905
			     "    \"> "));
274.1.1 by monty at mysql
Split error message for crashed table to 3 different error messages.
1906
      if (opt_outfile && glob_buffer.is_empty())
1907
	fflush(OUTFILE);
1346.96.3 by monty at mysql
Fixes for Netware
1908
3089 by Davi Arnaut
Fix for a few assorted compiler warnings.
1909
#if defined(__WIN__) || defined(__NETWARE__)
1346.96.3 by monty at mysql
Fixes for Netware
1910
      tee_fputs(prompt, stdout);
1616.2286.1 by SergeyV at selena
Fixes bug #12929. Uses my_cgets instead of _cgets function, thus eliminating
1911
#if defined(__NETWARE__)
1346.96.3 by monty at mysql
Fixes for Netware
1912
      line=fgets(linebuffer, sizeof(linebuffer)-1, stdin);
1913
      /* Remove the '\n' */
1346.623.1 by monty at mysql
Added patches from Novell
1914
      if (line)
263.1.1 by jani at mysql
Bug fix to mysql.cc for windows version.
1915
      {
1346.96.3 by monty at mysql
Fixes for Netware
1916
        char *p = strrchr(line, '\n');
1346.159.1 by greg at mysql
Post-4.0.12 changes from Novell: mostly NetWare-related code changes to utilize new LibC
1917
        if (p != NULL)
1918
          *p = '\0';
263.1.1 by jani at mysql
Bug fix to mysql.cc for windows version.
1919
      }
3089 by Davi Arnaut
Fix for a few assorted compiler warnings.
1920
#else
1616.2286.1 by SergeyV at selena
Fixes bug #12929. Uses my_cgets instead of _cgets function, thus eliminating
1921
      if (!tmpbuf.is_alloced())
1922
        tmpbuf.alloc(65535);
1810.872.35 by reggie at ugeek
readd the my_cgets call that SergeyV originally put in
1923
      tmpbuf.length(0);
1616.2286.1 by SergeyV at selena
Fixes bug #12929. Uses my_cgets instead of _cgets function, thus eliminating
1924
      buffer.length(0);
2475.68.2 by monty at mysql
WL#3817: Simplify string / memory area types and make things more consistent (first part)
1925
      size_t clen;
1616.2286.1 by SergeyV at selena
Fixes bug #12929. Uses my_cgets instead of _cgets function, thus eliminating
1926
      do
1927
      {
1810.872.35 by reggie at ugeek
readd the my_cgets call that SergeyV originally put in
1928
	line= my_cgets((char*)tmpbuf.ptr(), tmpbuf.alloced_length()-1, &clen);
1616.2286.1 by SergeyV at selena
Fixes bug #12929. Uses my_cgets instead of _cgets function, thus eliminating
1929
        buffer.append(line, clen);
1930
        /* 
1931
           if we got buffer fully filled than there is a chance that
1932
           something else is still in console input buffer
1933
        */
1616.2302.4 by monty at mysql
Fixed error found during review of new pushed code
1934
      } while (tmpbuf.alloced_length() <= clen);
1810.3151.1 by kgeorge at magare
Bug #29469: Client dies if a query is issued after hitting Ctrl + C
1935
      /* 
1936
        An empty line is returned from my_cgets when there's error reading :
1937
        Ctrl-c for example
1938
      */
1939
      if (line)
1940
        line= buffer.c_ptr();
1346.96.3 by monty at mysql
Fixes for Netware
1941
#endif /* __NETWARE__ */
1942
#else
1943
      if (opt_outfile)
1944
	fputs(prompt, OUTFILE);
1945
      line= readline(prompt);
3089 by Davi Arnaut
Fix for a few assorted compiler warnings.
1946
#endif /* defined(__WIN__) || defined(__NETWARE__) */
1346.96.3 by monty at mysql
Fixes for Netware
1947
1346.623.1 by monty at mysql
Added patches from Novell
1948
      /*
1949
        When Ctrl+d or Ctrl+z is pressed, the line may be NULL on some OS
1950
        which may cause coredump.
1951
      */
1952
      if (opt_outfile && line)
259 by jani at mysql
Fixed bug in mysql client.
1953
	fprintf(OUTFILE, "%s\n", line);
254.2.1 by jani at mysql
New mysql client.
1954
    }
3452.51.13 by Dmitry Shulga
Fixed bug#57450 - mysql client enter in an infinite loop
1955
    // End of file or system error
1956
    if (!line)
2 by bk at mysql
Import changeset
1957
    {
3452.51.13 by Dmitry Shulga
Fixed bug#57450 - mysql client enter in an infinite loop
1958
      if (status.line_buff && status.line_buff->error)
1959
        status.exit_status= 1;
1960
      else
1961
        status.exit_status= 0;
2 by bk at mysql
Import changeset
1962
      break;
1963
    }
1964
1009 by monty at mysql
Big code cleanup/review before 4.0.2 release.
1965
    /*
1966
      Check if line is a mysql command line
1967
      (We want to allow help, print and clear anywhere at line start
1968
    */
1810.562.1 by jimw at mysql
Fix 'source' command in mysql client to handle delimiter command
1969
    if ((named_cmds || glob_buffer.is_empty())
1616.2665.2 by tnurnberg at mysql
Bug#20432: mysql client interprets commands in comments
1970
	&& !ml_comment && !in_string && (com=find_command(line,0)))
2 by bk at mysql
Import changeset
1971
    {
1972
      if ((*com->func)(&glob_buffer,line) > 0)
1973
	break;
1974
      if (glob_buffer.is_empty())		// If buffer was emptied
1975
	in_string=0;
1976
#ifdef HAVE_READLINE
1810.562.1 by jimw at mysql
Fix 'source' command in mysql client to handle delimiter command
1977
      if (interactive && status.add_to_history && not_in_history(line))
2 by bk at mysql
Import changeset
1978
	add_history(line);
1979
#endif
1980
      continue;
1981
    }
3452.51.13 by Dmitry Shulga
Fixed bug#57450 - mysql client enter in an infinite loop
1982
    if (add_line(glob_buffer, line, &in_string, &ml_comment,
1983
                 status.line_buff ? status.line_buff->truncated : 0))
2 by bk at mysql
Import changeset
1984
      break;
1985
  }
1986
  /* if in batch mode, send last query even if it doesn't end with \g or go */
1987
1810.562.1 by jimw at mysql
Fix 'source' command in mysql client to handle delimiter command
1988
  if (!interactive && !status.exit_status)
2 by bk at mysql
Import changeset
1989
  {
1990
    remove_cntrl(glob_buffer);
1991
    if (!glob_buffer.is_empty())
1992
    {
1993
      status.exit_status=1;
1994
      if (com_go(&glob_buffer,line) <= 0)
1995
	status.exit_status=0;
1996
    }
1997
  }
1616.2286.1 by SergeyV at selena
Fixes bug #12929. Uses my_cgets instead of _cgets function, thus eliminating
1998
3089 by Davi Arnaut
Fix for a few assorted compiler warnings.
1999
#if defined(__WIN__) || defined(__NETWARE__)
1616.2004.2 by jimw at mysql
Fix use of _cgets() to handle an input line that exceeds our buffer space
2000
  buffer.free();
2001
#endif
3089 by Davi Arnaut
Fix for a few assorted compiler warnings.
2002
#if defined(__WIN__)
1616.2286.1 by SergeyV at selena
Fixes bug #12929. Uses my_cgets instead of _cgets function, thus eliminating
2003
  tmpbuf.free();
2004
#endif
2005
2 by bk at mysql
Import changeset
2006
  return status.exit_status;
2007
}
2008
2009
1810.854.1 by monty at mysql
Review of code pushed since last 5.0 pull:
2010
static COMMANDS *find_command(char *name,char cmd_char)
2 by bk at mysql
Import changeset
2011
{
2012
  uint len;
2013
  char *end;
1810.854.1 by monty at mysql
Review of code pushed since last 5.0 pull:
2014
  DBUG_ENTER("find_command");
2015
  DBUG_PRINT("enter",("name: '%s'  char: %d", name ? name : "NULL", cmd_char));
2 by bk at mysql
Import changeset
2016
2017
  if (!name)
2018
  {
2019
    len=0;
2020
    end=0;
2021
  }
2022
  else
2023
  {
1494.8.12 by root at home
mysqltest.c, mysqlimport.c, mysqldump.c, mysqlcheck.c, mysql.cc:
2024
    while (my_isspace(charset_info,*name))
2 by bk at mysql
Import changeset
2025
      name++;
1764.28.20 by jani at omakaista
Fixed Bug#8922.
2026
    /*
1810.854.1 by monty at mysql
Review of code pushed since last 5.0 pull:
2027
      If there is an \\g in the row or if the row has a delimiter but
2028
      this is not a delimiter command, let add_line() take care of
2029
      parsing the row and calling find_command()
1764.28.20 by jani at omakaista
Fixed Bug#8922.
2030
    */
2031
    if (strstr(name, "\\g") || (strstr(name, delimiter) &&
1810.980.1 by tim at hindu
BUG#14358: in mysql.cc, don't neglect to strip delimiter off lines < 9 characters long.
2032
                                !(strlen(name) >= 9 &&
1810.3910.2 by Sergey Glukhov
Bug#37268 'binary' character set makes CLI-internal commands case sensitive
2033
                                  !my_strnncoll(&my_charset_latin1,
1810.980.1 by tim at hindu
BUG#14358: in mysql.cc, don't neglect to strip delimiter off lines < 9 characters long.
2034
                                                (uchar*) name, 9,
2035
                                                (const uchar*) "delimiter",
2036
                                                9))))
1810.854.1 by monty at mysql
Review of code pushed since last 5.0 pull:
2037
      DBUG_RETURN((COMMANDS *) 0);
2 by bk at mysql
Import changeset
2038
    if ((end=strcont(name," \t")))
2039
    {
2040
      len=(uint) (end - name);
1494.8.12 by root at home
mysqltest.c, mysqlimport.c, mysqldump.c, mysqlcheck.c, mysql.cc:
2041
      while (my_isspace(charset_info,*end))
2 by bk at mysql
Import changeset
2042
	end++;
2043
      if (!*end)
2044
	end=0;					// no arguments to function
2045
    }
2046
    else
38.1.1 by monty at mysql
FLUSH TABLE table_list
2047
      len=(uint) strlen(name);
2 by bk at mysql
Import changeset
2048
  }
2049
2050
  for (uint i= 0; commands[i].name; i++)
2051
  {
2052
    if (commands[i].func &&
1810.854.1 by monty at mysql
Review of code pushed since last 5.0 pull:
2053
	((name &&
1810.3910.2 by Sergey Glukhov
Bug#37268 'binary' character set makes CLI-internal commands case sensitive
2054
	  !my_strnncoll(&my_charset_latin1, (uchar*)name, len,
1504.1.7 by bar at r18
my_strncasecmp() is not used anymore. Use my_strncoll() instead.
2055
				     (uchar*)commands[i].name,len) &&
2 by bk at mysql
Import changeset
2056
	  !commands[i].name[len] &&
2057
	  (!end || (end && commands[i].takes_params))) ||
1810.3918.16 by Staale Smedseng
Merge from 5.0-bt
2058
	 (!name && commands[i].cmd_char == cmd_char)))
1810.854.1 by monty at mysql
Review of code pushed since last 5.0 pull:
2059
    {
2060
      DBUG_PRINT("exit",("found command: %s", commands[i].name));
2061
      DBUG_RETURN(&commands[i]);
2062
    }
2 by bk at mysql
Import changeset
2063
  }
1810.854.1 by monty at mysql
Review of code pushed since last 5.0 pull:
2064
  DBUG_RETURN((COMMANDS *) 0);
2 by bk at mysql
Import changeset
2065
}
2066
2067
1403.16.1 by jani at inet
mysql multiline comment, by Sergey Gluhov.
2068
static bool add_line(String &buffer,char *line,char *in_string,
1810.3863.1 by Alexey Kopytov
Fix for bug#41486: extra character appears in BLOB for every
2069
                     bool *ml_comment, bool truncated)
2 by bk at mysql
Import changeset
2070
{
2071
  uchar inchar;
1504.20.16 by jani at hynda
Added --delimiter option to mysql
2072
  char buff[80], *pos, *out;
2 by bk at mysql
Import changeset
2073
  COMMANDS *com;
1773.241.38 by antony at mysql
Bug#6925
2074
  bool need_space= 0;
1810.3289.8 by kaa at polly
Bug #30164: Using client side macro inside server side comments generates broken queries
2075
  bool ss_comment= 0;
1810.854.1 by monty at mysql
Review of code pushed since last 5.0 pull:
2076
  DBUG_ENTER("add_line");
2 by bk at mysql
Import changeset
2077
2078
  if (!line[0] && buffer.is_empty())
1810.854.1 by monty at mysql
Review of code pushed since last 5.0 pull:
2079
    DBUG_RETURN(0);
2 by bk at mysql
Import changeset
2080
#ifdef HAVE_READLINE
1616.159.39 by harrison at lordblink
Fix up history in readline implementation.
2081
  if (status.add_to_history && line[0] && not_in_history(line))
2 by bk at mysql
Import changeset
2082
    add_history(line);
2083
#endif
1810.854.1 by monty at mysql
Review of code pushed since last 5.0 pull:
2084
  char *end_of_line=line+(uint) strlen(line);
2 by bk at mysql
Import changeset
2085
2086
  for (pos=out=line ; (inchar= (uchar) *pos) ; pos++)
2087
  {
1810.3428.1 by kaa at polly
Fix for:
2088
    if (!preserve_comments)
2089
    {
1810.3807.1 by Chad MILLER
Bug#33812: mysql client incorrectly parsing DELIMITER
2090
      // Skip spaces at the beginning of a statement
1810.3428.1 by kaa at polly
Fix for:
2091
      if (my_isspace(charset_info,inchar) && (out == line) &&
2092
          buffer.is_empty())
2093
        continue;
2094
    }
2095
        
2 by bk at mysql
Import changeset
2096
#ifdef USE_MB
1810.3428.1 by kaa at polly
Fix for:
2097
    // Accept multi-byte characters as-is
1810.854.1 by monty at mysql
Review of code pushed since last 5.0 pull:
2098
    int length;
1494.8.12 by root at home
mysqltest.c, mysqlimport.c, mysqldump.c, mysqlcheck.c, mysql.cc:
2099
    if (use_mb(charset_info) &&
1810.862.18 by bar at mysql
mysql.cc:
2100
        (length= my_ismbchar(charset_info, pos, end_of_line)))
1616.2355.1 by bar at mysql
Bug#13487 Japanese data inside a comment causes the syntax error
2101
    {
1810.3428.1 by kaa at polly
Fix for:
2102
      if (!*ml_comment || preserve_comments)
1616.2355.1 by bar at mysql
Bug#13487 Japanese data inside a comment causes the syntax error
2103
      {
1810.862.18 by bar at mysql
mysql.cc:
2104
        while (length--)
1616.2355.1 by bar at mysql
Bug#13487 Japanese data inside a comment causes the syntax error
2105
          *out++ = *pos++;
2106
        pos--;
2107
      }
2108
      else
1810.862.18 by bar at mysql
mysql.cc:
2109
        pos+= length - 1;
1616.2355.1 by bar at mysql
Bug#13487 Japanese data inside a comment causes the syntax error
2110
      continue;
2 by bk at mysql
Import changeset
2111
    }
2112
#endif
1810.1927.1 by kgeorge at macbook
Bug #20103: Escaping with backslash does not work
2113
    if (!*ml_comment && inchar == '\\' &&
2748.1.1 by Alfranio Correia
BUG#36391: "mysqlbinlog creates invalid charset statements"
2114
        !(*in_string && 
2115
          (mysql.server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES)))
1504.20.16 by jani at hynda
Added --delimiter option to mysql
2116
    {
2117
      // Found possbile one character command like \c
2118
2 by bk at mysql
Import changeset
2119
      if (!(inchar = (uchar) *++pos))
2120
	break;				// readline adds one '\'
676.137.1 by monty at mysql
Fixed bug in INSERT DELAYED
2121
      if (*in_string || inchar == 'N')	// \N is short for NULL
2 by bk at mysql
Import changeset
2122
      {					// Don't allow commands in string
2123
	*out++='\\';
2124
	*out++= (char) inchar;
2125
	continue;
2126
      }
2127
      if ((com=find_command(NullS,(char) inchar)))
2128
      {
1810.3428.1 by kaa at polly
Fix for:
2129
        // Flush previously accepted characters
2130
        if (out != line)
2131
        {
2132
          buffer.append(line, (uint) (out-line));
2133
          out= line;
2134
        }
2135
        
1810.3289.8 by kaa at polly
Bug #30164: Using client side macro inside server side comments generates broken queries
2136
        if ((*com->func)(&buffer,pos-1) > 0)
2137
          DBUG_RETURN(1);                       // Quit
2138
        if (com->takes_params)
2139
        {
2140
          if (ss_comment)
2141
          {
2142
            /*
2143
              If a client-side macro appears inside a server-side comment,
2144
              discard all characters in the comment after the macro (that is,
2145
              until the end of the comment rather than the next delimiter)
2146
            */
2147
            for (pos++; *pos && (*pos != '*' || *(pos + 1) != '/'); pos++)
2148
              ;
2149
            pos--;
2150
          }
2151
          else
2152
          {
2153
            for (pos++ ;
2154
                 *pos && (*pos != *delimiter ||
2155
                          !is_prefix(pos + 1, delimiter + 1)) ; pos++)
2156
              ;	// Remove parameters
2157
            if (!*pos)
2158
              pos--;
2159
            else 
2160
              pos+= delimiter_length - 1; // Point at last delim char
2161
          }
2162
        }
2 by bk at mysql
Import changeset
2163
      }
2164
      else
2165
      {
2166
	sprintf(buff,"Unknown command '\\%c'.",inchar);
2167
	if (put_info(buff,INFO_ERROR) > 0)
1810.854.1 by monty at mysql
Review of code pushed since last 5.0 pull:
2168
	  DBUG_RETURN(1);
2 by bk at mysql
Import changeset
2169
	*out++='\\';
2170
	*out++=(char) inchar;
2171
	continue;
2172
      }
2173
    }
1810.3428.1 by kaa at polly
Fix for:
2174
    else if (!*ml_comment && !*in_string && is_prefix(pos, delimiter))
2175
    {
2176
      // Found a statement. Continue parsing after the delimiter
2177
      pos+= delimiter_length;
2178
2179
      if (preserve_comments)
2180
      {
2181
        while (my_isspace(charset_info, *pos))
2182
          *out++= *pos++;
2183
      }
2184
      // Flush previously accepted characters
2185
      if (out != line)
2186
      {
2187
        buffer.append(line, (uint32) (out-line));
2188
        out= line;
2189
      }
2190
2191
      if (preserve_comments && ((*pos == '#') ||
2192
                                ((*pos == '-') &&
2193
                                 (pos[1] == '-') &&
2194
                                 my_isspace(charset_info, pos[2]))))
2195
      {
2196
        // Add trailing single line comments to this statement
2197
        buffer.append(pos);
2198
        pos+= strlen(pos);
2199
      }
2200
2201
      pos--;
2202
1504.20.16 by jani at hynda
Added --delimiter option to mysql
2203
      if ((com= find_command(buffer.c_ptr(), 0)))
2 by bk at mysql
Import changeset
2204
      {
1810.3428.1 by kaa at polly
Fix for:
2205
          
2206
        if ((*com->func)(&buffer, buffer.c_ptr()) > 0)
2207
          DBUG_RETURN(1);                       // Quit 
2 by bk at mysql
Import changeset
2208
      }
2209
      else
2210
      {
1810.3428.1 by kaa at polly
Fix for:
2211
        if (com_go(&buffer, 0) > 0)             // < 0 is not fatal
2212
          DBUG_RETURN(1);
2 by bk at mysql
Import changeset
2213
      }
2214
      buffer.length(0);
2215
    }
1403.16.1 by jani at inet
mysql multiline comment, by Sergey Gluhov.
2216
    else if (!*ml_comment && (!*in_string && (inchar == '#' ||
1810.3918.16 by Staale Smedseng
Merge from 5.0-bt
2217
                                              (inchar == '-' && pos[1] == '-' &&
1810.3733.9 by Gleb Shchepa
Bug #36244: MySQL CLI doesn't recognize standalone --
2218
                              /*
2219
                                The third byte is either whitespace or is the
2220
                                end of the line -- which would occur only
2221
                                because of the user sending newline -- which is
2222
                                itself whitespace and should also match.
2223
                              */
2224
			      (my_isspace(charset_info,pos[2]) ||
1810.3918.16 by Staale Smedseng
Merge from 5.0-bt
2225
                               !pos[2])))))
1810.3428.1 by kaa at polly
Fix for:
2226
    {
2227
      // Flush previously accepted characters
2228
      if (out != line)
2229
      {
2230
        buffer.append(line, (uint32) (out - line));
2231
        out= line;
2232
      }
2233
2234
      // comment to end of line
2235
      if (preserve_comments)
1810.3807.1 by Chad MILLER
Bug#33812: mysql client incorrectly parsing DELIMITER
2236
      {
2237
        bool started_with_nothing= !buffer.length();
2238
1810.3428.1 by kaa at polly
Fix for:
2239
        buffer.append(pos);
2240
1810.3807.1 by Chad MILLER
Bug#33812: mysql client incorrectly parsing DELIMITER
2241
        /*
2242
          A single-line comment by itself gets sent immediately so that
2243
          client commands (delimiter, status, etc) will be interpreted on
2244
          the next line.
2245
        */
2246
        if (started_with_nothing)
2247
        {
2248
          if (com_go(&buffer, 0) > 0)             // < 0 is not fatal
2249
            DBUG_RETURN(1);
2250
          buffer.length(0);
2251
        }
2252
      }
2253
1810.3428.1 by kaa at polly
Fix for:
2254
      break;
2255
    }
1504.20.16 by jani at hynda
Added --delimiter option to mysql
2256
    else if (!*in_string && inchar == '/' && *(pos+1) == '*' &&
2257
	     *(pos+2) != '!')
1403.16.1 by jani at inet
mysql multiline comment, by Sergey Gluhov.
2258
    {
1810.3428.1 by kaa at polly
Fix for:
2259
      if (preserve_comments)
2260
      {
2261
        *out++= *pos++;                       // copy '/'
2262
        *out++= *pos;                         // copy '*'
2263
      }
2264
      else
2265
        pos++;
1403.16.1 by jani at inet
mysql multiline comment, by Sergey Gluhov.
2266
      *ml_comment= 1;
2267
      if (out != line)
2268
      {
2269
        buffer.append(line,(uint) (out-line));
2270
        out=line;
2271
      }
2272
    }
1810.3289.8 by kaa at polly
Bug #30164: Using client side macro inside server side comments generates broken queries
2273
    else if (*ml_comment && !ss_comment && inchar == '*' && *(pos + 1) == '/')
1403.16.1 by jani at inet
mysql multiline comment, by Sergey Gluhov.
2274
    {
1810.3428.1 by kaa at polly
Fix for:
2275
      if (preserve_comments)
2276
      {
2277
        *out++= *pos++;                       // copy '*'
2278
        *out++= *pos;                         // copy '/'
2279
      }
2280
      else
2281
        pos++;
1403.16.1 by jani at inet
mysql multiline comment, by Sergey Gluhov.
2282
      *ml_comment= 0;
1810.3428.1 by kaa at polly
Fix for:
2283
      if (out != line)
2284
      {
2285
        buffer.append(line, (uint32) (out - line));
2286
        out= line;
2287
      }
2288
      // Consumed a 2 chars or more, and will add 1 at most,
2289
      // so using the 'line' buffer to edit data in place is ok.
1773.241.38 by antony at mysql
Bug#6925
2290
      need_space= 1;
1403.16.1 by jani at inet
mysql multiline comment, by Sergey Gluhov.
2291
    }      
2 by bk at mysql
Import changeset
2292
    else
2293
    {						// Add found char to buffer
1810.3289.8 by kaa at polly
Bug #30164: Using client side macro inside server side comments generates broken queries
2294
      if (!*in_string && inchar == '/' && *(pos + 1) == '*' &&
2295
          *(pos + 2) == '!')
2296
        ss_comment= 1;
2297
      else if (!*in_string && ss_comment && inchar == '*' && *(pos + 1) == '/')
2298
        ss_comment= 0;
2 by bk at mysql
Import changeset
2299
      if (inchar == *in_string)
1546.16.10 by ram at r18
mysql should ignore ' " ` symbols inside comments (Bug #539).
2300
	*in_string= 0;
1546.21.1 by ram at r18
bugfix for the bugfix for the bug #539
2301
      else if (!*ml_comment && !*in_string &&
2302
	       (inchar == '\'' || inchar == '"' || inchar == '`'))
2303
	*in_string= (char) inchar;
1810.3428.1 by kaa at polly
Fix for:
2304
      if (!*ml_comment || preserve_comments)
1773.241.38 by antony at mysql
Bug#6925
2305