~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzle.cc

  • Committer: Lee
  • Date: 2008-10-03 23:31:06 UTC
  • mfrom: (413.2.3 drizzle)
  • mto: This revision was merged to the branch mainline in revision 459.
  • Revision ID: lbieber@lbieber-desktop-20081003233106-tgvzu0fh25gb3xeg
breaking out enum field classes

Show diffs side-by-side

added added

removed removed

Lines of Context:
610
610
  { "QUARTER", 0, 0, 0, ""},
611
611
  { "QUERY", 0, 0, 0, ""},
612
612
  { "QUICK", 0, 0, 0, ""},
 
613
  { "RAID0", 0, 0, 0, ""},
 
614
  { "RAID_CHUNKS", 0, 0, 0, ""},
 
615
  { "RAID_CHUNKSIZE", 0, 0, 0, ""},
 
616
  { "RAID_TYPE", 0, 0, 0, ""},
613
617
  { "READ", 0, 0, 0, ""},
614
618
  { "READS", 0, 0, 0, ""},
615
619
  { "REAL", 0, 0, 0, ""},
1011
1015
static void end_timer(uint32_t start_time,char *buff);
1012
1016
static void drizzle_end_timer(uint32_t start_time,char *buff);
1013
1017
static void nice_time(double sec,char *buff,bool part_second);
1014
 
extern RETSIGTYPE drizzle_end(int sig);
1015
 
extern RETSIGTYPE handle_sigint(int sig);
 
1018
extern sig_handler drizzle_end(int sig);
 
1019
extern sig_handler handle_sigint(int sig);
1016
1020
#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
1017
 
static RETSIGTYPE window_resize(int sig);
 
1021
static sig_handler window_resize(int sig);
1018
1022
#endif
1019
1023
 
1020
1024
int main(int argc,char *argv[])
1147
1151
          strncmp(link_name, "/dev/null", 10) == 0)
1148
1152
      {
1149
1153
        /* The .drizzle_history file is a symlink to /dev/null, don't use it */
1150
 
        free(histfile);
 
1154
        my_free(histfile, MYF(MY_ALLOW_ZERO_PTR));
1151
1155
        histfile= 0;
1152
1156
      }
1153
1157
    }
1177
1181
  return(0);        // Keep compiler happy
1178
1182
}
1179
1183
 
1180
 
RETSIGTYPE drizzle_end(int sig)
 
1184
sig_handler drizzle_end(int sig)
1181
1185
{
1182
1186
  drizzle_close(&drizzle);
1183
1187
  if (!status.batch && !quick && histfile)
1198
1202
    delete glob_buffer;
1199
1203
  if (processed_prompt)
1200
1204
    delete processed_prompt;
1201
 
  free(opt_password);
1202
 
  free(opt_drizzle_unix_port);
1203
 
  free(histfile);
1204
 
  free(histfile_tmp);
1205
 
  free(current_db);
1206
 
  free(current_host);
1207
 
  free(current_user);
1208
 
  free(full_username);
1209
 
  free(part_username);
1210
 
  free(default_prompt);
1211
 
  free(current_prompt);
 
1205
  my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
 
1206
  my_free(opt_drizzle_unix_port,MYF(MY_ALLOW_ZERO_PTR));
 
1207
  my_free(histfile,MYF(MY_ALLOW_ZERO_PTR));
 
1208
  my_free(histfile_tmp,MYF(MY_ALLOW_ZERO_PTR));
 
1209
  my_free(current_db,MYF(MY_ALLOW_ZERO_PTR));
 
1210
  my_free(current_host,MYF(MY_ALLOW_ZERO_PTR));
 
1211
  my_free(current_user,MYF(MY_ALLOW_ZERO_PTR));
 
1212
  my_free(full_username,MYF(MY_ALLOW_ZERO_PTR));
 
1213
  my_free(part_username,MYF(MY_ALLOW_ZERO_PTR));
 
1214
  my_free(default_prompt,MYF(MY_ALLOW_ZERO_PTR));
 
1215
  my_free(current_prompt,MYF(MY_ALLOW_ZERO_PTR));
1212
1216
  free_defaults(defaults_argv);
1213
1217
  my_end(my_end_arg);
1214
1218
  exit(status.exit_status);
1220
1224
  If query is in process, kill query
1221
1225
  no query in process, terminate like previous behavior
1222
1226
*/
1223
 
RETSIGTYPE handle_sigint(int sig)
 
1227
sig_handler handle_sigint(int sig)
1224
1228
{
1225
1229
  char kill_buffer[40];
1226
1230
  DRIZZLE *kill_drizzle= NULL;
1253
1257
 
1254
1258
 
1255
1259
#if defined(HAVE_TERMIOS_H) && defined(GWINSZ_IN_SYS_IOCTL)
1256
 
RETSIGTYPE window_resize(int sig __attribute__((unused)))
 
1260
sig_handler window_resize(int sig __attribute__((unused)))
1257
1261
{
1258
1262
  struct winsize window_size;
1259
1263
 
1561
1565
    if (argument)
1562
1566
    {
1563
1567
      char *start= argument;
1564
 
      free(opt_password);
 
1568
      my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
1565
1569
      opt_password= strdup(argument);
1566
1570
      while (*argument) *argument++= 'x';        // Destroy argument
1567
1571
      if (*start)
1649
1653
  if (argc == 1)
1650
1654
  {
1651
1655
    skip_updates= 0;
1652
 
    free(current_db);
 
1656
    my_free(current_db, MYF(MY_ALLOW_ZERO_PTR));
1653
1657
    current_db= strdup(*argv);
1654
1658
  }
1655
1659
  if (tty_password)
1656
 
    opt_password= get_tty_password(NULL);
 
1660
    opt_password= get_tty_password(NullS);
1657
1661
  if (debug_info_flag)
1658
1662
    my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
1659
1663
  if (debug_check_flag)
1682
1686
        you save the file using "Unicode UTF-8" format.
1683
1687
      */
1684
1688
      if (!line_number &&
1685
 
          (unsigned char) line[0] == 0xEF &&
1686
 
          (unsigned char) line[1] == 0xBB &&
1687
 
          (unsigned char) line[2] == 0xBF)
 
1689
          (uchar) line[0] == 0xEF &&
 
1690
          (uchar) line[1] == 0xBB &&
 
1691
          (uchar) line[2] == 0xBF)
1688
1692
        line+= 3;
1689
1693
      line_number++;
1690
1694
      if (!glob_buffer->empty())
1778
1782
    if (strstr(name, "\\g") || (strstr(name, delimiter) &&
1779
1783
                                !(strlen(name) >= 9 &&
1780
1784
                                  !my_strnncoll(charset_info,
1781
 
                                                (unsigned char*) name, 9,
1782
 
                                                (const unsigned char*) "delimiter",
 
1785
                                                (uchar*) name, 9,
 
1786
                                                (const uchar*) "delimiter",
1783
1787
                                                9))))
1784
1788
      return((COMMANDS *) 0);
1785
1789
    if ((end=strcont(name," \t")))
1797
1801
  for (uint i= 0; commands[i].name; i++)
1798
1802
  {
1799
1803
    if (commands[i].func &&
1800
 
        ((name && !my_strnncoll(charset_info,(const unsigned char*)name,len, (const unsigned char*)commands[i].name,len) && !commands[i].name[len] && (!end || (end && commands[i].takes_params))) || (!name && commands[i].cmd_char == cmd_char)))
 
1804
        ((name && !my_strnncoll(charset_info,(const uchar*)name,len, (const uchar*)commands[i].name,len) && !commands[i].name[len] && (!end || (end && commands[i].takes_params))) || (!name && commands[i].cmd_char == cmd_char)))
1801
1805
    {
1802
1806
      return(&commands[i]);
1803
1807
    }
1809
1813
static bool add_line(string *buffer, char *line, char *in_string,
1810
1814
                        bool *ml_comment)
1811
1815
{
1812
 
  unsigned char inchar;
 
1816
  uchar inchar;
1813
1817
  char buff[80], *pos, *out;
1814
1818
  COMMANDS *com;
1815
1819
  bool need_space= 0;
1822
1826
    add_history(line);
1823
1827
  char *end_of_line=line+(uint) strlen(line);
1824
1828
 
1825
 
  for (pos=out=line ; (inchar= (unsigned char) *pos) ; pos++)
 
1829
  for (pos=out=line ; (inchar= (uchar) *pos) ; pos++)
1826
1830
  {
1827
1831
    if (!preserve_comments)
1828
1832
    {
1854
1858
    {
1855
1859
      // Found possbile one character command like \c
1856
1860
 
1857
 
      if (!(inchar = (unsigned char) *++pos))
 
1861
      if (!(inchar = (uchar) *++pos))
1858
1862
        break;        // readline adds one '\'
1859
1863
      if (*in_string || inchar == 'N')  // \N is short for NULL
1860
1864
      {          // Don't allow commands in string
1862
1866
        *out++= (char) inchar;
1863
1867
        continue;
1864
1868
      }
1865
 
      if ((com=find_command(NULL,(char) inchar)))
 
1869
      if ((com=find_command(NullS,(char) inchar)))
1866
1870
      {
1867
1871
        // Flush previously accepted characters
1868
1872
        if (out != line)
1911
1915
    }
1912
1916
    else if (!*ml_comment && !*in_string &&
1913
1917
             (end_of_line - pos) >= 10 &&
1914
 
             !my_strnncoll(charset_info, (unsigned char*) pos, 10,
1915
 
                           (const unsigned char*) "delimiter ", 10))
 
1918
             !my_strnncoll(charset_info, (uchar*) pos, 10,
 
1919
                           (const uchar*) "delimiter ", 10))
1916
1920
    {
1917
1921
      // Flush previously accepted characters
1918
1922
      if (out != line)
2210
2214
 
2211
2215
      b = find_all_matches(&ht,text,(uint) strlen(text),&len);
2212
2216
      if (!b)
2213
 
        return NULL;
 
2217
        return NullS;
2214
2218
      e = b->pData;
2215
2219
    }
2216
2220
 
2237
2241
        }
2238
2242
      }
2239
2243
    }
2240
 
    ptr= NULL;
 
2244
    ptr= NullS;
2241
2245
    while (e && !ptr)
2242
2246
    {          /* find valid entry in bucket */
2243
2247
      if ((uint) strlen(e->str) == b->nKeyLength)
2266
2270
    if (ptr)
2267
2271
      return ptr;
2268
2272
  }
2269
 
  return NULL;
 
2273
  return NullS;
2270
2274
}
2271
2275
 
2272
2276
 
2357
2361
  i=0;
2358
2362
  while ((table_row=drizzle_fetch_row(tables)))
2359
2363
  {
2360
 
    if ((fields=drizzle_list_fields(&drizzle,(const char*) table_row[0],NULL)))
 
2364
    if ((fields=drizzle_list_fields(&drizzle,(const char*) table_row[0],NullS)))
2361
2365
    {
2362
2366
      num_fields=drizzle_num_fields(fields);
2363
2367
      if (!(field_names[i] = (char **) alloc_root(&hash_mem_root,
2404
2408
    for (;;)
2405
2409
    {
2406
2410
      if (*s == (char) c) return (char*) s;
2407
 
      if (!*s++) return NULL;
 
2411
      if (!*s++) return NullS;
2408
2412
    }
2409
2413
  }
2410
2414
 
2412
2416
  {
2413
2417
    register char *t;
2414
2418
 
2415
 
    t = NULL;
 
2419
    t = NullS;
2416
2420
    do if (*s == (char) c) t = (char*) s; while (*s++);
2417
2421
    return (char*) t;
2418
2422
  }
2440
2444
{
2441
2445
  DRIZZLE_RES *res;
2442
2446
 
2443
 
  free(current_db);
 
2447
  my_free(current_db, MYF(MY_ALLOW_ZERO_PTR));
2444
2448
  current_db= NULL;
2445
2449
  /* In case of error below current_db will be NULL */
2446
2450
  if (!drizzle_query(&drizzle, "SELECT DATABASE()") &&
2514
2518
        end_arg--;
2515
2519
      *++end_arg= '\0';
2516
2520
    }
2517
 
    (void) strxnmov(cmd_buf, sizeof(cmd_buf), "help '", help_arg, "'", NULL);
 
2521
    (void) strxnmov(cmd_buf, sizeof(cmd_buf), "help '", help_arg, "'", NullS);
2518
2522
    server_cmd= cmd_buf;
2519
2523
  }
2520
2524
 
2863
2867
    case DRIZZLE_TYPE_TIME:        return "TIME";
2864
2868
    case DRIZZLE_TYPE_TIMESTAMP:   return "TIMESTAMP";
2865
2869
    case DRIZZLE_TYPE_TINY:        return "TINY";
2866
 
    case DRIZZLE_TYPE_VIRTUAL:     return "VIRTUAL";
2867
2870
    default:                     return "?-unknown-?";
2868
2871
  }
2869
2872
}
3042
3045
    (void) tee_fputs("\n", PAGER);
3043
3046
  }
3044
3047
  tee_puts(separator.c_str(), PAGER);
3045
 
  free(num_flag);
 
3048
  my_free(num_flag, MYF(MY_ALLOW_ZERO_PTR));
3046
3049
}
3047
3050
 
3048
3051
/**
3446
3449
    tmp= get_arg(buff, 0);
3447
3450
    if (tmp && *tmp)
3448
3451
    {
3449
 
      free(current_db);
 
3452
      my_free(current_db, MYF(MY_ALLOW_ZERO_PTR));
3450
3453
      current_db= strdup(tmp);
3451
3454
      tmp= get_arg(buff, 1);
3452
3455
      if (tmp)
3453
3456
      {
3454
 
        free(current_host);
 
3457
        my_free(current_host,MYF(MY_ALLOW_ZERO_PTR));
3455
3458
        current_host=strdup(tmp);
3456
3459
      }
3457
3460
    }
3504
3507
  end[0]=0;
3505
3508
  unpack_filename(source_name,source_name);
3506
3509
  /* open file name */
3507
 
  if (!(sql_file = my_fopen(source_name, O_RDONLY,MYF(0))))
 
3510
  if (!(sql_file = my_fopen(source_name, O_RDONLY | O_BINARY,MYF(0))))
3508
3511
  {
3509
3512
    char buff[FN_REFLEN+60];
3510
3513
    sprintf(buff,"Failed to open file '%s', error: %d", source_name,errno);
3630
3633
      if (drizzle_select_db(&drizzle,tmp))
3631
3634
        return put_error(&drizzle);
3632
3635
    }
3633
 
    free(current_db);
 
3636
    my_free(current_db,MYF(MY_ALLOW_ZERO_PTR));
3634
3637
    current_db= strdup(tmp);
3635
3638
    if (select_db > 1)
3636
3639
      build_completion_hash(opt_rehash, 1);
3693
3696
        ptr++;
3694
3697
  }
3695
3698
  if (!*ptr)
3696
 
    return NULL;
 
3699
    return NullS;
3697
3700
  while (my_isspace(charset_info, *ptr))
3698
3701
    ptr++;
3699
3702
  if (*ptr == '\'' || *ptr == '\"' || *ptr == '`')
3716
3719
    }
3717
3720
  }
3718
3721
  valid_arg= ptr != start;
3719
 
  return valid_arg ? start : NULL;
 
3722
  return valid_arg ? start : NullS;
3720
3723
}
3721
3724
 
3722
3725
 
3737
3740
                  (char*) &timeout);
3738
3741
  }
3739
3742
  if (opt_compress)
3740
 
    drizzle_options(&drizzle,DRIZZLE_OPT_COMPRESS,NULL);
 
3743
    drizzle_options(&drizzle,DRIZZLE_OPT_COMPRESS,NullS);
3741
3744
  if (opt_secure_auth)
3742
3745
    drizzle_options(&drizzle, DRIZZLE_SECURE_AUTH, (char *) &opt_secure_auth);
3743
3746
  if (using_opt_local_infile)
3882
3885
      DRIZZLE_ROW cur = drizzle_fetch_row(result);
3883
3886
      if (cur && cur[0])
3884
3887
      {
3885
 
        bufp = strxnmov(bufp, sizeof buf - (bufp - buf), " ", cur[0], NULL);
 
3888
        bufp = strxnmov(bufp, sizeof buf - (bufp - buf), " ", cur[0], NullS);
3886
3889
      }
3887
3890
      drizzle_free_result(result);
3888
3891
    }
4283
4286
 
4284
4287
static void init_username()
4285
4288
{
4286
 
  free(full_username);
4287
 
  free(part_username);
 
4289
  my_free(full_username,MYF(MY_ALLOW_ZERO_PTR));
 
4290
  my_free(part_username,MYF(MY_ALLOW_ZERO_PTR));
4288
4291
 
4289
4292
  DRIZZLE_RES *result;
4290
4293
  if (!drizzle_query(&drizzle,"select USER()") &&
4302
4305
{
4303
4306
  char *ptr=strchr(line, ' ');
4304
4307
  prompt_counter = 0;
4305
 
  free(current_prompt);
 
4308
  my_free(current_prompt, MYF(MY_ALLOW_ZERO_PTR));
4306
4309
  current_prompt= strdup(ptr ? ptr+1 : default_prompt);
4307
4310
  if (!ptr)
4308
4311
    tee_fprintf(stdout, "Returning to default PROMPT of %s\n",
4314
4317
 
4315
4318
/*
4316
4319
    strcont(str, set) if str contanies any character in the string set.
4317
 
    The result is the position of the first found character in str, or NULL
 
4320
    The result is the position of the first found character in str, or NullS
4318
4321
    if there isn't anything found.
4319
4322
*/
4320
4323