~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.cc

Merged from Andrew.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#include CMATH_H
39
39
#include <mystrings/m_ctype.h>
40
40
#include <stdarg.h>
41
 
#include <readline/history.h>
42
41
#include "my_readline.h"
43
42
#include <signal.h>
44
43
#include <sys/ioctl.h>
148
147
typedef enum enum_info_type INFO_TYPE;
149
148
 
150
149
static DRIZZLE drizzle;      /* The connection */
151
 
static bool ignore_errors=0,quick=0,
152
 
  connected=0,opt_raw_data=0,unbuffered=0,output_tables=0,
153
 
  opt_rehash=1,skip_updates=0,safe_updates=0,one_database=0,
154
 
  opt_compress=0, using_opt_local_infile=0,
155
 
  vertical=0, line_numbers=1, column_names=1,
156
 
  opt_nopager=1, opt_outfile=0, named_cmds= 0,
157
 
  tty_password= 0, opt_nobeep=0, opt_reconnect=1,
158
 
  default_charset_used= 0, opt_secure_auth= 0,
159
 
  default_pager_set= 0, opt_sigint_ignore= 0,
160
 
  auto_vertical_output= 0,
161
 
  show_warnings= 0, executing_query= 0, interrupted_query= 0;
 
150
static bool ignore_errors= false, quick= false,
 
151
  connected= false, opt_raw_data= false, unbuffered= false,
 
152
  output_tables= false, opt_rehash= true, skip_updates= false,
 
153
  safe_updates= false, one_database= false,
 
154
  opt_compress= false, using_opt_local_infile= false,
 
155
  vertical= false, line_numbers= true, column_names= true,
 
156
  opt_nopager= true, opt_outfile= false, named_cmds= false,
 
157
  tty_password= false, opt_nobeep= false, opt_reconnect= true,
 
158
  default_charset_used= false, opt_secure_auth= false,
 
159
  default_pager_set= false, opt_sigint_ignore= false,
 
160
  auto_vertical_output= false,
 
161
  show_warnings= false, executing_query= false, interrupted_query= false;
162
162
static uint32_t  show_progress_size= 0;
163
163
static bool debug_info_flag, debug_check_flag;
164
164
static bool column_types_flag;
165
 
static bool preserve_comments= 0;
 
165
static bool preserve_comments= false;
166
166
static uint32_t opt_max_allowed_packet, opt_net_buffer_length;
167
 
static int verbose=0,opt_silent=0,opt_drizzle_port=0, opt_local_infile=0;
 
167
static int verbose= 0, opt_drizzle_port= 0, opt_silent= 0, opt_local_infile= 0;
168
168
static uint my_end_arg;
169
 
static char * opt_drizzle_unix_port=0;
170
 
static int connect_flag=CLIENT_INTERACTIVE;
171
 
static char *current_host,*current_db,*current_user=0,*opt_password=0,
172
 
  *delimiter_str= 0,* current_prompt= 0;
 
169
static char * opt_drizzle_unix_port= NULL;
 
170
static int connect_flag= CLIENT_INTERACTIVE;
 
171
static char *current_host, *current_db, *current_user= NULL,
 
172
  *opt_password= NULL, *delimiter_str= NULL, *current_prompt= NULL;
173
173
static char *histfile;
174
174
static char *histfile_tmp;
175
175
static string *glob_buffer;
176
176
static string *processed_prompt= NULL;
177
177
static char *default_prompt= NULL;
178
 
static char *full_username=0,*part_username=0;
 
178
static char *full_username= NULL,*part_username= NULL;
179
179
static STATUS status;
180
180
static uint32_t select_limit;
181
181
static uint32_t max_join_size;
182
182
static uint32_t opt_connect_timeout= 0;
183
183
static char drizzle_charsets_dir[FN_REFLEN+1];
184
184
// TODO: Need to i18n these
185
 
static const char *day_names[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
186
 
static const char *month_names[]={"Jan","Feb","Mar","Apr","May","Jun","Jul",
 
185
static const char *day_names[]= {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
 
186
static const char *month_names[]= {"Jan","Feb","Mar","Apr","May","Jun","Jul",
187
187
                                  "Aug","Sep","Oct","Nov","Dec"};
188
188
static char default_pager[FN_REFLEN];
189
189
static char pager[FN_REFLEN], outfile[FN_REFLEN];
1364
1364
  {"no-pager", OPT_NOPAGER,
1365
1365
   N_("Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead."),
1366
1366
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1367
 
  {"password", 'p',
 
1367
  {"password", 'P',
1368
1368
   N_("Password to use when connecting to server. If password is not given it's asked from the tty."),
1369
1369
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
1370
 
  {"port", 'P', N_("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, ")
 
1370
  {"port", 'p', N_("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, ")
1371
1371
   N_("built-in default") " (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
1372
 
   (char**) &opt_drizzle_port,
1373
 
   (char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,  0},
 
1372
   0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1374
1373
  {"prompt", OPT_PROMPT, N_("Set the drizzle prompt to this value."),
1375
1374
   (char**) &current_prompt, (char**) &current_prompt, 0, GET_STR_ALLOC,
1376
1375
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1474
1473
extern "C" bool
1475
1474
get_one_option(int optid, const struct my_option *, char *argument)
1476
1475
{
 
1476
  char *endchar = NULL;
 
1477
 
1477
1478
  switch(optid) {
1478
1479
  case OPT_CHARSETS_DIR:
1479
1480
    strncpy(drizzle_charsets_dir, argument, sizeof(drizzle_charsets_dir) - 1);
1498
1499
      {
1499
1500
        put_info(_("DELIMITER cannot contain a backslash character"),
1500
1501
                 INFO_ERROR,0,0);
1501
 
        return 0;
 
1502
        return false;
1502
1503
      }
1503
1504
    }
1504
1505
    delimiter_length= (uint)strlen(delimiter);
1567
1568
      one_database= skip_updates= 1;
1568
1569
    break;
1569
1570
  case 'p':
 
1571
    opt_drizzle_port= strtol(argument, &endchar, 10);
 
1572
    /* if there is an alpha character this is not a valid port */
 
1573
    if (strlen(endchar) != 0)
 
1574
    {
 
1575
      put_info(_("Non-integer value supplied for port.  If you are trying to enter a password please use --password instead."), INFO_ERROR, 0, 0);
 
1576
      return false;
 
1577
    }
 
1578
    break;
 
1579
  case 'P':
 
1580
    /* Don't require password */
1570
1581
    if (argument == disabled_my_option)
1571
 
      argument= (char*) "";      // Don't require password
 
1582
    {
 
1583
      argument= (char*) "";
 
1584
    }
1572
1585
    if (argument)
1573
1586
    {
1574
1587
      char *start= argument;
1575
1588
      free(opt_password);
1576
1589
      opt_password= strdup(argument);
1577
 
      while (*argument) *argument++= 'x';        // Destroy argument
 
1590
      while (*argument)
 
1591
      {
 
1592
        /* Overwriting password with 'x' */
 
1593
        *argument++= 'x';
 
1594
      }
1578
1595
      if (*start)
1579
 
        start[1]=0 ;
 
1596
      {
 
1597
        start[1]= 0;
 
1598
      }
1580
1599
      tty_password= 0;
1581
1600
    }
1582
1601
    else
 
1602
    {
1583
1603
      tty_password= 1;
 
1604
    }
1584
1605
    break;
1585
1606
  case 's':
1586
1607
    if (argument == disabled_my_option)