~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.cc

Merge Siddharth, ran formatting across it.

Someone really should take these programs apart and clean them up.

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
#  endif /* !defined(HAVE_READLINE_H) */
90
90
char *cmdline = NULL;
91
91
#else /* !defined(HAVE_READLINE_READLINE_H) */
92
 
  /* no readline */
 
92
/* no readline */
93
93
#  error Readline Required
94
94
#endif /* HAVE_LIBREADLINE */
95
95
 
103
103
extern int write_history ();
104
104
extern int read_history ();
105
105
#  endif /* defined(HAVE_READLINE_HISTORY_H) */
106
 
    /* no history */
 
106
/* no history */
107
107
#endif /* HAVE_READLINE_HISTORY */
108
108
 
109
109
/**
110
 
 Make the old readline interface look like the new one.
 
110
  Make the old readline interface look like the new one.
111
111
*/
112
112
#ifndef HAVE_RL_COMPLETION
113
113
typedef char **rl_completion_func_t(const char *, int, int);
176
176
static drizzle_st drizzle;      /* The library handle */
177
177
static drizzle_con_st con;      /* The connection */
178
178
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;
 
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;
191
191
static uint32_t  show_progress_size= 0;
192
192
static bool column_types_flag;
193
193
static bool preserve_comments= false;
195
195
static int verbose= 0, opt_silent= 0, opt_local_infile= 0;
196
196
static drizzle_capabilities_t connect_flag= DRIZZLE_CAPABILITIES_NONE;
197
197
static char *current_host, *current_db, *current_user= NULL,
198
 
  *opt_password= NULL, *delimiter_str= NULL, *current_prompt= NULL;
 
198
            *opt_password= NULL, *delimiter_str= NULL, *current_prompt= NULL;
199
199
static char *histfile;
200
200
static char *histfile_tmp;
201
201
static string *glob_buffer;
209
209
// TODO: Need to i18n these
210
210
static const char *day_names[]= {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
211
211
static const char *month_names[]= {"Jan","Feb","Mar","Apr","May","Jun","Jul",
212
 
                                  "Aug","Sep","Oct","Nov","Dec"};
 
212
  "Aug","Sep","Oct","Nov","Dec"};
213
213
static char default_pager[FN_REFLEN];
214
214
static char pager[FN_REFLEN], outfile[FN_REFLEN];
215
215
static FILE *PAGER, *OUTFILE;
234
234
/* The names of functions that actually do the manipulation. */
235
235
static int get_options(int argc,char **argv);
236
236
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*);
 
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*);
247
247
 
248
248
static int read_and_execute(bool interactive);
249
249
static int sql_connect(char *host,char *database,char *user,char *password,
266
266
static const char * strcont(register const char *str, register const char *set);
267
267
 
268
268
/* A structure which contains information on the commands this program
269
 
   can understand. */
 
269
  can understand. */
270
270
typedef struct {
271
271
  const char *name;        /* User printable name of the function. */
272
272
  char cmd_char;        /* msql command character */
1027
1027
  Shutdown the server that we are currently connected to.
1028
1028
 
1029
1029
  @retval
1030
 
    true success
 
1030
  true success
1031
1031
  @retval
1032
 
    false failure
 
1032
  false failure
1033
1033
*/
1034
1034
static bool server_shutdown(void)
1035
1035
{
1073
1073
  Ping the server that we are currently connected to.
1074
1074
 
1075
1075
  @retval
1076
 
    true success
 
1076
  true success
1077
1077
  @retval
1078
 
    false failure
 
1078
  false failure
1079
1079
*/
1080
1080
static bool server_ping(void)
1081
1081
{
1110
1110
  Execute command(s) specified by the user.
1111
1111
 
1112
1112
  @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.
 
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.
1117
1117
 
1118
1118
  @retval
1119
 
    false no commands were executed
 
1119
  false no commands were executed
1120
1120
  @retval
1121
 
    true  at least one command was executed
 
1121
  true  at least one command was executed
1122
1122
*/
1123
1123
static bool execute_commands(int *error)
1124
1124
{
1156
1156
  default_prompt= strdup(getenv("DRIZZLE_PS1") ?
1157
1157
                         getenv("DRIZZLE_PS1") :
1158
1158
                         "drizzle> ");
1159
 
  
 
1159
 
1160
1160
  if (default_prompt == NULL)
1161
1161
  {
1162
1162
    fprintf(stderr, _("Memory allocation error while constructing initial "
1268
1268
  glob_buffer= new string();
1269
1269
  glob_buffer->reserve(512);
1270
1270
 
1271
 
  char * output_buff= (char *)malloc(512);
1272
 
  memset(output_buff, '\0', 512);
 
1271
  size_t output_buff_size = 512;
 
1272
  char * output_buff= (char *)malloc(output_buff_size);
 
1273
  memset(output_buff, '\0', output_buff_size);
1273
1274
 
1274
 
  sprintf(output_buff,
1275
 
          _("Your Drizzle connection id is %u\nServer version: %s\n"),
1276
 
          drizzle_con_thread_id(&con),
1277
 
          server_version_string(&con));
 
1275
  snprintf(output_buff, output_buff_size,
 
1276
           _("Your Drizzle connection id is %u\nServer version: %s\n"),
 
1277
           drizzle_con_thread_id(&con),
 
1278
           server_version_string(&con));
1278
1279
  put_info(output_buff, INFO_INFO, 0, 0);
1279
1280
 
1280
1281
  initialize_readline(current_prompt);
1285
1286
      histfile= strdup(getenv("DRIZZLE_HISTFILE"));
1286
1287
    else if (getenv("HOME"))
1287
1288
    {
1288
 
      histfile=(char*) malloc(strlen(getenv("HOME")) + strlen("/.drizzle_history") + 2);
 
1289
      size_t histfile_size = strlen(getenv("HOME")) +
 
1290
        strlen("/.drizzle_history") + 2;
 
1291
      histfile=(char*) malloc(histfile_size);
1289
1292
      if (histfile)
1290
 
        sprintf(histfile,"%s/.drizzle_history",getenv("HOME"));
 
1293
        snprintf(histfile, histfile_size, "%s/.drizzle_history",getenv("HOME"));
1291
1294
      char link_name[FN_REFLEN];
1292
1295
      ssize_t sym_link_size= readlink(histfile,link_name,FN_REFLEN-1);
1293
1296
      if (sym_link_size >= 0)
1306
1309
      if (verbose)
1307
1310
        tee_fprintf(stdout, _("Reading history-file %s\n"),histfile);
1308
1311
      read_history(histfile);
1309
 
      if (!(histfile_tmp= (char*) malloc((uint32_t) strlen(histfile) + 5)))
 
1312
      size_t histfile_tmp_size = strlen(histfile) + 5;
 
1313
      if (!(histfile_tmp= (char*) malloc(histfile_tmp_size)))
1310
1314
      {
1311
1315
        fprintf(stderr, _("Couldn't allocate memory for temp histfile!\n"));
1312
1316
        exit(1);
1313
1317
      }
1314
 
      sprintf(histfile_tmp, "%s.TMP", histfile);
 
1318
      snprintf(histfile_tmp, histfile_tmp_size, "%s.TMP", histfile);
1315
1319
    }
1316
1320
  }
1317
1321
 
1388
1392
  }
1389
1393
 
1390
1394
  /* kill_buffer is always big enough because max length of %lu is 15 */
1391
 
  sprintf(kill_buffer, "KILL /*!50000 QUERY */ %u",
1392
 
          drizzle_con_thread_id(&con));
 
1395
  snprintf(kill_buffer, sizeof(kill_buffer), "KILL /*!50000 QUERY */ %u",
 
1396
           drizzle_con_thread_id(&con));
1393
1397
 
1394
1398
  if (drizzle_query_str(&kill_drizzle, &res, kill_buffer, &ret) != NULL)
1395
1399
    drizzle_result_free(&res);
1419
1423
static struct my_option my_long_options[] =
1420
1424
{
1421
1425
  {"help", '?', N_("Display this help and exit."), 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
1422
 
   0, 0, 0, 0, 0},
 
1426
    0, 0, 0, 0, 0},
1423
1427
  {"help", 'I', N_("Synonym for -?"), 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
1424
 
   0, 0, 0, 0, 0},
 
1428
    0, 0, 0, 0, 0},
1425
1429
  {"auto-rehash", OPT_AUTO_REHASH,
1426
 
   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."),
1427
 
   (char**) &opt_rehash, (char**) &opt_rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
1428
 
   0, 0},
 
1430
    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."),
 
1431
    (char**) &opt_rehash, (char**) &opt_rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
 
1432
    0, 0},
1429
1433
  {"no-auto-rehash", 'A',
1430
 
   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."),
1431
 
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1434
    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."),
 
1435
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1432
1436
  {"auto-vertical-output", OPT_AUTO_VERTICAL_OUTPUT,
1433
 
   N_("Automatically switch to vertical output mode if the result is wider than the terminal width."),
1434
 
   (char**) &auto_vertical_output, (char**) &auto_vertical_output, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1437
    N_("Automatically switch to vertical output mode if the result is wider than the terminal width."),
 
1438
    (char**) &auto_vertical_output, (char**) &auto_vertical_output, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1435
1439
  {"batch", 'B',
1436
 
   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},
 
1440
    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},
1437
1441
  {"column-type-info", OPT_COLUMN_TYPES, N_("Display column type information."),
1438
 
   (char**) &column_types_flag, (char**) &column_types_flag,
1439
 
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1442
    (char**) &column_types_flag, (char**) &column_types_flag,
 
1443
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1440
1444
  {"comments", 'c', N_("Preserve comments. Send comments to the server. The default is --skip-comments (discard comments), enable with --comments"),
1441
 
   (char**) &preserve_comments, (char**) &preserve_comments,
1442
 
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1445
    (char**) &preserve_comments, (char**) &preserve_comments,
 
1446
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1443
1447
  {"compress", 'C', N_("Use compression in server/client protocol."),
1444
 
   (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
1445
 
   0, 0, 0},
 
1448
    (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
1449
    0, 0, 0},
1446
1450
  {"database", 'D', N_("Database to use."), (char**) &current_db,
1447
 
   (char**) &current_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1451
    (char**) &current_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1448
1452
  {"default-character-set", OPT_DEFAULT_CHARSET,
1449
 
   N_("(not used)"), 0,
1450
 
   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1453
    N_("(not used)"), 0,
 
1454
    0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1451
1455
  {"delimiter", OPT_DELIMITER, N_("Delimiter to be used."), (char**) &delimiter_str,
1452
 
   (char**) &delimiter_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1456
    (char**) &delimiter_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1453
1457
  {"execute", 'e', N_("Execute command and quit. (Disables --force and history file)"), 0,
1454
 
   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1458
    0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1455
1459
  {"vertical", 'E', N_("Print the output of a query (rows) vertically."),
1456
 
   (char**) &vertical, (char**) &vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
1457
 
   0},
 
1460
    (char**) &vertical, (char**) &vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
 
1461
    0},
1458
1462
  {"force", 'f', N_("Continue even if we get an sql error."),
1459
 
   (char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
1460
 
   0, 0, 0, 0},
 
1463
    (char**) &ignore_errors, (char**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
 
1464
    0, 0, 0, 0},
1461
1465
  {"named-commands", 'G',
1462
 
   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."),
1463
 
   (char**) &named_cmds, (char**) &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
1464
 
   0, 0},
 
1466
    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."),
 
1467
    (char**) &named_cmds, (char**) &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
 
1468
    0, 0},
1465
1469
  {"no-named-commands", 'g',
1466
 
   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."),
1467
 
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1470
    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."),
 
1471
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1468
1472
  {"ignore-spaces", 'i', N_("Ignore space after function names."), 0, 0, 0,
1469
 
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1473
    GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1470
1474
  {"local-infile", OPT_LOCAL_INFILE, N_("Enable/disable LOAD DATA LOCAL INFILE."),
1471
 
   (char**) &opt_local_infile,
1472
 
   (char**) &opt_local_infile, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
1475
    (char**) &opt_local_infile,
 
1476
    (char**) &opt_local_infile, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
1473
1477
  {"no-beep", 'b', N_("Turn off beep on error."), (char**) &opt_nobeep,
1474
 
   (char**) &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1478
    (char**) &opt_nobeep, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1475
1479
  {"host", 'h', N_("Connect to host."), (char**) &current_host,
1476
 
   (char**) &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1480
    (char**) &current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1477
1481
  {"line-numbers", OPT_LINE_NUMBERS, N_("Write line numbers for errors."),
1478
 
   (char**) &line_numbers, (char**) &line_numbers, 0, GET_BOOL,
1479
 
   NO_ARG, 1, 0, 0, 0, 0, 0},
 
1482
    (char**) &line_numbers, (char**) &line_numbers, 0, GET_BOOL,
 
1483
    NO_ARG, 1, 0, 0, 0, 0, 0},
1480
1484
  {"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,
1481
 
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
1485
    NO_ARG, 0, 0, 0, 0, 0, 0},
1482
1486
  {"unbuffered", 'n', N_("Flush buffer after each query."), (char**) &unbuffered,
1483
 
   (char**) &unbuffered, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1487
    (char**) &unbuffered, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1484
1488
  {"column-names", OPT_COLUMN_NAMES, N_("Write column names in results."),
1485
 
   (char**) &column_names, (char**) &column_names, 0, GET_BOOL,
1486
 
   NO_ARG, 1, 0, 0, 0, 0, 0},
 
1489
    (char**) &column_names, (char**) &column_names, 0, GET_BOOL,
 
1490
    NO_ARG, 1, 0, 0, 0, 0, 0},
1487
1491
  {"skip-column-names", 'N',
1488
 
   N_("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."),
1489
 
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1492
    N_("Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead."),
 
1493
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1490
1494
  {"set-variable", 'O',
1491
 
   N_("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value."),
1492
 
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1495
    N_("Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value."),
 
1496
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1493
1497
  {"sigint-ignore", OPT_SIGINT_IGNORE, N_("Ignore SIGINT (CTRL-C)"),
1494
 
   (char**) &opt_sigint_ignore,  (char**) &opt_sigint_ignore, 0, GET_BOOL,
1495
 
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
1498
    (char**) &opt_sigint_ignore,  (char**) &opt_sigint_ignore, 0, GET_BOOL,
 
1499
    NO_ARG, 0, 0, 0, 0, 0, 0},
1496
1500
  {"one-database", 'o',
1497
 
   N_("Only update the default database. This is useful for skipping updates to other database in the update log."),
1498
 
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1501
    N_("Only update the default database. This is useful for skipping updates to other database in the update log."),
 
1502
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1499
1503
  {"pager", OPT_PAGER,
1500
 
   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."),
1501
 
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
1504
    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."),
 
1505
    0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
1502
1506
  {"no-pager", OPT_NOPAGER,
1503
 
   N_("Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead."),
1504
 
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1507
    N_("Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead."),
 
1508
    0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1505
1509
  {"password", 'P',
1506
 
   N_("Password to use when connecting to server. If password is not given it's asked from the tty."),
1507
 
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
1510
    N_("Password to use when connecting to server. If password is not given it's asked from the tty."),
 
1511
    0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
1508
1512
  {"port", 'p', N_("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, ")
1509
 
   N_("built-in default") " (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
1510
 
   0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1513
    N_("built-in default") " (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
 
1514
    0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1511
1515
  {"prompt", OPT_PROMPT, N_("Set the drizzle prompt to this value."),
1512
 
   (char**) &current_prompt, (char**) &current_prompt, 0, GET_STR_ALLOC,
1513
 
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1516
    (char**) &current_prompt, (char**) &current_prompt, 0, GET_STR_ALLOC,
 
1517
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1514
1518
  {"quick", 'q',
1515
 
   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."),
1516
 
   (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1519
    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."),
 
1520
    (char**) &quick, (char**) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1517
1521
  {"raw", 'r', N_("Write fields without conversion. Used with --batch."),
1518
 
   (char**) &opt_raw_data, (char**) &opt_raw_data, 0, GET_BOOL, NO_ARG, 0, 0, 0,
1519
 
   0, 0, 0},
 
1522
    (char**) &opt_raw_data, (char**) &opt_raw_data, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
1523
    0, 0, 0},
1520
1524
  {"reconnect", OPT_RECONNECT, N_("Reconnect if the connection is lost. Disable with --disable-reconnect. This option is enabled by default."),
1521
 
   (char**) &opt_reconnect, (char**) &opt_reconnect, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
 
1525
    (char**) &opt_reconnect, (char**) &opt_reconnect, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
1522
1526
  {"shutdown", OPT_SHUTDOWN, N_("Shutdown the server."),
1523
 
   (char**) &opt_shutdown, (char**) &opt_shutdown, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1527
    (char**) &opt_shutdown, (char**) &opt_shutdown, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1524
1528
  {"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,
1525
 
   0, 0},
 
1529
    0, 0},
1526
1530
  {"table", 't', N_("Output in table format."), (char**) &output_tables,
1527
 
   (char**) &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1531
    (char**) &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1528
1532
  {"tee", OPT_TEE,
1529
 
   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."),
1530
 
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1533
    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."),
 
1534
    0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1531
1535
  {"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,
1532
 
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
1536
    NO_ARG, 0, 0, 0, 0, 0, 0},
1533
1537
  {"user", 'u', N_("User for login if not current user."), (char**) &current_user,
1534
 
   (char**) &current_user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
1538
    (char**) &current_user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1535
1539
  {"safe-updates", 'U', N_("Only allow UPDATE and DELETE that uses keys."),
1536
 
   (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
1537
 
   0, 0, 0, 0},
 
1540
    (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
 
1541
    0, 0, 0, 0},
1538
1542
  {"i-am-a-dummy", 'U', N_("Synonym for option --safe-updates, -U."),
1539
 
   (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
1540
 
   0, 0, 0, 0},
 
1543
    (char**) &safe_updates, (char**) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
 
1544
    0, 0, 0, 0},
1541
1545
  {"verbose", 'v', N_("Write more. (-v -v -v gives the table output format)."), 0,
1542
 
   0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1546
    0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1543
1547
  {"version", 'V', N_("Output version information and exit."), 0, 0, 0,
1544
 
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1548
    GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1545
1549
  {"wait", 'w', N_("Wait and retry if connection is down."), 0, 0, 0, GET_NO_ARG,
1546
 
   NO_ARG, 0, 0, 0, 0, 0, 0},
 
1550
    NO_ARG, 0, 0, 0, 0, 0, 0},
1547
1551
  {"connect_timeout", OPT_CONNECT_TIMEOUT,
1548
 
   N_("Number of seconds before connection timeout."),
1549
 
   (char**) &opt_connect_timeout,
1550
 
   (char**) &opt_connect_timeout, 0, GET_UINT32, REQUIRED_ARG, 0, 0, 3600*12, 0,
1551
 
   0, 0},
 
1552
    N_("Number of seconds before connection timeout."),
 
1553
    (char**) &opt_connect_timeout,
 
1554
    (char**) &opt_connect_timeout, 0, GET_UINT32, REQUIRED_ARG, 0, 0, 3600*12, 0,
 
1555
    0, 0},
1552
1556
  {"max_input_line", OPT_MAX_INPUT_LINE,
1553
 
   N_("Max length of input line"),
1554
 
   (char**) &opt_max_input_line, (char**) &opt_max_input_line, 0,
1555
 
   GET_UINT32, REQUIRED_ARG, 16 *1024L*1024L, 4096,
1556
 
   (int64_t) 2*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
 
1557
    N_("Max length of input line"),
 
1558
    (char**) &opt_max_input_line, (char**) &opt_max_input_line, 0,
 
1559
    GET_UINT32, REQUIRED_ARG, 16 *1024L*1024L, 4096,
 
1560
    (int64_t) 2*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0},
1557
1561
  {"select_limit", OPT_SELECT_LIMIT,
1558
 
   N_("Automatic limit for SELECT when using --safe-updates"),
1559
 
   (char**) &select_limit,
1560
 
   (char**) &select_limit, 0, GET_UINT32, REQUIRED_ARG, 1000L, 1, ULONG_MAX,
1561
 
   0, 1, 0},
 
1562
    N_("Automatic limit for SELECT when using --safe-updates"),
 
1563
    (char**) &select_limit,
 
1564
    (char**) &select_limit, 0, GET_UINT32, REQUIRED_ARG, 1000L, 1, ULONG_MAX,
 
1565
    0, 1, 0},
1562
1566
  {"max_join_size", OPT_MAX_JOIN_SIZE,
1563
 
   N_("Automatic limit for rows in a join when using --safe-updates"),
1564
 
   (char**) &max_join_size,
1565
 
   (char**) &max_join_size, 0, GET_UINT32, REQUIRED_ARG, 1000000L, 1, ULONG_MAX,
1566
 
   0, 1, 0},
 
1567
    N_("Automatic limit for rows in a join when using --safe-updates"),
 
1568
    (char**) &max_join_size,
 
1569
    (char**) &max_join_size, 0, GET_UINT32, REQUIRED_ARG, 1000000L, 1, ULONG_MAX,
 
1570
    0, 1, 0},
1567
1571
  {"secure-auth", OPT_SECURE_AUTH, N_("Refuse client connecting to server if it uses old (pre-4.1.1) protocol"), (char**) &opt_secure_auth,
1568
 
   (char**) &opt_secure_auth, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1572
    (char**) &opt_secure_auth, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1569
1573
  {"show-warnings", OPT_SHOW_WARNINGS, N_("Show warnings after every statement."),
1570
 
   (char**) &show_warnings, (char**) &show_warnings, 0, GET_BOOL, NO_ARG,
1571
 
   0, 0, 0, 0, 0, 0},
 
1574
    (char**) &show_warnings, (char**) &show_warnings, 0, GET_BOOL, NO_ARG,
 
1575
    0, 0, 0, 0, 0, 0},
1572
1576
  {"show-progress-size", OPT_SHOW_PROGRESS_SIZE, N_("Number of lines before each import progress report."),
1573
 
   (char**) &show_progress_size, (char**) &show_progress_size, 0, GET_UINT32, REQUIRED_ARG,
1574
 
   0, 0, 0, 0, 0, 0},
 
1577
    (char**) &show_progress_size, (char**) &show_progress_size, 0, GET_UINT32, REQUIRED_ARG,
 
1578
    0, 0, 0, 0, 0, 0},
1575
1579
  {"ping", OPT_PING, N_("Ping the server to check if it's alive."),
1576
 
   (char**) &opt_ping, (char**) &opt_ping, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
1580
    (char**) &opt_ping, (char**) &opt_ping, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1577
1581
  {"mysql", 'm', N_("Use MySQL Protocol."),
1578
 
   (char**) &opt_mysql, (char**) &opt_mysql, 0, GET_BOOL, NO_ARG, 1, 0, 0,
1579
 
   0, 0, 0},
 
1582
    (char**) &opt_mysql, (char**) &opt_mysql, 0, GET_BOOL, NO_ARG, 1, 0, 0,
 
1583
    0, 0, 0},
1580
1584
  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
1581
1585
};
1582
1586
 
1707
1711
      return EXIT_ARGUMENT_INVALID;
1708
1712
    }
1709
1713
    /* If the port number is > 65535 it is not a valid port
1710
 
       This also helps with potential data loss casting unsigned long to a
1711
 
       uint32_t. */
 
1714
      This also helps with potential data loss casting unsigned long to a
 
1715
      uint32_t. */
1712
1716
    if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
1713
1717
    {
1714
1718
      put_info(_("Value supplied for port is not valid."), INFO_ERROR, 0, 0);
1969
1973
 
1970
1974
 
1971
1975
static bool add_line(string *buffer, char *line, char *in_string,
1972
 
                        bool *ml_comment)
 
1976
                     bool *ml_comment)
1973
1977
{
1974
1978
  unsigned char inchar;
1975
1979
  char *pos, *out;
2238
2242
}
2239
2243
 
2240
2244
/*****************************************************************
2241
 
            Interface to Readline Completion
2242
 
******************************************************************/
 
2245
  Interface to Readline Completion
 
2246
 ******************************************************************/
2243
2247
 
2244
2248
 
2245
2249
static char **mysql_completion (const char *text, int start, int end);
2477
2481
      if (drizzle_result_row_count(&tables) > 0 && !opt_silent && write_info)
2478
2482
      {
2479
2483
        tee_fprintf(stdout, _("\
2480
 
Reading table information for completion of table and column names\n    \
2481
 
You can turn off this feature to get a quicker startup with -A\n\n"));
 
2484
                              Reading table information for completion of table and column names\n    \
 
2485
                              You can turn off this feature to get a quicker startup with -A\n\n"));
2482
2486
      }
2483
2487
      while ((table_row=drizzle_row_next(&tables)))
2484
2488
      {
2507
2511
    query.append("show fields in '");
2508
2512
    query.append(table_row[0]);
2509
2513
    query.append("'");
2510
 
    
 
2514
 
2511
2515
    if (drizzle_query(&con, &fields, query.c_str(), query.length(),
2512
2516
                      &ret) != NULL)
2513
2517
    {
2573
2577
}
2574
2578
 
2575
2579
/***************************************************************************
2576
 
 The different commands
2577
 
***************************************************************************/
 
2580
  The different commands
 
2581
 ***************************************************************************/
2578
2582
 
2579
2583
int drizzleclient_real_query_for_lazy(const char *buf, int length,
2580
2584
                                      drizzle_result_st *result,
2656
2660
 
2657
2661
/*
2658
2662
  Execute command
2659
 
  Returns: 0  if ok
2660
 
  -1 if not fatal error
2661
 
  1  if fatal error
 
2663
Returns: 0  if ok
 
2664
-1 if not fatal error
 
2665
1  if fatal error
2662
2666
*/
2663
2667
static int
2664
2668
com_go(string *buffer, const char *)
2759
2763
          print_tab_data(&result);
2760
2764
        else
2761
2765
          print_table_data(&result);
2762
 
        sprintf(buff,
2763
 
                ngettext("%ld row in set","%ld rows in set",
2764
 
                         (long) drizzle_result_row_count(&result)),
2765
 
                (long) drizzle_result_row_count(&result));
 
2766
        snprintf(buff, sizeof(buff), 
 
2767
                 ngettext("%ld row in set","%ld rows in set",
 
2768
                          (long) drizzle_result_row_count(&result)),
 
2769
                 (long) drizzle_result_row_count(&result));
2766
2770
        end_pager();
2767
2771
        if (drizzle_result_error_code(&result))
2768
2772
          error= put_error(&con, &result);
2771
2775
    else if (drizzle_result_affected_rows(&result) == ~(uint64_t) 0)
2772
2776
      strcpy(buff,_("Query OK"));
2773
2777
    else
2774
 
      sprintf(buff, ngettext("Query OK, %ld row affected",
2775
 
                             "Query OK, %ld rows affected",
2776
 
                             (long) drizzle_result_affected_rows(&result)),
2777
 
              (long) drizzle_result_affected_rows(&result));
 
2778
      snprintf(buff, sizeof(buff), ngettext("Query OK, %ld row affected",
 
2779
                                            "Query OK, %ld rows affected",
 
2780
                                            (long) drizzle_result_affected_rows(&result)),
 
2781
               (long) drizzle_result_affected_rows(&result));
2778
2782
 
2779
2783
    pos= strchr(buff, '\0');
2780
2784
    if ((warnings= drizzle_result_warning_count(&result)))
2783
2787
      *pos++= ' ';
2784
2788
      char warnings_buff[20];
2785
2789
      memset(warnings_buff,0,20);
2786
 
      sprintf(warnings_buff, "%d", warnings);
 
2790
      snprintf(warnings_buff, sizeof(warnings_buff), "%d", warnings);
2787
2791
      strcpy(pos, warnings_buff);
2788
2792
      pos+= strlen(warnings_buff);
2789
2793
      pos= strcpy(pos, " warning")+8;
2901
2905
static const char *fieldtype2str(drizzle_column_type_t type)
2902
2906
{
2903
2907
  switch (type) {
2904
 
    case DRIZZLE_COLUMN_TYPE_BLOB:        return "BLOB";
2905
 
    case DRIZZLE_COLUMN_TYPE_DATE:        return "DATE";
2906
 
    case DRIZZLE_COLUMN_TYPE_DATETIME:    return "DATETIME";
2907
 
    case DRIZZLE_COLUMN_TYPE_NEWDECIMAL:  return "DECIMAL";
2908
 
    case DRIZZLE_COLUMN_TYPE_DOUBLE:      return "DOUBLE";
2909
 
    case DRIZZLE_COLUMN_TYPE_ENUM:        return "ENUM";
2910
 
    case DRIZZLE_COLUMN_TYPE_LONG:        return "LONG";
2911
 
    case DRIZZLE_COLUMN_TYPE_LONGLONG:    return "LONGLONG";
2912
 
    case DRIZZLE_COLUMN_TYPE_NULL:        return "NULL";
2913
 
    case DRIZZLE_COLUMN_TYPE_TIMESTAMP:   return "TIMESTAMP";
2914
 
    default:                     return "?-unknown-?";
 
2908
  case DRIZZLE_COLUMN_TYPE_BLOB:        return "BLOB";
 
2909
  case DRIZZLE_COLUMN_TYPE_DATE:        return "DATE";
 
2910
  case DRIZZLE_COLUMN_TYPE_DATETIME:    return "DATETIME";
 
2911
  case DRIZZLE_COLUMN_TYPE_NEWDECIMAL:  return "DECIMAL";
 
2912
  case DRIZZLE_COLUMN_TYPE_DOUBLE:      return "DOUBLE";
 
2913
  case DRIZZLE_COLUMN_TYPE_ENUM:        return "ENUM";
 
2914
  case DRIZZLE_COLUMN_TYPE_LONG:        return "LONG";
 
2915
  case DRIZZLE_COLUMN_TYPE_LONGLONG:    return "LONGLONG";
 
2916
  case DRIZZLE_COLUMN_TYPE_NULL:        return "NULL";
 
2917
  case DRIZZLE_COLUMN_TYPE_TIMESTAMP:   return "TIMESTAMP";
 
2918
  default:                     return "?-unknown-?";
2915
2919
  }
2916
2920
}
2917
2921
 
2921
2925
  *s=0;
2922
2926
#define ff2s_check_flag(X)                                              \
2923
2927
  if (f & DRIZZLE_COLUMN_FLAGS_ ## X) { s=strcpy(s, # X " ")+strlen(# X " "); \
2924
 
                        f &= ~ DRIZZLE_COLUMN_FLAGS_ ## X; }
 
2928
    f &= ~ DRIZZLE_COLUMN_FLAGS_ ## X; }
2925
2929
  ff2s_check_flag(NOT_NULL);
2926
2930
  ff2s_check_flag(PRI_KEY);
2927
2931
  ff2s_check_flag(UNIQUE_KEY);
2942
2946
  ff2s_check_flag(ON_UPDATE_NOW);
2943
2947
#undef ff2s_check_flag
2944
2948
  if (f)
2945
 
    sprintf(s, " unknows=0x%04x", f);
 
2949
    snprintf(s, sizeof(buf), " unknows=0x%04x", f);
2946
2950
  return buf;
2947
2951
}
2948
2952
 
3008
3012
      uint32_t name_length= strlen(drizzle_column_name(field));
3009
3013
 
3010
3014
      /* Check if the max_byte value is really the maximum in terms
3011
 
         of visual length since multibyte characters can affect the
3012
 
         length of the separator. */
 
3015
        of visual length since multibyte characters can affect the
 
3016
        length of the separator. */
3013
3017
      length= charset_info->cset->numcells(charset_info,
3014
3018
                                           drizzle_column_name(field),
3015
3019
                                           drizzle_column_name(field) +
3025
3029
        length= name_length;
3026
3030
      }
3027
3031
    }
3028
 
  
 
3032
 
3029
3033
    if (quick)
3030
3034
      length=max(length,drizzle_column_size(field));
3031
3035
    else
3052
3056
    {
3053
3057
      uint32_t name_length= (uint32_t) strlen(drizzle_column_name(field));
3054
3058
      uint32_t numcells= charset_info->cset->numcells(charset_info,
3055
 
                                                  drizzle_column_name(field),
3056
 
                                                  drizzle_column_name(field) +
3057
 
                                                  name_length);
 
3059
                                                      drizzle_column_name(field),
 
3060
                                                      drizzle_column_name(field) +
 
3061
                                                      name_length);
3058
3062
      uint32_t display_length= drizzle_column_max_size(field) + name_length -
3059
 
                               numcells;
 
3063
        numcells;
3060
3064
      tee_fprintf(PAGER, " %-*s |",(int) min(display_length,
3061
3065
                                             MAX_COLUMN_LENGTH),
3062
3066
                  drizzle_column_name(field));
3141
3145
}
3142
3146
 
3143
3147
/**
3144
 
   Return the length of a field after it would be rendered into text.
3145
 
 
3146
 
   This doesn't know or care about multibyte characters.  Assume we're
3147
 
   using such a charset.  We can't know that all of the upcoming rows
3148
 
   for this column will have bytes that each render into some fraction
3149
 
   of a character.  It's at least possible that a row has bytes that
3150
 
   all render into one character each, and so the maximum length is
3151
 
   still the number of bytes.  (Assumption 1:  This can't be better
3152
 
   because we can never know the number of characters that the DB is
3153
 
   going to send -- only the number of bytes.  2: Chars <= Bytes.)
3154
 
 
3155
 
   @param  field  Pointer to a field to be inspected
3156
 
 
3157
 
   @returns  number of character positions to be used, at most
 
3148
  Return the length of a field after it would be rendered into text.
 
3149
 
 
3150
  This doesn't know or care about multibyte characters.  Assume we're
 
3151
  using such a charset.  We can't know that all of the upcoming rows
 
3152
  for this column will have bytes that each render into some fraction
 
3153
  of a character.  It's at least possible that a row has bytes that
 
3154
  all render into one character each, and so the maximum length is
 
3155
  still the number of bytes.  (Assumption 1:  This can't be better
 
3156
  because we can never know the number of characters that the DB is
 
3157
  going to send -- only the number of bytes.  2: Chars <= Bytes.)
 
3158
 
 
3159
  @param  field  Pointer to a field to be inspected
 
3160
 
 
3161
  @returns  number of character positions to be used, at most
3158
3162
*/
3159
3163
static int get_field_disp_length(drizzle_column_st *field)
3160
3164
{
3166
3170
    length= max(length, (uint32_t)drizzle_column_max_size(field));
3167
3171
 
3168
3172
  if (length < 4 &&
3169
 
    !(drizzle_column_flags(field) & DRIZZLE_COLUMN_FLAGS_NOT_NULL))
 
3173
      !(drizzle_column_flags(field) & DRIZZLE_COLUMN_FLAGS_NOT_NULL))
3170
3174
  {
3171
3175
    length= 4;        /* Room for "NULL" */
3172
3176
  }
3175
3179
}
3176
3180
 
3177
3181
/**
3178
 
   For a new result, return the max number of characters that any
3179
 
   upcoming row may return.
3180
 
 
3181
 
   @param  result  Pointer to the result to judge
3182
 
 
3183
 
   @returns  The max number of characters in any row of this result
 
3182
  For a new result, return the max number of characters that any
 
3183
  upcoming row may return.
 
3184
 
 
3185
  @param  result  Pointer to the result to judge
 
3186
 
 
3187
  @returns  The max number of characters in any row of this result
3184
3188
*/
3185
3189
static int get_result_width(drizzle_result_st *result)
3186
3190
{
3304
3308
    warning.
3305
3309
  */
3306
3310
  if (!cur || (num_rows == 1 &&
3307
 
      error_code == (uint32_t) strtoul(cur[1], NULL, 10)))
 
3311
               error_code == (uint32_t) strtoul(cur[1], NULL, 10)))
3308
3312
  {
3309
3313
    goto end;
3310
3314
  }
3599
3603
 
3600
3604
  if (connected)
3601
3605
  {
3602
 
    sprintf(buff,"Connection id:    %u",drizzle_con_thread_id(&con));
 
3606
    snprintf(buff, sizeof(buff), "Connection id:    %u",drizzle_con_thread_id(&con));
3603
3607
    put_info(buff,INFO_INFO,0,0);
3604
 
    sprintf(buff,"Current database: %.128s\n",
3605
 
            current_db ? current_db : "*** NONE ***");
 
3608
    snprintf(buff, sizeof(buff), "Current database: %.128s\n",
 
3609
             current_db ? current_db : "*** NONE ***");
3606
3610
    put_info(buff,INFO_INFO,0,0);
3607
3611
  }
3608
3612
  return error;
3637
3641
  if (!(sql_file = fopen(source_name, "r")))
3638
3642
  {
3639
3643
    char buff[FN_REFLEN+60];
3640
 
    sprintf(buff,"Failed to open file '%s', error: %d", source_name,errno);
 
3644
    snprintf(buff, sizeof(buff), "Failed to open file '%s', error: %d", source_name,errno);
3641
3645
    return put_info(buff, INFO_ERROR, 0 ,0);
3642
3646
  }
3643
3647
 
3865
3869
 
3866
3870
static int
3867
3871
sql_connect(char *host,char *database,char *user,char *password,
3868
 
                 uint32_t silent)
 
3872
            uint32_t silent)
3869
3873
{
3870
3874
  drizzle_return_t ret;
3871
3875
 
3884
3888
    return 1;
3885
3889
  }
3886
3890
 
3887
 
/* XXX add this back in
3888
 
  if (opt_connect_timeout)
3889
 
  {
 
3891
  /* XXX add this back in
 
3892
    if (opt_connect_timeout)
 
3893
    {
3890
3894
    uint32_t timeout=opt_connect_timeout;
3891
3895
    drizzleclient_options(&drizzle,DRIZZLE_OPT_CONNECT_TIMEOUT,
3892
 
                  (char*) &timeout);
3893
 
  }
3894
 
*/
 
3896
    (char*) &timeout);
 
3897
    }
 
3898
  */
3895
3899
 
3896
 
/* XXX Do we need this?
3897
 
  if (safe_updates)
3898
 
  {
 
3900
  /* XXX Do we need this?
 
3901
    if (safe_updates)
 
3902
    {
3899
3903
    char init_command[100];
3900
3904
    sprintf(init_command,
3901
 
            "SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=%"PRIu32
3902
 
            ",MAX_JOIN_SIZE=%"PRIu32,
3903
 
            select_limit, max_join_size);
 
3905
    "SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=%"PRIu32
 
3906
    ",MAX_JOIN_SIZE=%"PRIu32,
 
3907
    select_limit, max_join_size);
3904
3908
    drizzleclient_options(&drizzle, DRIZZLE_INIT_COMMAND, init_command);
3905
 
  }
3906
 
*/
 
3909
    }
 
3910
  */
3907
3911
  if ((ret= drizzle_con_connect(&con)) != DRIZZLE_RETURN_OK)
3908
3912
  {
3909
3913
    if (!silent || (ret != DRIZZLE_RETURN_GETADDRINFO &&
3925
3929
static int
3926
3930
com_status(string *, const char *)
3927
3931
{
3928
 
/*
3929
 
  char buff[40];
3930
 
  uint64_t id;
3931
 
*/
 
3932
  /*
 
3933
    char buff[40];
 
3934
    uint64_t id;
 
3935
  */
3932
3936
  drizzle_result_st result;
3933
3937
  drizzle_return_t ret;
3934
3938
 
3976
3980
  tee_fprintf(stdout, "Server version:\t\t%s\n", server_version_string(&con));
3977
3981
  tee_fprintf(stdout, "Protocol version:\t%d\n", drizzle_con_protocol_version(&con));
3978
3982
  tee_fprintf(stdout, "Connection:\t\t%s\n", drizzle_con_host(&con));
3979
 
/* XXX need to save this from result
3980
 
  if ((id= drizzleclient_insert_id(&drizzle)))
 
3983
  /* XXX need to save this from result
 
3984
    if ((id= drizzleclient_insert_id(&drizzle)))
3981
3985
    tee_fprintf(stdout, "Insert id:\t\t%s\n", internal::llstr(id, buff));
3982
 
*/
 
3986
  */
3983
3987
 
3984
3988
  if (drizzle_con_uds(&con))
3985
3989
    tee_fprintf(stdout, "UNIX socket:\t\t%s\n", drizzle_con_uds(&con));
3992
3996
    tee_fprintf(stdout, "\nNote that you are running in safe_update_mode:\n");
3993
3997
    vidattr(A_NORMAL);
3994
3998
    tee_fprintf(stdout, "\
3995
 
UPDATEs and DELETEs that don't use a key in the WHERE clause are not allowed.\n\
3996
 
(One can force an UPDATE/DELETE by adding LIMIT # at the end of the command.)\n \
3997
 
SELECT has an automatic 'LIMIT %lu' if LIMIT is not used.\n             \
3998
 
Max number of examined row combination in a join is set to: %lu\n\n",
 
3999
                UPDATEs and DELETEs that don't use a key in the WHERE clause are not allowed.\n\
 
4000
                (One can force an UPDATE/DELETE by adding LIMIT # at the end of the command.)\n \
 
4001
                SELECT has an automatic 'LIMIT %lu' if LIMIT is not used.\n             \
 
4002
                Max number of examined row combination in a join is set to: %lu\n\n",
3999
4003
                select_limit, max_join_size);
4000
4004
  }
4001
4005
  tee_puts("--------------\n", stdout);
4130
4134
 
4131
4135
  return put_info(error, INFO_ERROR,
4132
4136
                  res == NULL ? drizzle_con_error_code(local_con) :
4133
 
                                drizzle_result_error_code(res),
 
4137
                  drizzle_result_error_code(res),
4134
4138
                  res == NULL ? drizzle_con_sqlstate(local_con) :
4135
 
                                drizzle_result_sqlstate(res));
 
4139
                  drizzle_result_sqlstate(res));
4136
4140
}
4137
4141
 
4138
4142
 
4205
4209
 
4206
4210
 
4207
4211
/**
4208
 
   Write as many as 52+1 bytes to buff, in the form of a legible
4209
 
   duration of time.
 
4212
  Write as many as 52+1 bytes to buff, in the form of a legible
 
4213
  duration of time.
4210
4214
 
4211
 
   len("4294967296 days, 23 hours, 59 minutes, 60.00 seconds")  ->  52
 
4215
  len("4294967296 days, 23 hours, 59 minutes, 60.00 seconds")  ->  52
4212
4216
*/
4213
4217
static void nice_time(double sec,char *buff,bool part_second)
4214
4218
{
4309
4313
        processed_prompt->append(current_db ? current_db : "(none)");
4310
4314
        break;
4311
4315
      case 'h':
4312
 
      {
4313
 
        const char *prompt;
4314
 
        prompt= connected ? drizzle_con_host(&con) : "not_connected";
4315
 
        if (strstr(prompt, "Localhost"))
4316
 
          processed_prompt->append("localhost");
4317
 
        else
4318
4316
        {
4319
 
          const char *end=strrchr(prompt,' ');
4320
 
          if (end != NULL)
4321
 
            processed_prompt->append(prompt, (end-prompt));
 
4317
          const char *prompt;
 
4318
          prompt= connected ? drizzle_con_host(&con) : "not_connected";
 
4319
          if (strstr(prompt, "Localhost"))
 
4320
            processed_prompt->append("localhost");
 
4321
          else
 
4322
          {
 
4323
            const char *end=strrchr(prompt,' ');
 
4324
            if (end != NULL)
 
4325
              processed_prompt->append(prompt, (end-prompt));
 
4326
          }
 
4327
          break;
4322
4328
        }
4323
 
        break;
4324
 
      }
4325
4329
      case 'p':
4326
 
      {
4327
 
        if (!connected)
4328
4330
        {
4329
 
          processed_prompt->append("not_connected");
4330
 
          break;
4331
 
        }
 
4331
          if (!connected)
 
4332
          {
 
4333
            processed_prompt->append("not_connected");
 
4334
            break;
 
4335
          }
4332
4336
 
4333
 
        if (drizzle_con_uds(&con))
4334
 
        {
4335
 
          const char *pos=strrchr(drizzle_con_uds(&con),'/');
4336
 
          processed_prompt->append(pos ? pos+1 : drizzle_con_uds(&con));
 
4337
          if (drizzle_con_uds(&con))
 
4338
          {
 
4339
            const char *pos=strrchr(drizzle_con_uds(&con),'/');
 
4340
            processed_prompt->append(pos ? pos+1 : drizzle_con_uds(&con));
 
4341
          }
 
4342
          else
 
4343
            add_int_to_prompt(drizzle_con_port(&con));
4337
4344
        }
4338
 
        else
4339
 
          add_int_to_prompt(drizzle_con_port(&con));
4340
 
      }
4341
 
      break;
 
4345
        break;
4342
4346
      case 'U':
4343
4347
        if (!full_username)
4344
4348
          init_username();
4448
4452
 
4449
4453
static void init_username()
4450
4454
{
4451
 
/* XXX need this?
4452
 
  free(full_username);
4453
 
  free(part_username);
 
4455
  /* XXX need this?
 
4456
    free(full_username);
 
4457
    free(part_username);
4454
4458
 
4455
 
  drizzle_result_st *result;
4456
 
  if (!drizzleclient_query(&drizzle,"select USER()") &&
4457
 
      (result=drizzleclient_use_result(&drizzle)))
4458
 
  {
 
4459
    drizzle_result_st *result;
 
4460
    if (!drizzleclient_query(&drizzle,"select USER()") &&
 
4461
    (result=drizzleclient_use_result(&drizzle)))
 
4462
    {
4459
4463
    drizzle_row_t cur=drizzleclient_fetch_row(result);
4460
4464
    full_username= strdup(cur[0]);
4461
4465
    part_username= strdup(strtok(cur[0],"@"));
4462
4466
    (void) drizzleclient_fetch_row(result);        // Read eof
4463
 
  }
4464
 
*/
 
4467
    }
 
4468
  */
4465
4469
}
4466
4470
 
4467
4471
static int com_prompt(string *, const char *line)
4484
4488
}
4485
4489
 
4486
4490
/*
4487
 
    strcont(str, set) if str contanies any character in the string set.
4488
 
    The result is the position of the first found character in str, or NULL
4489
 
    if there isn't anything found.
 
4491
  strcont(str, set) if str contanies any character in the string set.
 
4492
  The result is the position of the first found character in str, or NULL
 
4493
  if there isn't anything found.
4490
4494
*/
4491
4495
 
4492
4496
static const char * strcont(register const char *str, register const char *set)