~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.cc

  • Committer: Monty Taylor
  • Date: 2009-04-14 19:16:51 UTC
  • mto: (997.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 994.
  • Revision ID: mordred@inaugust.com-20090414191651-ltbww6hpqks8k7qk
Clarified instructions in README.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 
36
36
#include "client_priv.h"
37
37
#include <string>
38
 
#include <drizzled/gettext.h>
39
 
#include <iostream>
40
 
#include <map>
41
38
#include <algorithm>
42
 
#include <limits.h>
43
 
#include <cassert>
44
 
#include "drizzled/charset_info.h"
 
39
#include <mystrings/m_ctype.h>
45
40
#include <stdarg.h>
46
 
#include <math.h>
47
 
#include "client/linebuffer.h"
 
41
#include "my_readline.h"
48
42
#include <signal.h>
49
43
#include <sys/ioctl.h>
50
44
#include <drizzled/configmake.h>
51
 
#include "drizzled/charset.h"
52
45
 
53
46
#if defined(HAVE_CURSES_H) && defined(HAVE_TERM_H)
54
47
#include <curses.h>
89
82
#  endif /* !defined(HAVE_READLINE_H) */
90
83
char *cmdline = NULL;
91
84
#else /* !defined(HAVE_READLINE_READLINE_H) */
92
 
/* no readline */
 
85
  /* no readline */
93
86
#  error Readline Required
94
87
#endif /* HAVE_LIBREADLINE */
95
88
 
103
96
extern int write_history ();
104
97
extern int read_history ();
105
98
#  endif /* defined(HAVE_READLINE_HISTORY_H) */
106
 
/* no history */
 
99
    /* no history */
107
100
#endif /* HAVE_READLINE_HISTORY */
108
101
 
 
102
#define DRIZZLE_DEFAULT_INPUT_LINE 65536
 
103
 
109
104
/**
110
 
  Make the old readline interface look like the new one.
 
105
 Make the old readline interface look like the new one.
111
106
*/
112
 
#ifndef HAVE_RL_COMPLETION
113
 
typedef char **rl_completion_func_t(const char *, int, int);
 
107
#ifndef USE_NEW_READLINE_INTERFACE
 
108
typedef CPPFunction rl_completion_func_t;
 
109
typedef Function rl_compentry_func_t;
114
110
#define rl_completion_matches(str, func) \
115
111
  completion_matches((char *)str, (CPFunction *)func)
116
112
#endif
117
113
 
118
 
#ifdef HAVE_RL_COMPENTRY
119
 
# ifdef HAVE_WORKING_RL_COMPENTRY
120
 
typedef rl_compentry_func_t drizzle_compentry_func_t;
121
 
# else
122
 
/* Snow Leopard ships an rl_compentry which cannot be assigned to
123
 
 * rl_completion_entry_function. We must undo the complete and total
124
 
 * ass-bagery.
125
 
 */
126
 
typedef Function drizzle_compentry_func_t;
127
 
# endif
128
 
#else
129
 
typedef Function drizzle_compentry_func_t;
130
 
#endif
131
 
 
132
114
#if defined(HAVE_LOCALE_H)
133
115
#include <locale.h>
134
116
#endif
135
117
 
 
118
#include <drizzled/gettext.h>
 
119
 
 
120
 
 
121
void* sql_alloc(unsigned size);       // Don't use drizzled alloc for these
 
122
void sql_element_free(void *ptr);
136
123
 
137
124
 
138
125
#if !defined(HAVE_VIDATTR)
140
127
#define vidattr(A) {}      // Can't get this to work
141
128
#endif
142
129
 
143
 
using namespace drizzled;
 
130
#include <iostream>
 
131
#include <map>
 
132
 
144
133
using namespace std;
145
134
 
146
135
const string VER("14.14");
158
147
  int exit_status;
159
148
  uint32_t query_start_line;
160
149
  char *file_name;
161
 
  LineBuffer *line_buff;
 
150
  LINE_BUFFER *line_buff;
162
151
  bool batch,add_to_history;
163
152
} STATUS;
164
153
 
176
165
static drizzle_st drizzle;      /* The library handle */
177
166
static drizzle_con_st con;      /* The connection */
178
167
static bool ignore_errors= false, quick= false,
179
 
            connected= false, opt_raw_data= false, unbuffered= false,
180
 
            output_tables= false, opt_rehash= true, skip_updates= false,
181
 
            safe_updates= false, one_database= false,
182
 
            opt_compress= false, opt_shutdown= false, opt_ping= false,
183
 
            vertical= false, line_numbers= true, column_names= true,
184
 
            opt_nopager= true, opt_outfile= false, named_cmds= false,
185
 
            tty_password= false, opt_nobeep= false, opt_reconnect= true,
186
 
            default_charset_used= false, opt_secure_auth= false,
187
 
            default_pager_set= false, opt_sigint_ignore= false,
188
 
            auto_vertical_output= false,
189
 
            show_warnings= false, executing_query= false, interrupted_query= false,
190
 
            opt_mysql= false;
 
168
  connected= false, opt_raw_data= false, unbuffered= false,
 
169
  output_tables= false, opt_rehash= true, skip_updates= false,
 
170
  safe_updates= false, one_database= false,
 
171
  opt_compress= false, opt_shutdown= false, opt_ping= false,
 
172
  vertical= false, line_numbers= true, column_names= true,
 
173
  opt_nopager= true, opt_outfile= false, named_cmds= false,
 
174
  tty_password= false, opt_nobeep= false, opt_reconnect= true,
 
175
  default_charset_used= false, opt_secure_auth= false,
 
176
  default_pager_set= false, opt_sigint_ignore= false,
 
177
  auto_vertical_output= false,
 
178
  show_warnings= false, executing_query= false, interrupted_query= false;
191
179
static uint32_t  show_progress_size= 0;
 
180
static bool debug_info_flag, debug_check_flag;
192
181
static bool column_types_flag;
193
182
static bool preserve_comments= false;
194
183
static uint32_t opt_max_input_line, opt_drizzle_port= 0;
195
184
static int verbose= 0, opt_silent= 0, opt_local_infile= 0;
 
185
static uint32_t my_end_arg;
 
186
static char * opt_drizzle_unix_port= NULL;
196
187
static drizzle_capabilities_t connect_flag= DRIZZLE_CAPABILITIES_NONE;
197
188
static char *current_host, *current_db, *current_user= NULL,
198
 
            *opt_password= NULL, *delimiter_str= NULL, *current_prompt= NULL;
 
189
  *opt_password= NULL, *delimiter_str= NULL, *current_prompt= NULL;
199
190
static char *histfile;
200
191
static char *histfile_tmp;
201
192
static string *glob_buffer;
209
200
// TODO: Need to i18n these
210
201
static const char *day_names[]= {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
211
202
static const char *month_names[]= {"Jan","Feb","Mar","Apr","May","Jun","Jul",
212
 
  "Aug","Sep","Oct","Nov","Dec"};
 
203
                                  "Aug","Sep","Oct","Nov","Dec"};
213
204
static char default_pager[FN_REFLEN];
214
205
static char pager[FN_REFLEN], outfile[FN_REFLEN];
215
206
static FILE *PAGER, *OUTFILE;
233
224
static void tee_print_sized_data(const char *, unsigned int, unsigned int, bool);
234
225
/* The names of functions that actually do the manipulation. */
235
226
static int get_options(int argc,char **argv);
 
227
extern "C" bool get_one_option(int optid, const struct my_option *opt,
 
228
                               char *argument);
236
229
static int com_quit(string *str,const char*),
237
 
           com_go(string *str,const char*), com_ego(string *str,const char*),
238
 
           com_print(string *str,const char*),
239
 
           com_help(string *str,const char*), com_clear(string *str,const char*),
240
 
           com_connect(string *str,const char*), com_status(string *str,const char*),
241
 
           com_use(string *str,const char*), com_source(string *str, const char*),
242
 
           com_rehash(string *str, const char*), com_tee(string *str, const char*),
243
 
           com_notee(string *str, const char*),
244
 
           com_prompt(string *str, const char*), com_delimiter(string *str, const char*),
245
 
           com_warnings(string *str, const char*), com_nowarnings(string *str, const char*),
246
 
           com_nopager(string *str, const char*), com_pager(string *str, const char*);
 
230
  com_go(string *str,const char*), com_ego(string *str,const char*),
 
231
  com_print(string *str,const char*),
 
232
  com_help(string *str,const char*), com_clear(string *str,const char*),
 
233
  com_connect(string *str,const char*), com_status(string *str,const char*),
 
234
  com_use(string *str,const char*), com_source(string *str, const char*),
 
235
  com_rehash(string *str, const char*), com_tee(string *str, const char*),
 
236
  com_notee(string *str, const char*),
 
237
  com_prompt(string *str, const char*), com_delimiter(string *str, const char*),
 
238
  com_warnings(string *str, const char*), com_nowarnings(string *str, const char*),
 
239
  com_nopager(string *str, const char*), com_pager(string *str, const char*);
247
240
 
248
241
static int read_and_execute(bool interactive);
249
242
static int sql_connect(char *host,char *database,char *user,char *password,
266
259
static const char * strcont(register const char *str, register const char *set);
267
260
 
268
261
/* A structure which contains information on the commands this program
269
 
  can understand. */
 
262
   can understand. */
270
263
typedef struct {
271
264
  const char *name;        /* User printable name of the function. */
272
265
  char cmd_char;        /* msql command character */
280
273
  { "?",      '?', com_help,   0, N_("Synonym for `help'.") },
281
274
  { "clear",  'c', com_clear,  0, N_("Clear command.")},
282
275
  { "connect",'r', com_connect,1,
283
 
    N_("Reconnect to the server. Optional arguments are db and host.")},
 
276
    N_("Reconnect to the server. Optional arguments are db and host." }),
284
277
  { "delimiter", 'd', com_delimiter,    1,
285
278
    N_("Set statement delimiter. NOTE: Takes the rest of the line as new delimiter.") },
286
279
  { "ego",    'G', com_ego,    0,
732
725
  { "TIMESTAMP", 0, 0, 0, ""},
733
726
  { "TIMESTAMPADD", 0, 0, 0, ""},
734
727
  { "TIMESTAMPDIFF", 0, 0, 0, ""},
 
728
  { "TINYINT", 0, 0, 0, ""},
735
729
  { "TINYTEXT", 0, 0, 0, ""},
736
730
  { "TO", 0, 0, 0, ""},
737
731
  { "TRAILING", 0, 0, 0, ""},
799
793
  { "ATAN2", 0, 0, 0, ""},
800
794
  { "BENCHMARK", 0, 0, 0, ""},
801
795
  { "BIN", 0, 0, 0, ""},
 
796
  { "BIT_COUNT", 0, 0, 0, ""},
802
797
  { "BIT_OR", 0, 0, 0, ""},
803
798
  { "BIT_AND", 0, 0, 0, ""},
804
799
  { "BIT_XOR", 0, 0, 0, ""},
805
800
  { "CAST", 0, 0, 0, ""},
806
801
  { "CEIL", 0, 0, 0, ""},
807
802
  { "CEILING", 0, 0, 0, ""},
 
803
  { "BIT_LENGTH", 0, 0, 0, ""},
808
804
  { "CENTROID", 0, 0, 0, ""},
809
805
  { "CHAR_LENGTH", 0, 0, 0, ""},
810
806
  { "CHARACTER_LENGTH", 0, 0, 0, ""},
1023
1019
static void window_resize(int sig);
1024
1020
#endif
1025
1021
 
 
1022
static inline int is_prefix(const char *s, const char *t)
 
1023
{
 
1024
  while (*t)
 
1025
    if (*s++ != *t++) return 0;
 
1026
  return 1;                                     /* WRONG */
 
1027
}
 
1028
 
1026
1029
/**
1027
1030
  Shutdown the server that we are currently connected to.
1028
1031
 
1029
1032
  @retval
1030
 
  true success
 
1033
    true success
1031
1034
  @retval
1032
 
  false failure
 
1035
    false failure
1033
1036
*/
1034
1037
static bool server_shutdown(void)
1035
1038
{
1073
1076
  Ping the server that we are currently connected to.
1074
1077
 
1075
1078
  @retval
1076
 
  true success
 
1079
    true success
1077
1080
  @retval
1078
 
  false failure
 
1081
    false failure
1079
1082
*/
1080
1083
static bool server_ping(void)
1081
1084
{
1110
1113
  Execute command(s) specified by the user.
1111
1114
 
1112
1115
  @param error  error status of command execution.
1113
 
  If an error had occurred, this variable will be set
1114
 
  to 1 whereas on success, it shall be set to 0. This
1115
 
  value will be supplied to the exit() function used
1116
 
  by the caller.
 
1116
                If an error had occurred, this variable will be set
 
1117
                to 1 whereas on success, it shall be set to 0. This
 
1118
                value will be supplied to the exit() function used
 
1119
                by the caller.
1117
1120
 
1118
1121
  @retval
1119
 
  false no commands were executed
 
1122
    false no commands were executed
1120
1123
  @retval
1121
 
  true  at least one command was executed
 
1124
    true  at least one command was executed
1122
1125
*/
1123
1126
static bool execute_commands(int *error)
1124
1127
{
1143
1146
 
1144
1147
int main(int argc,char *argv[])
1145
1148
{
 
1149
  char buff[80];
 
1150
 
1146
1151
#if defined(ENABLE_NLS)
1147
1152
# if defined(HAVE_LOCALE_H)
1148
1153
  setlocale(LC_ALL, "");
1156
1161
  default_prompt= strdup(getenv("DRIZZLE_PS1") ?
1157
1162
                         getenv("DRIZZLE_PS1") :
1158
1163
                         "drizzle> ");
1159
 
 
 
1164
  
1160
1165
  if (default_prompt == NULL)
1161
1166
  {
1162
1167
    fprintf(stderr, _("Memory allocation error while constructing initial "
1208
1213
      close(stdout_fileno_copy);             /* Clean up dup(). */
1209
1214
  }
1210
1215
 
1211
 
  internal::load_defaults("drizzle",load_default_groups,&argc,&argv);
 
1216
  load_defaults("drizzle",load_default_groups,&argc,&argv);
1212
1217
  defaults_argv=argv;
1213
1218
  if (get_options(argc, (char **) argv))
1214
1219
  {
1215
 
    internal::free_defaults(defaults_argv);
1216
 
    internal::my_end();
 
1220
    free_defaults(defaults_argv);
 
1221
    my_end(0);
1217
1222
    exit(1);
1218
1223
  }
1219
1224
 
1230
1235
  if (execute_commands(&command_error) != false)
1231
1236
  {
1232
1237
    /* we've executed a command so exit before we go into readline mode */
1233
 
    internal::free_defaults(defaults_argv);
1234
 
    internal::my_end();
 
1238
    free_defaults(defaults_argv);
 
1239
    my_end(0);
1235
1240
    exit(command_error);
1236
1241
  }
1237
1242
 
1238
1243
  if (status.batch && !status.line_buff)
1239
1244
  {
1240
 
    status.line_buff= new(std::nothrow) LineBuffer(opt_max_input_line, stdin);
 
1245
    status.line_buff =batch_readline_init(opt_max_input_line+512, stdin);
1241
1246
    if (status.line_buff == NULL)
1242
1247
    {
1243
 
      internal::free_defaults(defaults_argv);
1244
 
      internal::my_end();
 
1248
      free_defaults(defaults_argv);
 
1249
      my_end(0);
1245
1250
      exit(1);
1246
1251
    }
1247
1252
  }
1268
1273
  glob_buffer= new string();
1269
1274
  glob_buffer->reserve(512);
1270
1275
 
1271
 
  ostringstream output_buff;
1272
 
  output_buff << _("Your Drizzle connection id is ");
1273
 
  output_buff << drizzle_con_thread_id(&con);
1274
 
  output_buff << "\n";
1275
 
  output_buff << _("Server version: ");
1276
 
  output_buff << server_version_string(&con) << "\n";
1277
 
  put_info(output_buff.str().c_str(), INFO_INFO, 0, 0);
 
1276
  char * output_buff= (char *)malloc(512);
 
1277
  memset(output_buff, '\0', 512);
 
1278
 
 
1279
  sprintf(output_buff,
 
1280
          _("Your Drizzle connection id is %u\nServer version: %s\n"),
 
1281
          drizzle_con_thread_id(&con),
 
1282
          server_version_string(&con));
 
1283
  put_info(output_buff, INFO_INFO, 0, 0);
1278
1284
 
1279
1285
  initialize_readline(current_prompt);
1280
1286
  if (!status.batch && !quick)
1284
1290
      histfile= strdup(getenv("DRIZZLE_HISTFILE"));
1285
1291
    else if (getenv("HOME"))
1286
1292
    {
1287
 
      size_t histfile_size = strlen(getenv("HOME")) +
1288
 
        strlen("/.drizzle_history") + 2;
1289
 
      histfile=(char*) malloc(histfile_size);
 
1293
      histfile=(char*) malloc(strlen(getenv("HOME")) + strlen("/.drizzle_history") + 2);
1290
1294
      if (histfile)
1291
 
        snprintf(histfile, histfile_size, "%s/.drizzle_history",getenv("HOME"));
 
1295
        sprintf(histfile,"%s/.drizzle_history",getenv("HOME"));
1292
1296
      char link_name[FN_REFLEN];
1293
 
      ssize_t sym_link_size= readlink(histfile,link_name,FN_REFLEN-1);
1294
 
      if (sym_link_size >= 0)
 
1297
      if (my_readlink(link_name, histfile, 0) == 0 &&
 
1298
          strncmp(link_name, "/dev/null", 10) == 0)
1295
1299
      {
1296
 
        link_name[sym_link_size]= '\0';
1297
 
        if (strncmp(link_name, "/dev/null", 10) == 0)
1298
 
        {
1299
 
          /* The .drizzle_history file is a symlink to /dev/null, don't use it */
1300
 
          free(histfile);
1301
 
          histfile= 0;
1302
 
        }
 
1300
        /* The .drizzle_history file is a symlink to /dev/null, don't use it */
 
1301
        free(histfile);
 
1302
        histfile= 0;
1303
1303
      }
1304
1304
    }
1305
1305
    if (histfile)
1307
1307
      if (verbose)
1308
1308
        tee_fprintf(stdout, _("Reading history-file %s\n"),histfile);
1309
1309
      read_history(histfile);
1310
 
      size_t histfile_tmp_size = strlen(histfile) + 5;
1311
 
      if (!(histfile_tmp= (char*) malloc(histfile_tmp_size)))
 
1310
      if (!(histfile_tmp= (char*) malloc((uint32_t) strlen(histfile) + 5)))
1312
1311
      {
1313
1312
        fprintf(stderr, _("Couldn't allocate memory for temp histfile!\n"));
1314
1313
        exit(1);
1315
1314
      }
1316
 
      snprintf(histfile_tmp, histfile_tmp_size, "%s.TMP", histfile);
 
1315
      sprintf(histfile_tmp, "%s.TMP", histfile);
1317
1316
    }
1318
1317
  }
 
1318
  sprintf(buff, "%s",
 
1319
          _("Type 'help;' or '\\h' for help. Type '\\c' to clear the buffer.\n"));
1319
1320
 
1320
 
  put_info(_("Type 'help;' or '\\h' for help. "
1321
 
             "Type '\\c' to clear the buffer.\n"),INFO_INFO,0,0);
 
1321
  put_info(buff,INFO_INFO,0,0);
1322
1322
  status.exit_status= read_and_execute(!status.batch);
1323
1323
  if (opt_outfile)
1324
1324
    end_tee();
1337
1337
    if (verbose)
1338
1338
      tee_fprintf(stdout, _("Writing history-file %s\n"),histfile);
1339
1339
    if (!write_history(histfile_tmp))
1340
 
      internal::my_rename(histfile_tmp, histfile, MYF(MY_WME));
 
1340
      my_rename(histfile_tmp, histfile, MYF(MY_WME));
1341
1341
  }
1342
 
  delete status.line_buff;
1343
 
  status.line_buff= 0;
 
1342
  batch_readline_end(status.line_buff);
1344
1343
 
1345
1344
  if (sig >= 0)
1346
1345
    put_info(sig ? _("Aborted") : _("Bye"), INFO_RESULT,0,0);
1349
1348
  if (processed_prompt)
1350
1349
    delete processed_prompt;
1351
1350
  free(opt_password);
 
1351
  free(opt_drizzle_unix_port);
1352
1352
  free(histfile);
1353
1353
  free(histfile_tmp);
1354
1354
  free(current_db);
1358
1358
  free(part_username);
1359
1359
  free(default_prompt);
1360
1360
  free(current_prompt);
1361
 
  internal::free_defaults(defaults_argv);
1362
 
  internal::my_end();
 
1361
  free_defaults(defaults_argv);
 
1362
  my_end(my_end_arg);
1363
1363
  exit(status.exit_status);
1364
1364
}
1365
1365
 
1384
1384
 
1385
1385
  if (drizzle_con_add_tcp(&drizzle, &kill_drizzle, current_host,
1386
1386
                          opt_drizzle_port, current_user, opt_password, NULL,
1387
 
                          opt_mysql ? DRIZZLE_CON_MYSQL : DRIZZLE_CON_NONE) == NULL)
 
1387
                          DRIZZLE_CON_NONE) == NULL)
1388
1388
  {
1389
1389
    goto err;
1390
1390
  }
1391
1391
 
1392
1392
  /* kill_buffer is always big enough because max length of %lu is 15 */
1393
 
  snprintf(kill_buffer, sizeof(kill_buffer), "KILL /*!50000 QUERY */ %u",
1394
 
           drizzle_con_thread_id(&con));
 
1393
  sprintf(kill_buffer, "KILL /*!50000 QUERY */ %u",
 
1394
          drizzle_con_thread_id(&con));
1395
1395
 
1396
1396
  if (drizzle_query_str(&kill_drizzle, &res, kill_buffer, &ret) != NULL)
1397
1397
    drizzle_result_free(&res);
1418
1418
}
1419
1419
#endif
1420
1420
 
1421
 
static struct option my_long_options[] =
 
1421
static struct my_option my_long_options[] =
1422
1422
{
1423
1423
  {"help", '?', N_("Display this help and exit."), 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
1424
 
    0, 0, 0, 0, 0},
 
1424
   0, 0, 0, 0, 0},
1425
1425
  {"help", 'I', N_("Synonym for -?"), 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
1426
 
    0, 0, 0, 0, 0},
 
1426
   0, 0, 0, 0, 0},
1427
1427
  {"auto-rehash", OPT_AUTO_REHASH,
1428
 
    N_("Enable automatic rehashing. One doesn't need to use 'rehash' to get table and field completion, but startup and reconnecting may take a longer time. Disable with --disable-auto-rehash."),
1429
 
    (char**) &opt_rehash, (char**) &opt_rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
1430
 
    0, 0},
 
1428
   N_("Enable automatic rehashing. One doesn't need to use 'rehash' to get table and field completion, but startup and reconnecting may take a longer time. Disable with --disable-auto-rehash."),
 
1429
   (char**) &opt_rehash, (char**) &opt_rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
 
1430
   0, 0},
1431
1431
  {"no-auto-rehash", 'A',
1432
 
    N_("No automatic rehashing. One has to use 'rehash' to get table and field completion. This gives a quicker start of drizzle_st and disables rehashing on reconnect. WARNING: options deprecated; use --disable-auto-rehash instead."),
1433
 
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1432
   N_("No automatic rehashing. One has to use 'rehash' to get table and field completion. This gives a quicker start of drizzle_st and disables rehashing on reconnect. WARNING: options deprecated; use --disable-auto-rehash instead."),
 
1433
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1434
1434
  {"auto-vertical-output", OPT_AUTO_VERTICAL_OUTPUT,
1435
 
    N_("Automatically switch to vertical output mode if the result is wider than the terminal width."),
1436
 
    (char**) &auto_vertical_output, (char**) &auto_vertical_output, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1435
   N_("Automatically switch to vertical output mode if the result is wider than the terminal width."),
 
1436
   (char**) &auto_vertical_output, (char**) &auto_vertical_output, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1437
1437
  {"batch", 'B',
1438
 
    N_("Don't use history file. Disable interactive behavior. (Enables --silent)"), 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1438
   N_("Don't use history file. Disable interactive behavior. (Enables --silent)"), 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1439
1439
  {"column-type-info", OPT_COLUMN_TYPES, N_("Display column type information."),
1440
 
    (char**) &column_types_flag, (char**) &column_types_flag,
1441
 
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1440
   (char**) &column_types_flag, (char**) &column_types_flag,
 
1441
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1442
1442
  {"comments", 'c', N_("Preserve comments. Send comments to the server. The default is --skip-comments (discard comments), enable with --comments"),
1443
 
    (char**) &preserve_comments, (char**) &preserve_comments,
1444
 
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1443
   (char**) &preserve_comments, (char**) &preserve_comments,
 
1444
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1445
1445
  {"compress", 'C', N_("Use compression in server/client protocol."),
1446
 
    (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
1447
 
    0, 0, 0},
 
1446
   (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
1447
   0, 0, 0},
 
1448
  {"debug-check", OPT_DEBUG_CHECK, N_("Check memory and open file usage at exit ."),
 
1449
   (char**) &debug_check_flag, (char**) &debug_check_flag, 0,
 
1450
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1451
  {"debug-info", 'T', N_("Print some debug info at exit."), (char**) &debug_info_flag,
 
1452
   (char**) &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1448
1453
  {"database", 'D', N_("Database to use."), (char**) &current_db,
1449
 
    (char**) &current_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1454
   (char**) &current_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1450
1455
  {"default-character-set", OPT_DEFAULT_CHARSET,
1451
 
    N_("(not used)"), 0,
1452
 
    0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1456
   N_("(not used)"), 0,
 
1457
   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1453
1458
  {"delimiter", OPT_DELIMITER, N_("Delimiter to be used."), (char**) &delimiter_str,
1454
 
    (char**) &delimiter_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1459
   (char**) &delimiter_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1455
1460
  {"execute", 'e', N_("Execute command and quit. (Disables --force and history file)"), 0,
1456
 
    0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1461
   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1457
1462
  {"vertical", 'E', N_("Print the output of a query (rows) vertically."),
1458
 
    (char**) &vertical, (char**) &vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
1459
 
    0},
 
1463
   (char**) &vertical, (char**) &vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
 
1464
   0},
1460
1465
  {"force", 'f', N_("Continue even if we get an sql error."),
1461
 
    (char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
1462
 
    0, 0, 0, 0},
 
1466
   (char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
 
1467
   0, 0, 0, 0},
1463
1468
  {"named-commands", 'G',
1464
 
    N_("Enable named commands. Named commands mean this program's internal commands; see drizzle> help . When enabled, the named commands can be used from any line of the query, otherwise only from the first line, before an enter. Disable with --disable-named-commands. This option is disabled by default."),
1465
 
    (char**) &named_cmds, (char**) &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1466
 
    0, 0},
 
1469
   N_("Enable named commands. Named commands mean this program's internal commands; see drizzle> help . When enabled, the named commands can be used from any line of the query, otherwise only from the first line, before an enter. Disable with --disable-named-commands. This option is disabled by default."),
 
1470
   (char**) &named_cmds, (char**) &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
1471
   0, 0},
1467
1472
  {"no-named-commands", 'g',
1468
 
    N_("Named commands are disabled. Use \\* form only, or use named commands only in the beginning of a line ending with a semicolon (;) Since version 10.9 the client now starts with this option ENABLED by default! Disable with '-G'. Long format commands still work from the first line. WARNING: option deprecated; use --disable-named-commands instead."),
1469
 
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1473
   N_("Named commands are disabled. Use \\* form only, or use named commands only in the beginning of a line ending with a semicolon (;) Since version 10.9 the client now starts with this option ENABLED by default! Disable with '-G'. Long format commands still work from the first line. WARNING: option deprecated; use --disable-named-commands instead."),
 
1474
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1470
1475
  {"ignore-spaces", 'i', N_("Ignore space after function names."), 0, 0, 0,
1471
 
    GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1476
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1472
1477
  {"local-infile", OPT_LOCAL_INFILE, N_("Enable/disable LOAD DATA LOCAL INFILE."),
1473
 
    (char**) &opt_local_infile,
1474
 
    (char**) &opt_local_infile, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
1478
   (char**) &opt_local_infile,
 
1479
   (char**) &opt_local_infile, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
1475
1480
  {"no-beep", 'b', N_("Turn off beep on error."), (char**) &opt_nobeep,
1476
 
    (char**) &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1481
   (char**) &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1477
1482
  {"host", 'h', N_("Connect to host."), (char**) &current_host,
1478
 
    (char**) &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1483
   (char**) &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1479
1484
  {"line-numbers", OPT_LINE_NUMBERS, N_("Write line numbers for errors."),
1480
 
    (char**) &line_numbers, (char**) &line_numbers, 0, GET_BOOL,
1481
 
    NO_ARG, 1, 0, 0, 0, 0, 0},
 
1485
   (char**) &line_numbers, (char**) &line_numbers, 0, GET_BOOL,
 
1486
   NO_ARG, 1, 0, 0, 0, 0, 0},
1482
1487
  {"skip-line-numbers", 'L', N_("Don't write line number for errors. WARNING: -L is deprecated, use long version of this option instead."), 0, 0, 0, GET_NO_ARG,
1483
 
    NO_ARG, 0, 0, 0, 0, 0, 0},
 
1488
   NO_ARG, 0, 0, 0, 0, 0, 0},
1484
1489
  {"unbuffered", 'n', N_("Flush buffer after each query."), (char**) &unbuffered,
1485
 
    (char**) &unbuffered, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1490
   (char**) &unbuffered, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1486
1491
  {"column-names", OPT_COLUMN_NAMES, N_("Write column names in results."),
1487
 
    (char**) &column_names, (char**) &column_names, 0, GET_BOOL,
1488
 
    NO_ARG, 1, 0, 0, 0, 0, 0},
 
1492
   (char**) &column_names, (char**) &column_names, 0, GET_BOOL,
 
1493
   NO_ARG, 1, 0, 0, 0, 0, 0},
1489
1494
  {"skip-column-names", 'N',
1490
 
    N_("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."),
1491
 
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1495
   N_("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."),
 
1496
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1492
1497
  {"set-variable", 'O',
1493
 
    N_("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value."),
1494
 
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1498
   N_("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value."),
 
1499
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1495
1500
  {"sigint-ignore", OPT_SIGINT_IGNORE, N_("Ignore SIGINT (CTRL-C)"),
1496
 
    (char**) &opt_sigint_ignore,  (char**) &opt_sigint_ignore, 0, GET_BOOL,
1497
 
    NO_ARG, 0, 0, 0, 0, 0, 0},
 
1501
   (char**) &opt_sigint_ignore,  (char**) &opt_sigint_ignore, 0, GET_BOOL,
 
1502
   NO_ARG, 0, 0, 0, 0, 0, 0},
1498
1503
  {"one-database", 'o',
1499
 
    N_("Only update the default database. This is useful for skipping updates to other database in the update log."),
1500
 
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1504
   N_("Only update the default database. This is useful for skipping updates to other database in the update log."),
 
1505
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1501
1506
  {"pager", OPT_PAGER,
1502
 
    N_("Pager to use to display results. If you don't supply an option the default pager is taken from your ENV variable PAGER. Valid pagers are less, more, cat [> filename], etc. See interactive help (\\h) also. This option does not work in batch mode. Disable with --disable-pager. This option is disabled by default."),
1503
 
    0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
1507
   N_("Pager to use to display results. If you don't supply an option the default pager is taken from your ENV variable PAGER. Valid pagers are less, more, cat [> filename], etc. See interactive help (\\h) also. This option does not work in batch mode. Disable with --disable-pager. This option is disabled by default."),
 
1508
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
1504
1509
  {"no-pager", OPT_NOPAGER,
1505
 
    N_("Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead."),
1506
 
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1510
   N_("Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead."),
 
1511
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1507
1512
  {"password", 'P',
1508
 
    N_("Password to use when connecting to server. If password is not given it's asked from the tty."),
1509
 
    0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
1513
   N_("Password to use when connecting to server. If password is not given it's asked from the tty."),
 
1514
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
1510
1515
  {"port", 'p', N_("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, ")
1511
 
    N_("built-in default") " (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
1512
 
    0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1516
   N_("built-in default") " (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
 
1517
   0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1513
1518
  {"prompt", OPT_PROMPT, N_("Set the drizzle prompt to this value."),
1514
 
    (char**) &current_prompt, (char**) &current_prompt, 0, GET_STR_ALLOC,
1515
 
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1519
   (char**) &current_prompt, (char**) &current_prompt, 0, GET_STR_ALLOC,
 
1520
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1516
1521
  {"quick", 'q',
1517
 
    N_("Don't cache result, print it row by row. This may slow down the server if the output is suspended. Doesn't use history file."),
1518
 
    (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1522
   N_("Don't cache result, print it row by row. This may slow down the server if the output is suspended. Doesn't use history file."),
 
1523
   (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1519
1524
  {"raw", 'r', N_("Write fields without conversion. Used with --batch."),
1520
 
    (char**) &opt_raw_data, (char**) &opt_raw_data, 0, GET_BOOL, NO_ARG, 0, 0, 0,
1521
 
    0, 0, 0},
 
1525
   (char**) &opt_raw_data, (char**) &opt_raw_data, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
1526
   0, 0, 0},
1522
1527
  {"reconnect", OPT_RECONNECT, N_("Reconnect if the connection is lost. Disable with --disable-reconnect. This option is enabled by default."),
1523
 
    (char**) &opt_reconnect, (char**) &opt_reconnect, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
 
1528
   (char**) &opt_reconnect, (char**) &opt_reconnect, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
1524
1529
  {"shutdown", OPT_SHUTDOWN, N_("Shutdown the server."),
1525
 
    (char**) &opt_shutdown, (char**) &opt_shutdown, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1530
   (char**) &opt_shutdown, (char**) &opt_shutdown, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1526
1531
  {"silent", 's', N_("Be more silent. Print results with a tab as separator, each row on new line."), 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0,
1527
 
    0, 0},
 
1532
   0, 0},
 
1533
  {"socket", 'S', N_("Socket file to use for connection."),
 
1534
   (char**) &opt_drizzle_unix_port, (char**) &opt_drizzle_unix_port, 0, GET_STR_ALLOC,
 
1535
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1528
1536
  {"table", 't', N_("Output in table format."), (char**) &output_tables,
1529
 
    (char**) &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1537
   (char**) &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1530
1538
  {"tee", OPT_TEE,
1531
 
    N_("Append everything into outfile. See interactive help (\\h) also. Does not work in batch mode. Disable with --disable-tee. This option is disabled by default."),
1532
 
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1539
   N_("Append everything into outfile. See interactive help (\\h) also. Does not work in batch mode. Disable with --disable-tee. This option is disabled by default."),
 
1540
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1533
1541
  {"no-tee", OPT_NOTEE, N_("Disable outfile. See interactive help (\\h) also. WARNING: option deprecated; use --disable-tee instead"), 0, 0, 0, GET_NO_ARG,
1534
 
    NO_ARG, 0, 0, 0, 0, 0, 0},
 
1542
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
1543
#ifndef DONT_ALLOW_USER_CHANGE
1535
1544
  {"user", 'u', N_("User for login if not current user."), (char**) &current_user,
1536
 
    (char**) &current_user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1545
   (char**) &current_user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1546
#endif
1537
1547
  {"safe-updates", 'U', N_("Only allow UPDATE and DELETE that uses keys."),
1538
 
    (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
1539
 
    0, 0, 0, 0},
 
1548
   (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
 
1549
   0, 0, 0, 0},
1540
1550
  {"i-am-a-dummy", 'U', N_("Synonym for option --safe-updates, -U."),
1541
 
    (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
1542
 
    0, 0, 0, 0},
 
1551
   (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
 
1552
   0, 0, 0, 0},
1543
1553
  {"verbose", 'v', N_("Write more. (-v -v -v gives the table output format)."), 0,
1544
 
    0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1554
   0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1545
1555
  {"version", 'V', N_("Output version information and exit."), 0, 0, 0,
1546
 
    GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1556
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1547
1557
  {"wait", 'w', N_("Wait and retry if connection is down."), 0, 0, 0, GET_NO_ARG,
1548
 
    NO_ARG, 0, 0, 0, 0, 0, 0},
 
1558
   NO_ARG, 0, 0, 0, 0, 0, 0},
1549
1559
  {"connect_timeout", OPT_CONNECT_TIMEOUT,
1550
 
    N_("Number of seconds before connection timeout."),
1551
 
    (char**) &opt_connect_timeout,
1552
 
    (char**) &opt_connect_timeout, 0, GET_UINT32, REQUIRED_ARG, 0, 0, 3600*12, 0,
1553
 
    0, 0},
 
1560
   N_("Number of seconds before connection timeout."),
 
1561
   (char**) &opt_connect_timeout,
 
1562
   (char**) &opt_connect_timeout, 0, GET_UINT32, REQUIRED_ARG, 0, 0, 3600*12, 0,
 
1563
   0, 0},
1554
1564
  {"max_input_line", OPT_MAX_INPUT_LINE,
1555
 
    N_("Max length of input line"),
1556
 
    (char**) &opt_max_input_line, (char**) &opt_max_input_line, 0,
1557
 
    GET_UINT32, REQUIRED_ARG, 16 *1024L*1024L, 4096,
1558
 
    (int64_t) 2*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
 
1565
   N_("Max length of input line"),
 
1566
   (char**) &opt_max_input_line, (char**) &opt_max_input_line, 0,
 
1567
   GET_UINT32, REQUIRED_ARG, 16 *1024L*1024L, 4096,
 
1568
   (int64_t) 2*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
1559
1569
  {"select_limit", OPT_SELECT_LIMIT,
1560
 
    N_("Automatic limit for SELECT when using --safe-updates"),
1561
 
    (char**) &select_limit,
1562
 
    (char**) &select_limit, 0, GET_UINT32, REQUIRED_ARG, 1000L, 1, ULONG_MAX,
1563
 
    0, 1, 0},
 
1570
   N_("Automatic limit for SELECT when using --safe-updates"),
 
1571
   (char**) &select_limit,
 
1572
   (char**) &select_limit, 0, GET_UINT32, REQUIRED_ARG, 1000L, 1, ULONG_MAX,
 
1573
   0, 1, 0},
1564
1574
  {"max_join_size", OPT_MAX_JOIN_SIZE,
1565
 
    N_("Automatic limit for rows in a join when using --safe-updates"),
1566
 
    (char**) &max_join_size,
1567
 
    (char**) &max_join_size, 0, GET_UINT32, REQUIRED_ARG, 1000000L, 1, ULONG_MAX,
1568
 
    0, 1, 0},
 
1575
   N_("Automatic limit for rows in a join when using --safe-updates"),
 
1576
   (char**) &max_join_size,
 
1577
   (char**) &max_join_size, 0, GET_UINT32, REQUIRED_ARG, 1000000L, 1, ULONG_MAX,
 
1578
   0, 1, 0},
1569
1579
  {"secure-auth", OPT_SECURE_AUTH, N_("Refuse client connecting to server if it uses old (pre-4.1.1) protocol"), (char**) &opt_secure_auth,
1570
 
    (char**) &opt_secure_auth, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1580
   (char**) &opt_secure_auth, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1571
1581
  {"show-warnings", OPT_SHOW_WARNINGS, N_("Show warnings after every statement."),
1572
 
    (char**) &show_warnings, (char**) &show_warnings, 0, GET_BOOL, NO_ARG,
1573
 
    0, 0, 0, 0, 0, 0},
 
1582
   (char**) &show_warnings, (char**) &show_warnings, 0, GET_BOOL, NO_ARG,
 
1583
   0, 0, 0, 0, 0, 0},
1574
1584
  {"show-progress-size", OPT_SHOW_PROGRESS_SIZE, N_("Number of lines before each import progress report."),
1575
 
    (char**) &show_progress_size, (char**) &show_progress_size, 0, GET_UINT32, REQUIRED_ARG,
1576
 
    0, 0, 0, 0, 0, 0},
 
1585
   (char**) &show_progress_size, (char**) &show_progress_size, 0, GET_UINT32, REQUIRED_ARG,
 
1586
   0, 0, 0, 0, 0, 0},
1577
1587
  {"ping", OPT_PING, N_("Ping the server to check if it's alive."),
1578
 
    (char**) &opt_ping, (char**) &opt_ping, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1579
 
  {"mysql", 'm', N_("Use MySQL Protocol."),
1580
 
    (char**) &opt_mysql, (char**) &opt_mysql, 0, GET_BOOL, NO_ARG, 1, 0, 0,
1581
 
    0, 0, 0},
 
1588
   (char**) &opt_ping, (char**) &opt_ping, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1582
1589
  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
1583
1590
};
1584
1591
 
1587
1594
{
1588
1595
  const char* readline= "readline";
1589
1596
 
1590
 
  printf(_("%s  Ver %s Distrib %s, for %s-%s (%s) using %s %s\n"),
1591
 
         internal::my_progname, VER.c_str(), drizzle_version(),
1592
 
         HOST_VENDOR, HOST_OS, HOST_CPU,
 
1597
  printf(_("%s  Ver %s Distrib %s, for %s (%s) using %s %s\n"),
 
1598
         my_progname, VER.c_str(), drizzle_version(),
 
1599
         SYSTEM_TYPE, MACHINE_TYPE,
1593
1600
         readline, rl_library_version);
1594
1601
 
1595
1602
  if (version)
1599
1606
           "This is free software,\n"
1600
1607
           "and you are welcome to modify and redistribute it "
1601
1608
           "under the GPL license\n"));
1602
 
  printf(_("Usage: %s [OPTIONS] [database]\n"), internal::my_progname);
 
1609
  printf(_("Usage: %s [OPTIONS] [database]\n"), my_progname);
1603
1610
  my_print_help(my_long_options);
1604
 
  internal::print_defaults("drizzle", load_default_groups);
 
1611
  print_defaults("drizzle", load_default_groups);
1605
1612
  my_print_variables(my_long_options);
1606
1613
}
1607
1614
 
1608
1615
 
1609
 
static int get_one_option(int optid, const struct option *, char *argument)
 
1616
extern "C" bool
 
1617
get_one_option(int optid, const struct my_option *, char *argument)
1610
1618
{
1611
1619
  char *endchar= NULL;
1612
1620
  uint64_t temp_drizzle_port= 0;
1631
1639
      {
1632
1640
        put_info(_("DELIMITER cannot contain a backslash character"),
1633
1641
                 INFO_ERROR,0,0);
1634
 
        return EXIT_ARGUMENT_INVALID;
 
1642
        return false;
1635
1643
      }
1636
1644
    }
1637
1645
    delimiter_length= (uint32_t)strlen(delimiter);
1685
1693
  case 'e':
1686
1694
    status.batch= 1;
1687
1695
    status.add_to_history= 0;
1688
 
    if (status.line_buff == NULL)
1689
 
      status.line_buff= new(std::nothrow) LineBuffer(opt_max_input_line,NULL);
1690
 
    if (status.line_buff == NULL)
1691
 
    {
1692
 
      internal::my_end();
1693
 
      exit(1);
1694
 
    }
1695
 
    status.line_buff->addString(argument);
 
1696
    if (!status.line_buff)
 
1697
      ignore_errors= 0;                         // do it for the first -e only
 
1698
    if (!(status.line_buff= batch_readline_command(status.line_buff, argument)))
 
1699
      return 1;
1696
1700
    break;
1697
1701
  case 'o':
1698
1702
    if (argument == disabled_my_option)
1706
1710
    if (strlen(endchar) != 0)
1707
1711
    {
1708
1712
      put_info(_("Non-integer value supplied for port.  If you are trying to enter a password please use --password instead."), INFO_ERROR, 0, 0);
1709
 
      return EXIT_ARGUMENT_INVALID;
 
1713
      return false;
1710
1714
    }
1711
1715
    /* If the port number is > 65535 it is not a valid port
1712
 
      This also helps with potential data loss casting unsigned long to a
1713
 
      uint32_t. */
 
1716
       This also helps with potential data loss casting unsigned long to a
 
1717
       uint32_t. */
1714
1718
    if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
1715
1719
    {
1716
1720
      put_info(_("Value supplied for port is not valid."), INFO_ERROR, 0, 0);
1717
 
      return EXIT_ARGUMENT_INVALID;
 
1721
      return false;
1718
1722
    }
1719
1723
    else
1720
1724
    {
1823
1827
  }
1824
1828
  if (tty_password)
1825
1829
    opt_password= client_get_tty_password(NULL);
1826
 
 
 
1830
  if (debug_info_flag)
 
1831
    my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
 
1832
  if (debug_check_flag)
 
1833
    my_end_arg= MY_CHECK_ERROR;
1827
1834
  return(0);
1828
1835
}
1829
1836
 
1840
1847
  {
1841
1848
    if (!interactive)
1842
1849
    {
1843
 
      if (status.line_buff)
1844
 
        line= status.line_buff->readline();
1845
 
      else
1846
 
        line= 0;
1847
 
 
 
1850
      line=batch_readline(status.line_buff);
 
1851
      /*
 
1852
        Skip UTF8 Byte Order Marker (BOM) 0xEFBBBF.
 
1853
        Editors like "notepad" put this marker in
 
1854
        the very beginning of a text file when
 
1855
        you save the file using "Unicode UTF-8" format.
 
1856
      */
 
1857
      if (!line_number &&
 
1858
          (unsigned char) line[0] == 0xEF &&
 
1859
          (unsigned char) line[1] == 0xBB &&
 
1860
          (unsigned char) line[2] == 0xBF)
 
1861
        line+= 3;
1848
1862
      line_number++;
1849
1863
      if (show_progress_size > 0)
1850
1864
      {
1852
1866
          fprintf(stderr, _("Processing line: %"PRIu32"\n"), line_number);
1853
1867
      }
1854
1868
      if (!glob_buffer->empty())
1855
 
        status.query_start_line= line_number;
 
1869
        status.query_start_line=line_number;
1856
1870
    }
1857
1871
    else
1858
1872
    {
1971
1985
 
1972
1986
 
1973
1987
static bool add_line(string *buffer, char *line, char *in_string,
1974
 
                     bool *ml_comment)
 
1988
                        bool *ml_comment)
1975
1989
{
1976
1990
  unsigned char inchar;
1977
 
  char *pos, *out;
 
1991
  char buff[80], *pos, *out;
1978
1992
  COMMANDS *com;
1979
1993
  bool need_space= 0;
1980
1994
  bool ss_comment= 0;
1996
2010
        continue;
1997
2011
    }
1998
2012
 
 
2013
#ifdef USE_MB
1999
2014
    // Accept multi-byte characters as-is
2000
2015
    int length;
2001
2016
    if (use_mb(charset_info) &&
2011
2026
        pos+= length - 1;
2012
2027
      continue;
2013
2028
    }
2014
 
    if (!*ml_comment && inchar == '\\' &&
2015
 
        !(*in_string && (drizzle_con_status(&con) & DRIZZLE_CON_STATUS_NO_BACKSLASH_ESCAPES)))
 
2029
#endif
 
2030
        if (!*ml_comment && inchar == '\\' &&
 
2031
            !(*in_string && (drizzle_con_status(&con) & DRIZZLE_CON_STATUS_NO_BACKSLASH_ESCAPES)))
2016
2032
    {
2017
2033
      // Found possbile one character command like \c
2018
2034
 
2064
2080
      }
2065
2081
      else
2066
2082
      {
2067
 
        string buff(_("Unknown command: "));
2068
 
        buff.push_back('\'');
2069
 
        buff.push_back(inchar);
2070
 
        buff.push_back('\'');
2071
 
        buff.push_back('.');
2072
 
        if (put_info(buff.c_str(),INFO_ERROR,0,0) > 0)
 
2083
        sprintf(buff,_("Unknown command '\\%c'."),inchar);
 
2084
        if (put_info(buff,INFO_ERROR,0,0) > 0)
2073
2085
          return(1);
2074
2086
        *out++='\\';
2075
2087
        *out++=(char) inchar;
2240
2252
}
2241
2253
 
2242
2254
/*****************************************************************
2243
 
  Interface to Readline Completion
2244
 
 ******************************************************************/
 
2255
            Interface to Readline Completion
 
2256
******************************************************************/
2245
2257
 
2246
2258
 
2247
2259
static char **mysql_completion (const char *text, int start, int end);
2337
2349
 
2338
2350
  /* Tell the completer that we want a crack first. */
2339
2351
  rl_attempted_completion_function= (rl_completion_func_t*)&mysql_completion;
2340
 
  rl_completion_entry_function= (drizzle_compentry_func_t*)&no_completion;
 
2352
  rl_completion_entry_function= (rl_compentry_func_t*)&no_completion;
2341
2353
}
2342
2354
 
2343
2355
 
2479
2491
      if (drizzle_result_row_count(&tables) > 0 && !opt_silent && write_info)
2480
2492
      {
2481
2493
        tee_fprintf(stdout, _("\
2482
 
                              Reading table information for completion of table and column names\n    \
2483
 
                              You can turn off this feature to get a quicker startup with -A\n\n"));
 
2494
Reading table information for completion of table and column names\n    \
 
2495
You can turn off this feature to get a quicker startup with -A\n\n"));
2484
2496
      }
2485
2497
      while ((table_row=drizzle_row_next(&tables)))
2486
2498
      {
2509
2521
    query.append("show fields in '");
2510
2522
    query.append(table_row[0]);
2511
2523
    query.append("'");
2512
 
 
 
2524
    
2513
2525
    if (drizzle_query(&con, &fields, query.c_str(), query.length(),
2514
2526
                      &ret) != NULL)
2515
2527
    {
2538
2550
 
2539
2551
/* for gnu readline */
2540
2552
 
 
2553
#ifndef HAVE_INDEX
 
2554
extern "C" {
 
2555
  extern char *index(const char *,int c),*rindex(const char *,int);
 
2556
 
 
2557
  char *index(const char *s,int c)
 
2558
  {
 
2559
    for (;;)
 
2560
    {
 
2561
      if (*s == (char) c) return (char*) s;
 
2562
      if (!*s++) return NULL;
 
2563
    }
 
2564
  }
 
2565
 
 
2566
  char *rindex(const char *s,int c)
 
2567
  {
 
2568
    register char *t;
 
2569
 
 
2570
    t = NULL;
 
2571
    do if (*s == (char) c) t = (char*) s; while (*s++);
 
2572
    return (char*) t;
 
2573
  }
 
2574
}
 
2575
#endif
 
2576
 
2541
2577
 
2542
2578
static int reconnect(void)
2543
2579
{
 
2580
  /* purecov: begin tested */
2544
2581
  if (opt_reconnect)
2545
2582
  {
2546
2583
    put_info(_("No connection. Trying to reconnect..."),INFO_INFO,0,0);
2547
2584
    (void) com_connect((string *)0, 0);
2548
 
    if (opt_rehash && connected)
 
2585
    if (opt_rehash)
2549
2586
      com_rehash(NULL, NULL);
2550
2587
  }
2551
 
  if (! connected)
 
2588
  if (!connected)
2552
2589
    return put_info(_("Can't connect to the server\n"),INFO_ERROR,0,0);
 
2590
  /* purecov: end */
2553
2591
  return 0;
2554
2592
}
2555
2593
 
2569
2607
      drizzle_row_t row= drizzle_row_next(&res);
2570
2608
      if (row[0])
2571
2609
        current_db= strdup(row[0]);
2572
 
      drizzle_result_free(&res);
2573
2610
    }
 
2611
    drizzle_result_free(&res);
2574
2612
  }
2575
2613
}
2576
2614
 
2577
2615
/***************************************************************************
2578
 
  The different commands
2579
 
 ***************************************************************************/
 
2616
 The different commands
 
2617
***************************************************************************/
2580
2618
 
2581
2619
int drizzleclient_real_query_for_lazy(const char *buf, int length,
2582
2620
                                      drizzle_result_st *result,
2617
2655
    return 0;
2618
2656
 
2619
2657
  if (drizzle_con_error(&con)[0])
2620
 
  {
2621
 
    int ret = put_error(&con, result);
2622
 
    drizzle_result_free(result);
2623
 
    return ret;
2624
 
  }
 
2658
    return put_error(&con, result);
2625
2659
  return 0;
2626
2660
}
2627
2661
 
2662
2696
 
2663
2697
/*
2664
2698
  Execute command
2665
 
Returns: 0  if ok
2666
 
-1 if not fatal error
2667
 
1  if fatal error
 
2699
  Returns: 0  if ok
 
2700
  -1 if not fatal error
 
2701
  1  if fatal error
2668
2702
*/
2669
2703
static int
2670
2704
com_go(string *buffer, const char *)
2765
2799
          print_tab_data(&result);
2766
2800
        else
2767
2801
          print_table_data(&result);
2768
 
        snprintf(buff, sizeof(buff), 
2769
 
                 ngettext("%ld row in set","%ld rows in set",
2770
 
                          (long) drizzle_result_row_count(&result)),
2771
 
                 (long) drizzle_result_row_count(&result));
 
2802
        sprintf(buff,
 
2803
                ngettext("%ld row in set","%ld rows in set",
 
2804
                         (long) drizzle_result_row_count(&result)),
 
2805
                (long) drizzle_result_row_count(&result));
2772
2806
        end_pager();
2773
2807
        if (drizzle_result_error_code(&result))
2774
2808
          error= put_error(&con, &result);
2777
2811
    else if (drizzle_result_affected_rows(&result) == ~(uint64_t) 0)
2778
2812
      strcpy(buff,_("Query OK"));
2779
2813
    else
2780
 
      snprintf(buff, sizeof(buff), ngettext("Query OK, %ld row affected",
2781
 
                                            "Query OK, %ld rows affected",
2782
 
                                            (long) drizzle_result_affected_rows(&result)),
2783
 
               (long) drizzle_result_affected_rows(&result));
 
2814
      sprintf(buff, ngettext("Query OK, %ld row affected",
 
2815
                             "Query OK, %ld rows affected",
 
2816
                             (long) drizzle_result_affected_rows(&result)),
 
2817
              (long) drizzle_result_affected_rows(&result));
2784
2818
 
2785
2819
    pos= strchr(buff, '\0');
2786
2820
    if ((warnings= drizzle_result_warning_count(&result)))
2789
2823
      *pos++= ' ';
2790
2824
      char warnings_buff[20];
2791
2825
      memset(warnings_buff,0,20);
2792
 
      snprintf(warnings_buff, sizeof(warnings_buff), "%d", warnings);
 
2826
      sprintf(warnings_buff, "%d", warnings);
2793
2827
      strcpy(pos, warnings_buff);
2794
2828
      pos+= strlen(warnings_buff);
2795
2829
      pos= strcpy(pos, " warning")+8;
2907
2941
static const char *fieldtype2str(drizzle_column_type_t type)
2908
2942
{
2909
2943
  switch (type) {
2910
 
  case DRIZZLE_COLUMN_TYPE_BLOB:        return "BLOB";
2911
 
  case DRIZZLE_COLUMN_TYPE_DATE:        return "DATE";
2912
 
  case DRIZZLE_COLUMN_TYPE_DATETIME:    return "DATETIME";
2913
 
  case DRIZZLE_COLUMN_TYPE_NEWDECIMAL:  return "DECIMAL";
2914
 
  case DRIZZLE_COLUMN_TYPE_DOUBLE:      return "DOUBLE";
2915
 
  case DRIZZLE_COLUMN_TYPE_ENUM:        return "ENUM";
2916
 
  case DRIZZLE_COLUMN_TYPE_LONG:        return "LONG";
2917
 
  case DRIZZLE_COLUMN_TYPE_LONGLONG:    return "LONGLONG";
2918
 
  case DRIZZLE_COLUMN_TYPE_NULL:        return "NULL";
2919
 
  case DRIZZLE_COLUMN_TYPE_TIMESTAMP:   return "TIMESTAMP";
2920
 
  default:                     return "?-unknown-?";
 
2944
    case DRIZZLE_COLUMN_TYPE_BLOB:        return "BLOB";
 
2945
    case DRIZZLE_COLUMN_TYPE_DATE:        return "DATE";
 
2946
    case DRIZZLE_COLUMN_TYPE_DATETIME:    return "DATETIME";
 
2947
    case DRIZZLE_COLUMN_TYPE_NEWDECIMAL:  return "DECIMAL";
 
2948
    case DRIZZLE_COLUMN_TYPE_DOUBLE:      return "DOUBLE";
 
2949
    case DRIZZLE_COLUMN_TYPE_ENUM:        return "ENUM";
 
2950
    case DRIZZLE_COLUMN_TYPE_LONG:        return "LONG";
 
2951
    case DRIZZLE_COLUMN_TYPE_LONGLONG:    return "LONGLONG";
 
2952
    case DRIZZLE_COLUMN_TYPE_NULL:        return "NULL";
 
2953
    case DRIZZLE_COLUMN_TYPE_TIMESTAMP:   return "TIMESTAMP";
 
2954
    case DRIZZLE_COLUMN_TYPE_TINY:        return "TINY";
 
2955
    case DRIZZLE_COLUMN_TYPE_VIRTUAL:     return "VIRTUAL";
 
2956
    default:                     return "?-unknown-?";
2921
2957
  }
2922
2958
}
2923
2959
 
2927
2963
  *s=0;
2928
2964
#define ff2s_check_flag(X)                                              \
2929
2965
  if (f & DRIZZLE_COLUMN_FLAGS_ ## X) { s=strcpy(s, # X " ")+strlen(# X " "); \
2930
 
    f &= ~ DRIZZLE_COLUMN_FLAGS_ ## X; }
 
2966
                        f &= ~ DRIZZLE_COLUMN_FLAGS_ ## X; }
2931
2967
  ff2s_check_flag(NOT_NULL);
2932
2968
  ff2s_check_flag(PRI_KEY);
2933
2969
  ff2s_check_flag(UNIQUE_KEY);
2948
2984
  ff2s_check_flag(ON_UPDATE_NOW);
2949
2985
#undef ff2s_check_flag
2950
2986
  if (f)
2951
 
    snprintf(s, sizeof(buf), " unknows=0x%04x", f);
 
2987
    sprintf(s, " unknows=0x%04x", f);
2952
2988
  return buf;
2953
2989
}
2954
2990
 
3014
3050
      uint32_t name_length= strlen(drizzle_column_name(field));
3015
3051
 
3016
3052
      /* Check if the max_byte value is really the maximum in terms
3017
 
        of visual length since multibyte characters can affect the
3018
 
        length of the separator. */
 
3053
         of visual length since multibyte characters can affect the
 
3054
         length of the separator. */
3019
3055
      length= charset_info->cset->numcells(charset_info,
3020
3056
                                           drizzle_column_name(field),
3021
3057
                                           drizzle_column_name(field) +
3031
3067
        length= name_length;
3032
3068
      }
3033
3069
    }
3034
 
 
 
3070
  
3035
3071
    if (quick)
3036
3072
      length=max(length,drizzle_column_size(field));
3037
3073
    else
3058
3094
    {
3059
3095
      uint32_t name_length= (uint32_t) strlen(drizzle_column_name(field));
3060
3096
      uint32_t numcells= charset_info->cset->numcells(charset_info,
3061
 
                                                      drizzle_column_name(field),
3062
 
                                                      drizzle_column_name(field) +
3063
 
                                                      name_length);
 
3097
                                                  drizzle_column_name(field),
 
3098
                                                  drizzle_column_name(field) +
 
3099
                                                  name_length);
3064
3100
      uint32_t display_length= drizzle_column_max_size(field) + name_length -
3065
 
        numcells;
 
3101
                               numcells;
3066
3102
      tee_fprintf(PAGER, " %-*s |",(int) min(display_length,
3067
3103
                                             MAX_COLUMN_LENGTH),
3068
3104
                  drizzle_column_name(field));
3127
3163
      extra_padding= data_length - visible_length;
3128
3164
 
3129
3165
      if (field_max_length > MAX_COLUMN_LENGTH)
3130
 
        tee_print_sized_data(buffer, data_length, MAX_COLUMN_LENGTH+extra_padding, false);
 
3166
        tee_print_sized_data(buffer, data_length, MAX_COLUMN_LENGTH+extra_padding, FALSE);
3131
3167
      else
3132
3168
      {
3133
3169
        if (num_flag[off] != 0) /* if it is numeric, we right-justify it */
3134
 
          tee_print_sized_data(buffer, data_length, field_max_length+extra_padding, true);
 
3170
          tee_print_sized_data(buffer, data_length, field_max_length+extra_padding, TRUE);
3135
3171
        else
3136
3172
          tee_print_sized_data(buffer, data_length,
3137
 
                               field_max_length+extra_padding, false);
 
3173
                               field_max_length+extra_padding, FALSE);
3138
3174
      }
3139
3175
      tee_fputs(" | ", PAGER);
3140
3176
    }
3147
3183
}
3148
3184
 
3149
3185
/**
3150
 
  Return the length of a field after it would be rendered into text.
3151
 
 
3152
 
  This doesn't know or care about multibyte characters.  Assume we're
3153
 
  using such a charset.  We can't know that all of the upcoming rows
3154
 
  for this column will have bytes that each render into some fraction
3155
 
  of a character.  It's at least possible that a row has bytes that
3156
 
  all render into one character each, and so the maximum length is
3157
 
  still the number of bytes.  (Assumption 1:  This can't be better
3158
 
  because we can never know the number of characters that the DB is
3159
 
  going to send -- only the number of bytes.  2: Chars <= Bytes.)
3160
 
 
3161
 
  @param  field  Pointer to a field to be inspected
3162
 
 
3163
 
  @returns  number of character positions to be used, at most
 
3186
   Return the length of a field after it would be rendered into text.
 
3187
 
 
3188
   This doesn't know or care about multibyte characters.  Assume we're
 
3189
   using such a charset.  We can't know that all of the upcoming rows
 
3190
   for this column will have bytes that each render into some fraction
 
3191
   of a character.  It's at least possible that a row has bytes that
 
3192
   all render into one character each, and so the maximum length is
 
3193
   still the number of bytes.  (Assumption 1:  This can't be better
 
3194
   because we can never know the number of characters that the DB is
 
3195
   going to send -- only the number of bytes.  2: Chars <= Bytes.)
 
3196
 
 
3197
   @param  field  Pointer to a field to be inspected
 
3198
 
 
3199
   @returns  number of character positions to be used, at most
3164
3200
*/
3165
3201
static int get_field_disp_length(drizzle_column_st *field)
3166
3202
{
3172
3208
    length= max(length, (uint32_t)drizzle_column_max_size(field));
3173
3209
 
3174
3210
  if (length < 4 &&
3175
 
      !(drizzle_column_flags(field) & DRIZZLE_COLUMN_FLAGS_NOT_NULL))
 
3211
    !(drizzle_column_flags(field) & DRIZZLE_COLUMN_FLAGS_NOT_NULL))
3176
3212
  {
3177
3213
    length= 4;        /* Room for "NULL" */
3178
3214
  }
3181
3217
}
3182
3218
 
3183
3219
/**
3184
 
  For a new result, return the max number of characters that any
3185
 
  upcoming row may return.
3186
 
 
3187
 
  @param  result  Pointer to the result to judge
3188
 
 
3189
 
  @returns  The max number of characters in any row of this result
 
3220
   For a new result, return the max number of characters that any
 
3221
   upcoming row may return.
 
3222
 
 
3223
   @param  result  Pointer to the result to judge
 
3224
 
 
3225
   @returns  The max number of characters in any row of this result
3190
3226
*/
3191
3227
static int get_result_width(drizzle_result_st *result)
3192
3228
{
3310
3346
    warning.
3311
3347
  */
3312
3348
  if (!cur || (num_rows == 1 &&
3313
 
               error_code == (uint32_t) strtoul(cur[1], NULL, 10)))
 
3349
      error_code == (uint32_t) strtoul(cur[1], NULL, 10)))
3314
3350
  {
3315
3351
    goto end;
3316
3352
  }
3338
3374
    if (opt_raw_data)
3339
3375
      tee_fputs(pos, PAGER);
3340
3376
    else for (const char *end=pos+length ; pos != end ; pos++)
3341
 
    {
3342
 
      int l;
3343
 
      if (use_mb(charset_info) &&
3344
 
          (l = my_ismbchar(charset_info, pos, end)))
3345
 
      {
3346
 
        while (l--)
3347
 
          tee_putc(*pos++, PAGER);
3348
 
        pos--;
3349
 
        continue;
3350
 
      }
3351
 
      if (!*pos)
3352
 
        tee_fputs("\\0", PAGER); // This makes everything hard
3353
 
      else if (*pos == '\t')
3354
 
        tee_fputs("\\t", PAGER); // This would destroy tab format
3355
 
      else if (*pos == '\n')
3356
 
        tee_fputs("\\n", PAGER); // This too
3357
 
      else if (*pos == '\\')
3358
 
        tee_fputs("\\\\", PAGER);
3359
 
      else
3360
 
        tee_putc(*pos, PAGER);
3361
 
    }
 
3377
         {
 
3378
#ifdef USE_MB
 
3379
           int l;
 
3380
           if (use_mb(charset_info) &&
 
3381
               (l = my_ismbchar(charset_info, pos, end)))
 
3382
           {
 
3383
             while (l--)
 
3384
               tee_putc(*pos++, PAGER);
 
3385
             pos--;
 
3386
             continue;
 
3387
           }
 
3388
#endif
 
3389
           if (!*pos)
 
3390
             tee_fputs("\\0", PAGER); // This makes everything hard
 
3391
           else if (*pos == '\t')
 
3392
             tee_fputs("\\t", PAGER); // This would destroy tab format
 
3393
           else if (*pos == '\n')
 
3394
             tee_fputs("\\n", PAGER); // This too
 
3395
           else if (*pos == '\\')
 
3396
             tee_fputs("\\\\", PAGER);
 
3397
           else
 
3398
             tee_putc(*pos, PAGER);
 
3399
         }
3362
3400
  }
3363
3401
}
3364
3402
 
3592
3630
    else
3593
3631
    {
3594
3632
      /* Quick re-connect */
3595
 
      opt_rehash= 0;
 
3633
      opt_rehash= 0;                            /* purecov: tested */
3596
3634
    }
3597
3635
    // command used
3598
3636
    assert(buffer!=NULL);
3605
3643
 
3606
3644
  if (connected)
3607
3645
  {
3608
 
    snprintf(buff, sizeof(buff), "Connection id:    %u",drizzle_con_thread_id(&con));
 
3646
    sprintf(buff,"Connection id:    %u",drizzle_con_thread_id(&con));
3609
3647
    put_info(buff,INFO_INFO,0,0);
3610
 
    snprintf(buff, sizeof(buff), "Current database: %.128s\n",
3611
 
             current_db ? current_db : "*** NONE ***");
 
3648
    sprintf(buff,"Current database: %.128s\n",
 
3649
            current_db ? current_db : "*** NONE ***");
3612
3650
    put_info(buff,INFO_INFO,0,0);
3613
3651
  }
3614
3652
  return error;
3619
3657
{
3620
3658
  char source_name[FN_REFLEN], *end;
3621
3659
  const char *param;
3622
 
  LineBuffer *line_buff;
 
3660
  LINE_BUFFER *line_buff;
3623
3661
  int error;
3624
3662
  STATUS old_status;
3625
3663
  FILE *sql_file;
3638
3676
                               my_iscntrl(charset_info,end[-1])))
3639
3677
    end--;
3640
3678
  end[0]=0;
3641
 
  internal::unpack_filename(source_name,source_name);
 
3679
  unpack_filename(source_name,source_name);
3642
3680
  /* open file name */
3643
3681
  if (!(sql_file = fopen(source_name, "r")))
3644
3682
  {
3645
3683
    char buff[FN_REFLEN+60];
3646
 
    snprintf(buff, sizeof(buff), "Failed to open file '%s', error: %d", source_name,errno);
 
3684
    sprintf(buff,"Failed to open file '%s', error: %d", source_name,errno);
3647
3685
    return put_info(buff, INFO_ERROR, 0 ,0);
3648
3686
  }
3649
3687
 
3650
 
  line_buff= new(std::nothrow) LineBuffer(opt_max_input_line,sql_file);
3651
 
  if (line_buff == NULL)
 
3688
  if (!(line_buff=batch_readline_init(opt_max_input_line+512,sql_file)))
3652
3689
  {
3653
3690
    fclose(sql_file);
3654
 
    return put_info("Can't initialize LineBuffer", INFO_ERROR, 0, 0);
 
3691
    return put_info("Can't initialize batch_readline", INFO_ERROR, 0 ,0);
3655
3692
  }
3656
3693
 
3657
3694
  /* Save old status */
3669
3706
  // Continue as before
3670
3707
  status=old_status;
3671
3708
  fclose(sql_file);
3672
 
  delete status.line_buff;
3673
 
  line_buff= status.line_buff= 0;
 
3709
  batch_readline_end(line_buff);
3674
3710
  return error;
3675
3711
}
3676
3712
 
3871
3907
 
3872
3908
static int
3873
3909
sql_connect(char *host,char *database,char *user,char *password,
3874
 
            uint32_t silent)
 
3910
                 uint32_t silent)
3875
3911
{
3876
3912
  drizzle_return_t ret;
3877
3913
 
3883
3919
  }
3884
3920
  drizzle_create(&drizzle);
3885
3921
  if (drizzle_con_add_tcp(&drizzle, &con, host, opt_drizzle_port, user,
3886
 
                          password, database, opt_mysql ? DRIZZLE_CON_MYSQL : DRIZZLE_CON_NONE) == NULL)
 
3922
                          password, database, DRIZZLE_CON_NONE) == NULL)
3887
3923
  {
3888
3924
    (void) put_error(&con, NULL);
3889
3925
    (void) fflush(stdout);
3890
3926
    return 1;
3891
3927
  }
3892
3928
 
3893
 
  /* XXX add this back in
3894
 
    if (opt_connect_timeout)
3895
 
    {
 
3929
/* XXX add this back in
 
3930
  if (opt_connect_timeout)
 
3931
  {
3896
3932
    uint32_t timeout=opt_connect_timeout;
3897
3933
    drizzleclient_options(&drizzle,DRIZZLE_OPT_CONNECT_TIMEOUT,
3898
 
    (char*) &timeout);
3899
 
    }
3900
 
  */
 
3934
                  (char*) &timeout);
 
3935
  }
 
3936
*/
3901
3937
 
3902
 
  /* XXX Do we need this?
3903
 
    if (safe_updates)
3904
 
    {
 
3938
/* XXX Do we need this?
 
3939
  if (safe_updates)
 
3940
  {
3905
3941
    char init_command[100];
3906
3942
    sprintf(init_command,
3907
 
    "SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=%"PRIu32
3908
 
    ",MAX_JOIN_SIZE=%"PRIu32,
3909
 
    select_limit, max_join_size);
 
3943
            "SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=%"PRIu32
 
3944
            ",MAX_JOIN_SIZE=%"PRIu32,
 
3945
            select_limit, max_join_size);
3910
3946
    drizzleclient_options(&drizzle, DRIZZLE_INIT_COMMAND, init_command);
3911
 
    }
3912
 
  */
 
3947
  }
 
3948
*/
3913
3949
  if ((ret= drizzle_con_connect(&con)) != DRIZZLE_RETURN_OK)
3914
3950
  {
3915
3951
    if (!silent || (ret != DRIZZLE_RETURN_GETADDRINFO &&
3922
3958
    return -1;          // Retryable
3923
3959
  }
3924
3960
  connected=1;
3925
 
 
 
3961
/* XXX hmm?
 
3962
  drizzle.reconnect= debug_info_flag; // We want to know if this happens
 
3963
*/
3926
3964
  build_completion_hash(opt_rehash, 1);
3927
3965
  return 0;
3928
3966
}
3931
3969
static int
3932
3970
com_status(string *, const char *)
3933
3971
{
3934
 
  /*
3935
 
    char buff[40];
3936
 
    uint64_t id;
3937
 
  */
 
3972
/*
 
3973
  char buff[40];
 
3974
  uint64_t id;
 
3975
*/
3938
3976
  drizzle_result_st result;
3939
3977
  drizzle_return_t ret;
3940
3978
 
3982
4020
  tee_fprintf(stdout, "Server version:\t\t%s\n", server_version_string(&con));
3983
4021
  tee_fprintf(stdout, "Protocol version:\t%d\n", drizzle_con_protocol_version(&con));
3984
4022
  tee_fprintf(stdout, "Connection:\t\t%s\n", drizzle_con_host(&con));
3985
 
  /* XXX need to save this from result
3986
 
    if ((id= drizzleclient_insert_id(&drizzle)))
3987
 
    tee_fprintf(stdout, "Insert id:\t\t%s\n", internal::llstr(id, buff));
3988
 
  */
 
4023
/* XXX need to save this from result
 
4024
  if ((id= drizzleclient_insert_id(&drizzle)))
 
4025
    tee_fprintf(stdout, "Insert id:\t\t%s\n", llstr(id, buff));
 
4026
*/
3989
4027
 
3990
 
  if (drizzle_con_uds(&con))
 
4028
  if (strcmp(drizzle_con_uds(&con), ""))
3991
4029
    tee_fprintf(stdout, "UNIX socket:\t\t%s\n", drizzle_con_uds(&con));
3992
4030
  else
3993
4031
    tee_fprintf(stdout, "TCP port:\t\t%d\n", drizzle_con_port(&con));
3998
4036
    tee_fprintf(stdout, "\nNote that you are running in safe_update_mode:\n");
3999
4037
    vidattr(A_NORMAL);
4000
4038
    tee_fprintf(stdout, "\
4001
 
                UPDATEs and DELETEs that don't use a key in the WHERE clause are not allowed.\n\
4002
 
                (One can force an UPDATE/DELETE by adding LIMIT # at the end of the command.)\n \
4003
 
                SELECT has an automatic 'LIMIT %lu' if LIMIT is not used.\n             \
4004
 
                Max number of examined row combination in a join is set to: %lu\n\n",
 
4039
UPDATEs and DELETEs that don't use a key in the WHERE clause are not allowed.\n\
 
4040
(One can force an UPDATE/DELETE by adding LIMIT # at the end of the command.)\n \
 
4041
SELECT has an automatic 'LIMIT %lu' if LIMIT is not used.\n             \
 
4042
Max number of examined row combination in a join is set to: %lu\n\n",
4005
4043
                select_limit, max_join_size);
4006
4044
  }
4007
4045
  tee_puts("--------------\n", stdout);
4136
4174
 
4137
4175
  return put_info(error, INFO_ERROR,
4138
4176
                  res == NULL ? drizzle_con_error_code(local_con) :
4139
 
                  drizzle_result_error_code(res),
 
4177
                                drizzle_result_error_code(res),
4140
4178
                  res == NULL ? drizzle_con_sqlstate(local_con) :
4141
 
                  drizzle_result_sqlstate(res));
 
4179
                                drizzle_result_sqlstate(res));
4142
4180
}
4143
4181
 
4144
4182
 
4211
4249
 
4212
4250
 
4213
4251
/**
4214
 
  Write as many as 52+1 bytes to buff, in the form of a legible
4215
 
  duration of time.
 
4252
   Write as many as 52+1 bytes to buff, in the form of a legible
 
4253
   duration of time.
4216
4254
 
4217
 
  len("4294967296 days, 23 hours, 59 minutes, 60.00 seconds")  ->  52
 
4255
   len("4294967296 days, 23 hours, 59 minutes, 60.00 seconds")  ->  52
4218
4256
*/
4219
4257
static void nice_time(double sec,char *buff,bool part_second)
4220
4258
{
4315
4353
        processed_prompt->append(current_db ? current_db : "(none)");
4316
4354
        break;
4317
4355
      case 'h':
4318
 
        {
4319
 
          const char *prompt;
4320
 
          prompt= connected ? drizzle_con_host(&con) : "not_connected";
4321
 
          if (strstr(prompt, "Localhost"))
4322
 
            processed_prompt->append("localhost");
4323
 
          else
4324
 
          {
4325
 
            const char *end=strrchr(prompt,' ');
4326
 
            if (end != NULL)
4327
 
              processed_prompt->append(prompt, (end-prompt));
4328
 
          }
 
4356
      {
 
4357
        const char *prompt;
 
4358
        prompt= connected ? drizzle_con_host(&con) : "not_connected";
 
4359
        if (strstr(prompt, "Localhost"))
 
4360
          processed_prompt->append("localhost");
 
4361
        else
 
4362
        {
 
4363
          const char *end=strrchr(prompt,' ');
 
4364
          if (end != NULL)
 
4365
            processed_prompt->append(prompt, (end-prompt));
 
4366
        }
 
4367
        break;
 
4368
      }
 
4369
      case 'p':
 
4370
      {
 
4371
        if (!connected)
 
4372
        {
 
4373
          processed_prompt->append("not_connected");
4329
4374
          break;
4330
4375
        }
4331
 
      case 'p':
 
4376
 
 
4377
        if (strcmp(drizzle_con_uds(&con), ""))
4332
4378
        {
4333
 
          if (!connected)
4334
 
          {
4335
 
            processed_prompt->append("not_connected");
4336
 
            break;
4337
 
          }
4338
 
 
4339
 
          if (drizzle_con_uds(&con))
4340
 
          {
4341
 
            const char *pos=strrchr(drizzle_con_uds(&con),'/');
4342
 
            processed_prompt->append(pos ? pos+1 : drizzle_con_uds(&con));
4343
 
          }
4344
 
          else
4345
 
            add_int_to_prompt(drizzle_con_port(&con));
 
4379
          const char *pos=strrchr(drizzle_con_uds(&con),'/');
 
4380
          processed_prompt->append(pos ? pos+1 : drizzle_con_uds(&con));
4346
4381
        }
4347
 
        break;
 
4382
        else
 
4383
          add_int_to_prompt(drizzle_con_port(&con));
 
4384
      }
 
4385
      break;
4348
4386
      case 'U':
4349
4387
        if (!full_username)
4350
4388
          init_username();
4454
4492
 
4455
4493
static void init_username()
4456
4494
{
4457
 
  /* XXX need this?
4458
 
    free(full_username);
4459
 
    free(part_username);
 
4495
/* XXX need this?
 
4496
  free(full_username);
 
4497
  free(part_username);
4460
4498
 
4461
 
    drizzle_result_st *result;
4462
 
    if (!drizzleclient_query(&drizzle,"select USER()") &&
4463
 
    (result=drizzleclient_use_result(&drizzle)))
4464
 
    {
 
4499
  drizzle_result_st *result;
 
4500
  if (!drizzleclient_query(&drizzle,"select USER()") &&
 
4501
      (result=drizzleclient_use_result(&drizzle)))
 
4502
  {
4465
4503
    drizzle_row_t cur=drizzleclient_fetch_row(result);
4466
4504
    full_username= strdup(cur[0]);
4467
4505
    part_username= strdup(strtok(cur[0],"@"));
4468
4506
    (void) drizzleclient_fetch_row(result);        // Read eof
4469
 
    }
4470
 
  */
 
4507
  }
 
4508
*/
4471
4509
}
4472
4510
 
4473
4511
static int com_prompt(string *, const char *line)
4490
4528
}
4491
4529
 
4492
4530
/*
4493
 
  strcont(str, set) if str contanies any character in the string set.
4494
 
  The result is the position of the first found character in str, or NULL
4495
 
  if there isn't anything found.
 
4531
    strcont(str, set) if str contanies any character in the string set.
 
4532
    The result is the position of the first found character in str, or NULL
 
4533
    if there isn't anything found.
4496
4534
*/
4497
4535
 
4498
4536
static const char * strcont(register const char *str, register const char *set)