~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.cc

  • Committer: Brian Aker
  • Date: 2008-12-17 23:37:33 UTC
  • mfrom: (685.1.41 devel)
  • Revision ID: brian@tangent.org-20081217233733-ra30lk7ju04k7re9
Merge from Monty

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;
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;
 
165
static bool preserve_comments= false;
 
166
static uint32_t opt_max_allowed_packet, opt_net_buffer_length,
 
167
  opt_drizzle_port= 0;
 
168
static int verbose= 0, opt_silent= 0, opt_local_infile= 0;
168
169
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;
 
170
static char * opt_drizzle_unix_port= NULL;
 
171
static int connect_flag= CLIENT_INTERACTIVE;
 
172
static char *current_host, *current_db, *current_user= NULL,
 
173
  *opt_password= NULL, *delimiter_str= NULL, *current_prompt= NULL;
173
174
static char *histfile;
174
175
static char *histfile_tmp;
175
176
static string *glob_buffer;
176
177
static string *processed_prompt= NULL;
177
178
static char *default_prompt= NULL;
178
 
static char *full_username=0,*part_username=0;
 
179
static char *full_username= NULL,*part_username= NULL;
179
180
static STATUS status;
180
181
static uint32_t select_limit;
181
182
static uint32_t max_join_size;
182
183
static uint32_t opt_connect_timeout= 0;
183
184
static char drizzle_charsets_dir[FN_REFLEN+1];
184
185
// 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",
 
186
static const char *day_names[]= {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
 
187
static const char *month_names[]= {"Jan","Feb","Mar","Apr","May","Jun","Jul",
187
188
                                  "Aug","Sep","Oct","Nov","Dec"};
188
189
static char default_pager[FN_REFLEN];
189
190
static char pager[FN_REFLEN], outfile[FN_REFLEN];
1364
1365
  {"no-pager", OPT_NOPAGER,
1365
1366
   N_("Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead."),
1366
1367
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
1367
 
  {"password", 'p',
 
1368
  {"password", 'P',
1368
1369
   N_("Password to use when connecting to server. If password is not given it's asked from the tty."),
1369
1370
   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, ")
 
1371
  {"port", 'p', N_("Port number to use for connection or 0 for default to, in order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, ")
1371
1372
   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},
 
1373
   0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1374
1374
  {"prompt", OPT_PROMPT, N_("Set the drizzle prompt to this value."),
1375
1375
   (char**) &current_prompt, (char**) &current_prompt, 0, GET_STR_ALLOC,
1376
1376
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1474
1474
extern "C" bool
1475
1475
get_one_option(int optid, const struct my_option *, char *argument)
1476
1476
{
 
1477
  char *endchar= NULL;
 
1478
  uint64_t temp_drizzle_port= 0;
 
1479
 
1477
1480
  switch(optid) {
1478
1481
  case OPT_CHARSETS_DIR:
1479
1482
    strncpy(drizzle_charsets_dir, argument, sizeof(drizzle_charsets_dir) - 1);
1498
1501
      {
1499
1502
        put_info(_("DELIMITER cannot contain a backslash character"),
1500
1503
                 INFO_ERROR,0,0);
1501
 
        return 0;
 
1504
        return false;
1502
1505
      }
1503
1506
    }
1504
1507
    delimiter_length= (uint)strlen(delimiter);
1505
1508
    delimiter_str= delimiter;
1506
1509
    break;
1507
1510
  case OPT_LOCAL_INFILE:
1508
 
    using_opt_local_infile=1;
 
1511
    using_opt_local_infile= 1;
1509
1512
    break;
1510
1513
  case OPT_TEE:
1511
1514
    if (argument == disabled_my_option)
1567
1570
      one_database= skip_updates= 1;
1568
1571
    break;
1569
1572
  case 'p':
 
1573
    temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
 
1574
    /* if there is an alpha character this is not a valid port */
 
1575
    if (strlen(endchar) != 0)
 
1576
    {
 
1577
      put_info(_("Non-integer value supplied for port.  If you are trying to enter a password please use --password instead."), INFO_ERROR, 0, 0);
 
1578
      return false;
 
1579
    }
 
1580
    /* If the port number is > 65535 it is not a valid port
 
1581
       This also helps with potential data loss casting unsigned long to a
 
1582
       uint32_t. */
 
1583
    if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
 
1584
    {
 
1585
      put_info(_("Value supplied for port is not valid."), INFO_ERROR, 0, 0);
 
1586
      return false;
 
1587
    }
 
1588
    else
 
1589
    {
 
1590
      opt_drizzle_port= (uint32_t) temp_drizzle_port;
 
1591
    }
 
1592
    break;
 
1593
  case 'P':
 
1594
    /* Don't require password */
1570
1595
    if (argument == disabled_my_option)
1571
 
      argument= (char*) "";      // Don't require password
 
1596
    {
 
1597
      argument= (char*) "";
 
1598
    }
1572
1599
    if (argument)
1573
1600
    {
1574
1601
      char *start= argument;
1575
1602
      free(opt_password);
1576
1603
      opt_password= strdup(argument);
1577
 
      while (*argument) *argument++= 'x';        // Destroy argument
 
1604
      while (*argument)
 
1605
      {
 
1606
        /* Overwriting password with 'x' */
 
1607
        *argument++= 'x';
 
1608
      }
1578
1609
      if (*start)
1579
 
        start[1]=0 ;
 
1610
      {
 
1611
        start[1]= 0;
 
1612
      }
1580
1613
      tty_password= 0;
1581
1614
    }
1582
1615
    else
 
1616
    {
1583
1617
      tty_password= 1;
 
1618
    }
1584
1619
    break;
1585
1620
  case 's':
1586
1621
    if (argument == disabled_my_option)